(Below is an example with MySQL)
Customize config/database.yml to handle multiple databases.
<%
# How to setup a custom database for a branch
branch = `git symbolic-ref HEAD 2>/dev/null`.chomp.sub('refs/heads/', '')
suffix = `git config --bool branch.#{branch}.database`.chomp == 'true' ? "_#{branch}" : "_development"