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