Skip to content

Instantly share code, notes, and snippets.

@thbar
Created March 16, 2012 11:25
Show Gist options
  • Save thbar/2049666 to your computer and use it in GitHub Desktop.
Save thbar/2049666 to your computer and use it in GitHub Desktop.
ERB template for git-branch aware database.yml (development/test only)
<%
# if you need to work on a branch with a different schema, use
# git config --bool branch.the-new-branch.database true
# http://mislav.uniqpath.com/rails/branching-the-database-along-with-your-code/
branch = `git symbolic-ref HEAD 2>/dev/null`.chomp.sub('refs/heads/', '')
suffix = `git config --bool branch.#{branch}.database`.chomp == 'true' ? "_#{branch}" : ""
%>
common: &common
adapter: mysql2
encoding: utf8
reconnect: false
pool: 5
username: root
development:
<<: *common
database: app_dev<%= suffix %>
test:
<<: *common
database: app_test<%= suffix %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment