Skip to content

Instantly share code, notes, and snippets.

@thbar
Created January 22, 2013 08:09
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thbar/4592937 to your computer and use it in GitHub Desktop.
Save thbar/4592937 to your computer and use it in GitHub Desktop.
Little sh script to enable git config for branch-specific databases with Rails.
<%
# 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
pool: 5
username: root
# xxx
development:
<<: *common
database: app_dev<%= suffix %>
test:
<<: *common
database: app_test<%= suffix %>
#!/usr/bin/env bash
# change branch first then run this to quickly enable branch-specific database
git config --bool branch.$(ruby -e 'puts `git symbolic-ref HEAD 2>/dev/null`.split("/").last.chomp').database true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment