Register registers the migratecmd plugin to the provided app instance.
(app core.App, rootCmd *cobra.Command, config Config)
| 59 | |
| 60 | // Register registers the migratecmd plugin to the provided app instance. |
| 61 | func Register(app core.App, rootCmd *cobra.Command, config Config) error { |
| 62 | p := &plugin{app: app, config: config} |
| 63 | |
| 64 | if p.config.TemplateLang == "" { |
| 65 | p.config.TemplateLang = TemplateLangGo |
| 66 | } |
| 67 | |
| 68 | if p.config.Dir == "" { |
| 69 | if p.config.TemplateLang == TemplateLangJS { |
| 70 | p.config.Dir = filepath.Join(p.app.DataDir(), "../pb_migrations") |
| 71 | } else { |
| 72 | p.config.Dir = filepath.Join(p.app.DataDir(), "../migrations") |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | // attach the migrate command |
| 77 | if rootCmd != nil { |
| 78 | rootCmd.AddCommand(p.createCommand()) |
| 79 | } |
| 80 | |
| 81 | // watch for collection changes |
| 82 | if p.config.Automigrate { |
| 83 | p.app.OnCollectionCreateRequest().BindFunc(p.automigrateOnCollectionChange) |
| 84 | p.app.OnCollectionUpdateRequest().BindFunc(p.automigrateOnCollectionChange) |
| 85 | p.app.OnCollectionDeleteRequest().BindFunc(p.automigrateOnCollectionChange) |
| 86 | } |
| 87 | |
| 88 | return nil |
| 89 | } |
| 90 | |
| 91 | type plugin struct { |
| 92 | app core.App |
no test coverage detected
searching dependent graphs…