diff --git a/cmd/cli/wire_gen.go b/cmd/cli/wire_gen.go index 55201ccc25..fc4f46c89a 100644 --- a/cmd/cli/wire_gen.go +++ b/cmd/cli/wire_gen.go @@ -47,6 +47,7 @@ func initCli() (*app.Cli, error) { cliService := service.NewCliService(koanf, db, appRepo, cacheRepo, userRepo, settingRepo, backupRepo, websiteRepo, databaseServerRepo) cli := route.NewCli(cliService) command := bootstrap.NewCli(cli) - appCli := app.NewCli(command) + gormigrate := bootstrap.NewMigrate(db) + appCli := app.NewCli(command, gormigrate) return appCli, nil } diff --git a/internal/app/cli.go b/internal/app/cli.go index e243af37d5..2cc430df5a 100644 --- a/internal/app/cli.go +++ b/internal/app/cli.go @@ -4,20 +4,28 @@ import ( "context" "os" + "github.com/go-gormigrate/gormigrate/v2" "github.com/urfave/cli/v3" ) type Cli struct { - cmd *cli.Command + cmd *cli.Command + migrator *gormigrate.Gormigrate } -func NewCli(cmd *cli.Command) *Cli { +func NewCli(cmd *cli.Command, migrator *gormigrate.Gormigrate) *Cli { IsCli = true return &Cli{ - cmd: cmd, + cmd: cmd, + migrator: migrator, } } func (r *Cli) Run() error { + // migrate database + if err := r.migrator.Migrate(); err != nil { + return err + } + return r.cmd.Run(context.Background(), os.Args) }