Skip to content

Behavior when unknown migration #43

@ericklaus-wf

Description

@ericklaus-wf

sql-migrate behaves badly when the database has migrations "unknown" to the current run of sql-migrate. This is most likely to happen when a diverged branch applied its migrations to a database while another branch also applied its own migrations to a database.

For example:

  1. branch A: 1, 2, 3
  2. branch B: 1, 2, 4
  3. branch B applies against DB. State is now "1, 2, 4"
  4. branch A tries to apply against DB. Migration "4" is unknown.

See existing issue: #37

How should sql-migrate behave when asked to perform a migration against a database that has unknown migrations? I can think of two reasonable behaviors:

  1. Complain that unknown migrations exist. Require the user to pass a -f force flag to complete the migrations. I'm not sure how the library should change, but I could work up some suggestions.
  2. Do the best we can. When migrating up, ignore the unknown migrations. When migrating down, fail upon encountering an unknown migration.

(For option 2, we could also allow migrating down by adding a migrate_down column to the migrations table and storing the SQL at migrate up time. That doesn't help any existing installations, but would be a way forward.)

Which behavior seems best? I'm in favor of 2, but see the merits of 1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions