This script is a convenience script which can be run as
doctrine-checkout.sh some-branch
instead of git checkout some-branch
whenever you switch between feature branches in a Symfony2 + Doctrine project.
It cleanly migrates backwards to the first common migration between two diverging branches and then migrates back up to the latest migration in the branch you check out. If you always run this when switching branches, and your migrations aren't too buggy, then hopefully your database will always be correct and you won't have problems creating new migrations.
If anyone knows a better way of doing this, please let me know. This doesn't use git-hooks because I don't like the idea of this running without me saying so explicitly.
Note: If you rebase branches, it's possible that migrations with a date older than the most recent migration get introduced in further ahead commits. This script can't work in those cases, but you can amend the commits in your branch to change the date of an out-of-order migration to a more recent date.