This is blatently summarized from here: http://dgmstuart.github.io/blog/2017/04/12/how-to-recover-from-rails-database-schema-conflicts-when-rebasing/
I wanted a more succeinct version available to me.
- Try to manually merge it
- Checkout and pull and ensure the database agrees with the schema.
- Run
rake db:migrate:status
and ensure everything is 'up'- If anything is marked 'down' run
rake db:migrate
- If anything is marked *** NO FILE *** your db had a migration run against it outside of the current branch.
- You can switch to the branch with the migration and rollback there.
- If anything is marked 'down' run
- Run your rebase:
git pull --rebase origin master
- At the first conflict, unstage the schema diff from your new branch:
git reset HEAD db/schema.rb
- Discard the schema diff from your new branch:
git checkout db/schema.rb
- Rebuild the schema:
rake db:migrate
-
Check the resulting schema diff against the original diff on your branch (e.g. by looking at the commit on the pull request) - it should be identical
- …with one exception: if the migration you’re adding was created before any of the migrations on develop, then the version in the schema file won’t change. This is expected: that version should always relate to the most recently generated migration.
That’s it! You can now continue your rebase.