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

Rollback database when backing sql source is removed #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

iderdik
Copy link

@iderdik iderdik commented Mar 25, 2015

When redeploying an older version of the app, the database is left in it's newest state, even if the older application expects an older version of the database.

To rollback when an older version of the app is deployed, we must:

  • Insert the "down" portion of the script into the database when the initial "up" migration is performed because the older app will not have the sql file embedded in it!
  • On "up" migrations, compare the database to the new list of migrations in the MigrationSource. Any extra migrations in the database need to be rolled back.

@@ -87,6 +87,7 @@ func (b byId) Less(i, j int) bool { return b[i].Less(b[j]) }
type MigrationRecord struct {
Id string `db:"id"`
AppliedAt time.Time `db:"applied_at"`
DownSql string `db:"down_sql"`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be a problem, anyone who is currently using sql-migrate won't have this column in their migrations table.

We've come at the sad point that we'll need to migrate the migrations table, but we have no way of doing so.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, that's a good point. I'll try to add something that detects an older database and migrate it but that feels "off", especially since package is meant to migrate databases!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. What if we store the DownSql in a separate new table? Does that let us avoid compatibility issues?

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.

3 participants