(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"
db_socket = ENV['DEV_MYSQL_SOCKET'] || "/tmp/mysql.sock" # Check env var for db socket path, defaults to OSX db socket path
%>
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: portal<%= suffix %>
pool: 5
username: root
password:
socket: <%= db_socket %>
Create a new branch
git branch your_new_branch
git checkout your_new_branch
Opt-in for the branch specific database
git config --bool branch.your_new_branch.database true
Create the new database and load schema.rb
rake db:create
Initialize the database without previous database content run
rake db:schema:load
To copy the current development database to the newly created one (example for MySQL)
mysqldump -u root yourapp_development | mysql -u root yourapp_your_new_branch
(Make sure that the database you are copying from is the same branch as your_new_branch
was branched form.)
Check: config/database.yml
Verify that the database has successfully been created