From cff89253c8f18b12bb23d3b0a200e9bb8fe4f64f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Sun, 29 Dec 2024 15:13:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20cli=E6=95=B0=E6=8D=AE=E5=BA=93=E8=BF=81?= =?UTF-8?q?=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/cli/wire_gen.go | 3 ++- internal/app/cli.go | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) 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) }