feat: 增加命令行工具的参数支持,包括路径、干运行模式和输出目录选项
This commit is contained in:
@@ -13,12 +13,14 @@ import (
|
||||
|
||||
// migrate
|
||||
func CommandMigrate(root *cobra.Command) {
|
||||
cmd := &cobra.Command{
|
||||
Use: "migrate [up|up-by-one|up-to|create|down|down-to|fix|redo|reset|status|version]",
|
||||
Aliases: []string{"m"},
|
||||
RunE: commandMigrate,
|
||||
}
|
||||
cmd.Flags().StringP("config", "c", "config.toml", "database config file")
|
||||
cmd := &cobra.Command{
|
||||
Use: "migrate [up|up-by-one|up-to|create|down|down-to|fix|redo|reset|status|version]",
|
||||
Aliases: []string{"m"},
|
||||
RunE: commandMigrate,
|
||||
}
|
||||
cmd.Flags().StringP("config", "c", "config.toml", "database config file")
|
||||
cmd.Flags().String("dir", "database/migrations", "migrations directory")
|
||||
cmd.Flags().String("table", "migrations", "migrations table name")
|
||||
|
||||
root.AddCommand(cmd)
|
||||
}
|
||||
@@ -39,10 +41,13 @@ func commandMigrate(cmd *cobra.Command, args []string) error {
|
||||
return errors.Wrap(err, "get db")
|
||||
}
|
||||
|
||||
action, args := args[0], args[1:]
|
||||
log.Infof("migration action: %s args: %+v", action, args)
|
||||
action, args := args[0], args[1:]
|
||||
log.Infof("migration action: %s args: %+v", action, args)
|
||||
|
||||
goose.SetTableName("migrations")
|
||||
dir := cmd.Flag("dir").Value.String()
|
||||
table := cmd.Flag("table").Value.String()
|
||||
|
||||
return goose.RunContext(context.Background(), action, db, "database/migrations", args...)
|
||||
goose.SetTableName(table)
|
||||
|
||||
return goose.RunContext(context.Background(), action, db, dir, args...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user