April 9th, 2009 by michael
git to manage your Ruby on Rails projects? Then you’ve probably come to appreciate topic branches as a kind of transaction facility for programmers. If you need to implement a non-trivial or just try something, the way to go is onto a new “topic” branch. There you can mangle the code all you like, without fearing to cause any lasting harm. In case everything works out fine, you merge the branch into the master branch and discard it. If you come to a dead end — well, you just discard the misbegotten branch.
But what about the database? If moving along your branch involves changes to the database, structural changes in particular, you can’t easily switch to another branch without these changes. In other words, your development database is really only suitable for a single branch.
Up to now, that is. Install the
branch_db gem and what you get is a private database for your branch that you can mutilate without interfering with work on the other branches.
For details and installation instructions see the README. Here’s just an appetizer. Say you’re on branch “feature” and want a private copy of the “master” database. Here’s how you do it:
$ rake db:branches:copy ORIG_BRANCH=master
- $ sudo gem install mschuerig-branch_db
Let your Rails app know about it
In the appropriate place in
config.gem "mschuerig-branch_db", :lib => 'branch_db'