migrate
migrate copied to clipboard
Implement a way to upgrade without "dirty" functionality
Is your feature request related to a problem? Please describe.
As discussed in #282, the "dirty" functionality can lead to painful debugging and development situations - the "fix and force" solution that the error message demands is neither directly explained nor feasible unless the user is using migrate
as a CLI.
Describe the solution you'd like
Add a variant of migrate.Up
that does not invoke this functionality (acting as if the migration was not applied at all - not updating schema_migrations
and not blocking re-runs).
Describe alternatives you've considered Alternatively, a way to clean up this situation that's less bad-habit-forming for developers than "completely wipe the database and try again" would be appreciated.
Additional context This functionality appears to be intended for production safety, and allowing a way to disable it might encourage devs to disable it in production - but, I'd argue that a sane production rollout procedure has a database rollback plan, anyway - the correct solution should not be for someone to manually correct and re-run a migration, in the general case.
I am using the following:
version, dirty, err := m.Version()
switch {
case err == migrate.ErrNilVersion:
case err != nil:
return nil, fmt.Errorf("cannot retrieve version: %w", err)
case dirty:
forceVersion := version - 1
err := m.Force(int(forceVersion))
if err != nil {
return nil, fmt.Errorf("cannot force version %v: %w",
forceVersion, err)
}
}
err = m.Up()
switch {
case err == migrate.ErrNoChange:
case err != nil:
return nil, err
}