Easily Manage DB Changes between branches in git
January 11th, 2009
About a month ago I ran into a pitfall in my git work flow. I had a topic branch where I was radically changing the schema and needed to flip back to another branch to fix some issue and found I had some new bizarre issues that had me scratching my head until I realized my db had changed from under me. Hmm.. I discussed the issue with some friends on irc and after a short while one of them came back with a quick solution he and his buddies at SevenWire whipped up and pushed out to github.
db_branch, is a simple plugin that will load an alternate database file for the current branch if it exists and some rake tasks to initialize the config file and databases.
Earlier today I worked on making it even better and added some tasks to clone an existing db and purge the branch dbs.
Git it on github, http://github.com/agile/db_branch/tree/master
1 2 |
git submodule add git://github.com/agile/db_branch.git vendor/plugins/db_branch rake db:branch |
So now my work flow when messing up the db, is something like..
1 2 3 4 5 6 7 8 9 10 11 |
git co -b messy_branch rake db:branch ./script generate migration making_a_mess # look at me, messing up my db, but it's ok because only this branch uses this db rake db:migrate git add db/migrate && git ci "committing the business" # and while I'm on that branch, I'll be using my awesomeapp_messy_branch db git co master #and I'm back to using my old awesomeapp db |
nice!
Taking it to eleven..?
I think I’d like to figure out how to tie it into git’s hooks so that it just automatically creates a db branch and clones when a new branch is created, then purges when the branch is deleted. That’d be hot.
Sorry, comments are closed for this article.