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