Skip to content

Commit

Permalink
migrate goto with force support (#872)
Browse files Browse the repository at this point in the history
  • Loading branch information
nopcoder authored Oct 28, 2020
1 parent a8c06ae commit 00d3eb2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cmd/lakefs/cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
}
8 changes: 6 additions & 2 deletions db/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down

0 comments on commit 00d3eb2

Please sign in to comment.