From fcf107036b36ce6235bd56e76c400673c5455a9a Mon Sep 17 00:00:00 2001 From: Rogee Date: Tue, 23 Dec 2025 10:52:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BD=BF=E7=94=A8=E5=8C=BF=E5=90=8D?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E6=9B=BF=E4=BB=A3=E5=91=BD=E5=90=8D=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/commands/migrate/migrate.go.tpl | 46 ++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/templates/project/app/commands/migrate/migrate.go.tpl b/templates/project/app/commands/migrate/migrate.go.tpl index 44c8448..ff70396 100644 --- a/templates/project/app/commands/migrate/migrate.go.tpl +++ b/templates/project/app/commands/migrate/migrate.go.tpl @@ -57,33 +57,27 @@ func Serve(cmd *cobra.Command, args []string) error { goose.SetBaseFS(database.MigrationFS) goose.SetTableName("migrations") - goose.AddNamedMigrationNoTxContext("0001_river_job.go", RiverUp, RiverDown) + goose.AddNamedMigrationNoTxContext( + "10000000000001_river_job.go", + func(ctx context.Context, db *sql.DB) error { + migrator, err := rivermigrate.New(riverdatabasesql.New(db), nil) + if err != nil { + return err + } + + _, err = migrator.Migrate(ctx, rivermigrate.DirectionUp, &rivermigrate.MigrateOpts{TargetVersion: -1}) + return err + }, + func(ctx context.Context, db *sql.DB) error { + migrator, err := rivermigrate.New(riverdatabasesql.New(db), nil) + if err != nil { + return err + } + + _, err = migrator.Migrate(ctx, rivermigrate.DirectionDown, &rivermigrate.MigrateOpts{TargetVersion: -1}) + return err + }) return goose.RunContext(context.Background(), action, svc.DB, "migrations", args...) }) } - -func RiverUp(ctx context.Context, db *sql.DB) error { - migrator, err := rivermigrate.New(riverdatabasesql.New(db), nil) - if err != nil { - return err - } - - // Migrate up. An empty MigrateOpts will migrate all the way up, but - // best practice is to specify a specific target version. - _, err = migrator.Migrate(ctx, rivermigrate.DirectionUp, &rivermigrate.MigrateOpts{}) - return err -} - -func RiverDown(ctx context.Context, db *sql.DB) error { - migrator, err := rivermigrate.New(riverdatabasesql.New(db), nil) - if err != nil { - return err - } - - // TargetVersion -1 removes River's schema completely. - _, err = migrator.Migrate(ctx, rivermigrate.DirectionDown, &rivermigrate.MigrateOpts{ - TargetVersion: -1, - }) - return err -}