Skip to content

Instantly share code, notes, and snippets.

@Narnach
Forked from FiXato/switch2branch.sh
Created January 15, 2009 12:08
Show Gist options
  • Save Narnach/47385 to your computer and use it in GitHub Desktop.
Save Narnach/47385 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Usage: s2b.sh branchname
# Easily switch between branches and their databases for Rails projects.
# Checks out given branch and copies the branch's database.yml to the active database.yml
# Outputs a small list of databases being used.
# Make sure you have set up your branch's database.yml in #{RAILS_ROOT}/config/database.#{branchname}.yml
git checkout $1 && cp config/database.$1.yml config/database.yml
databases=`grep --colour=auto database config/database.yml | grep -v ^# | sed s/database\:// | tr -d '\012' | sed -E s/^\ +\|\ +$// | sed -E s/\ +/,\ /g`
echo "Using databases: $databases"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment