Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle unknown migrations #44

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ericklaus-wf
Copy link

Fixes bad behavior when some migrations in the db table are unknown to the current sql-migrate instance. That might happen when one branch applies some migrations and a branch lacking those migrations tries to add some of its own.

This resolves #37 by choosing option 2 of #43.

Fixed behaviors:

  • If most recent migration is unknown, migrate up reports "nothing to do"
    • Fix: Migrations are now applied
  • If any migrations are unknown, sql-migrate status panics
    • Fix: A log warning is now emitted indicating which migrations are unknown

Some weirdness remains:

  • If the latest migration is unknown sql-migrate redo reports "nothing to do"
  • I'd rather that sql-migrate status include the fact of unknown statuses in the table it prints, rather than as separate warnings
    • Perhaps we could add a column to the sql-migrate status table (probably before the migration column) that includes a status code. Maybe "!" for "unknown" and "a" for "not applied"?

Is this course desirable? If so, I can resolve the pointed out weirdness either in this PR or later on.

@rickvanbodegraven
Copy link

I am probably going to see if I can use this in our project, as it might fix the exact issues we are facing. Our branching strategy has branches for each of our scrum stories, which results in migrations being written on various branches, some of which are sometimes dependent on one another. Whenever we have to review work that was done on other branches, our dockerized postgres databases get partial migrations from some of those branches, and if we then switch back to our own work, we have to delete our database (thus losing all our test data every single time) and get it migrated again (which is fast and all, but really annoying......).

Heavy support for this PR 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql-migrate status fails if old migration file not found
2 participants