reCoreD-UI/cmd/config/database.go

36 lines
614 B
Go
Raw Normal View History

2024-04-03 09:05:12 +00:00
package config
import (
"reCoreD-UI/controllers"
2024-04-09 08:28:18 +00:00
"reCoreD-UI/database"
2024-04-03 09:05:12 +00:00
"github.com/urfave/cli/v2"
)
var DatabaseCommand *cli.Command
func init() {
migrationCommand := &cli.Command{
Name: "migrate",
Usage: "migrate database",
Action: migrateDatabase,
}
DatabaseCommand = &cli.Command{
Name: "database",
Usage: "database administration",
Aliases: []string{"db"},
Subcommands: []*cli.Command{
migrationCommand,
},
}
}
func migrateDatabase(c *cli.Context) error {
2024-04-09 08:28:18 +00:00
if err := database.Connect(c.String("mysql-dsn")); err != nil {
2024-04-03 09:05:12 +00:00
return err
}
2024-04-09 08:28:18 +00:00
return controllers.Migrate()
2024-04-03 09:05:12 +00:00
}