Skip to content

Instantly share code, notes, and snippets.

@zeroeth
Last active December 14, 2015 19:49
Show Gist options
  • Select an option

  • Save zeroeth/5139770 to your computer and use it in GitHub Desktop.

Select an option

Save zeroeth/5139770 to your computer and use it in GitHub Desktop.
per branch database.yml for rails
# add 'grit' and 'colored' to Gemfile
# you can delete the color methods on line #9 if you don't want to install colored gem.
# uses your typical app_development, app_test if git is under master.
# adds _branch_name to end if not.
<%
git_repo = Grit::Repo.new(".")
postfix = git_repo.head.name == 'master' ? nil : git_repo.head.name
app_name = Rails.application.class.parent_name.downcase
database = [app_name, Rails.env, postfix].compact.join("_")
puts "database branch: ".cyan.bold + "#{database}".magenta.bold
%>
defaults: &DEFAULTS
adapter: postgresql
encoding: unicode
pool: 5
username: userhere
password: xyzxyz
development:
<<: *DEFAULTS
database: <%= database %>
test: &TEST
<<: *DEFAULTS
database: <%= database %>
staging: &TEST
<<: *DEFAULTS
database: <%= database %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment