github.com/Accefy/pop@v0.0.0-20230428174248-e9f677eab5b9/soda/cmd/migrate.go (about) 1 package cmd 2 3 import ( 4 "errors" 5 "os" 6 7 "github.com/gobuffalo/pop/v6" 8 "github.com/spf13/cobra" 9 ) 10 11 var migrationPath string 12 13 var migrateCmd = &cobra.Command{ 14 Use: "migrate", 15 Aliases: []string{"m"}, 16 Short: "Runs migrations against your database.", 17 PersistentPreRunE: func(cmd *cobra.Command, args []string) error { 18 RootCmd.PersistentPreRun(cmd, args) 19 return os.MkdirAll(migrationPath, 0766) 20 }, 21 RunE: func(cmd *cobra.Command, args []string) error { 22 if len(args) > 0 { 23 return errors.New("migrate command does not accept any argument") 24 } 25 mig, err := pop.NewFileMigrator(migrationPath, getConn()) 26 if err != nil { 27 return err 28 } 29 return mig.Up() 30 }, 31 } 32 33 func init() { 34 RootCmd.AddCommand(migrateCmd) 35 RootCmd.PersistentFlags().StringVarP(&migrationPath, "path", "p", "./migrations", "Path to the migrations folder") 36 }