add backend tpl
This commit is contained in:
40
backend_v1/cmd/migrate.go
Normal file
40
backend_v1/cmd/migrate.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.ipao.vip/rogeecn/mp-qvyun/conf"
|
||||
"git.ipao.vip/rogeecn/mp-qvyun/database"
|
||||
"github.com/gofiber/fiber/v3/log"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pressly/goose/v3"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func CommandMigrate(root *cobra.Command) {
|
||||
cmd := &cobra.Command{
|
||||
Use: "migrate",
|
||||
Short: "migrate",
|
||||
RunE: commandMigrate,
|
||||
}
|
||||
root.AddCommand(cmd)
|
||||
}
|
||||
|
||||
func commandMigrate(cmd *cobra.Command, args []string) error {
|
||||
if len(args) == 0 {
|
||||
args = append(args, "up")
|
||||
}
|
||||
|
||||
db, err := database.GetDB(conf.C.Database)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "get db")
|
||||
}
|
||||
|
||||
action, args := args[0], args[1:]
|
||||
log.Infof("migration action: %s args: %+v", action, args)
|
||||
|
||||
goose.SetBaseFS(database.MigrationFS)
|
||||
goose.SetTableName("migrations")
|
||||
|
||||
return goose.RunContext(context.Background(), action, db, "migrations", args...)
|
||||
}
|
||||
Reference in New Issue
Block a user