MCPcopy
hub / github.com/pocketbase/pocketbase / createCommand

Method createCommand

plugins/migratecmd/migratecmd.go:96–144  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

94}
95
96func (p *plugin) createCommand() *cobra.Command {
97 const cmdDesc = `Supported arguments are:
98- up - runs all available migrations
99- down [number] - reverts the last [number] applied migrations
100- create name - creates new blank migration template file
101- collections - creates new migration file with snapshot of the local collections configuration
102- history-sync - ensures that the _migrations history table doesn't have references to deleted migration files
103`
104
105 command := &cobra.Command{
106 Use: "migrate",
107 Short: "Executes app DB migration scripts",
108 Long: cmdDesc,
109 ValidArgs: []string{"up", "down", "create", "collections"},
110 SilenceUsage: true,
111 RunE: func(command *cobra.Command, args []string) error {
112 cmd := ""
113 if len(args) > 0 {
114 cmd = args[0]
115 }
116
117 switch cmd {
118 case "create":
119 if _, err := p.migrateCreateHandler("", args[1:], true); err != nil {
120 return err
121 }
122 case "collections":
123 if _, err := p.migrateCollectionsHandler(args[1:], true); err != nil {
124 return err
125 }
126 default:
127 // note: system migrations are always applied as part of the bootstrap process
128 var list = core.MigrationsList{}
129 list.Copy(core.SystemMigrations)
130 list.Copy(core.AppMigrations)
131
132 runner := core.NewMigrationsRunner(p.app, list)
133
134 if err := runner.Run(args...); err != nil {
135 return err
136 }
137 }
138
139 return nil
140 },
141 }
142
143 return command
144}
145
146func (p *plugin) migrateCreateHandler(template string, args []string, interactive bool) (string, error) {
147 if len(args) < 1 {

Callers 1

RegisterFunction · 0.95

Calls 5

migrateCreateHandlerMethod · 0.95
RunMethod · 0.95
NewMigrationsRunnerFunction · 0.92
CopyMethod · 0.65

Tested by

no test coverage detected