diff --git a/cmd/lakefs/cmd/migrate.go b/cmd/lakefs/cmd/migrate.go index c7c21372e4b..6d04b25cf71 100644 --- a/cmd/lakefs/cmd/migrate.go +++ b/cmd/lakefs/cmd/migrate.go @@ -67,8 +67,9 @@ var gotoCmd = &cobra.Command{ fmt.Printf("Failed to get value for 'version': %s\n", err) os.Exit(1) } + force, _ := cmd.Flags().GetBool("force") uri := cfg.GetDatabaseParams() - err = db.MigrateTo(uri, version) + err = db.MigrateTo(uri, version, force) if err != nil { fmt.Printf("Failed to migrate to version %d.\n%s\n", version, err) os.Exit(1) @@ -85,4 +86,5 @@ func init() { migrateCmd.AddCommand(gotoCmd) _ = gotoCmd.Flags().Uint("version", 0, "version number") _ = gotoCmd.MarkFlagRequired("version") + _ = gotoCmd.Flags().Bool("force", false, "force migrate") } diff --git a/db/migration.go b/db/migration.go index 1b0ea91f64b..595450020d2 100644 --- a/db/migration.go +++ b/db/migration.go @@ -151,7 +151,7 @@ func MigrateDown(params params.Database) error { return nil } -func MigrateTo(p params.Database, version uint) error { +func MigrateTo(p params.Database, version uint, force bool) error { // make sure we have schema by calling connect mdb, err := ConnectDB(p) if err != nil { @@ -165,7 +165,11 @@ func MigrateTo(p params.Database, version uint) error { return err } defer closeMigrate(m) - err = m.Migrate(version) + if force { + err = m.Force(int(version)) + } else { + err = m.Migrate(version) + } if err != nil && !errors.Is(err, migrate.ErrNoChange) { return err }