Skip to content

Instantly share code, notes, and snippets.

@monsha
Last active September 12, 2018 20:45
Show Gist options
  • Save monsha/4b9be25cbc0236c8f5c88de2dc2c2125 to your computer and use it in GitHub Desktop.
Save monsha/4b9be25cbc0236c8f5c88de2dc2c2125 to your computer and use it in GitHub Desktop.
Database per branch - Rails
parent=$1
if [ -z $1 ]; then
echo "Parent db is empty"
echo "Using master"
parent="development_master"
fi
repo=`git rev-parse --abbrev-ref HEAD`
db=$(echo "development_$repo" | tr "-" "_")
echo 'Creating dev db'
createdb -U user -p 5433 -h localhost -T $parent $db
echo 'Done!'
<%
branch = `git rev-parse --abbrev-ref HEAD`.strip rescue nil
branch_spec = (branch.nil? ? "" : "_#{branch}").underscore.gsub(/[\.\/\-]/, '_')
%>
development:
<<: *default
database: app_development<%= branch_spec%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment