Skip to content

Instantly share code, notes, and snippets.

@yvesvanbroekhoven
Created September 2, 2014 09:20
Show Gist options
  • Save yvesvanbroekhoven/a2e083ccd1bbeb56ef70 to your computer and use it in GitHub Desktop.
Save yvesvanbroekhoven/a2e083ccd1bbeb56ef70 to your computer and use it in GitHub Desktop.
#
# Heroku pg:transfer shortcut
#
# Convention:
# - heroku app names end with -s for staging and -p for production (foo-s or foo-p)
# - local postgres db is named like client_appnamewithoutenv_development (client_foo_development)
#
# How to use:
# Place this in your ~/.bash_profile
# Go to a folder where heroku gem is installed
# Type in terminal:
# pgt bulo
#
#
function pgt {
if [ -z "$1" ]; then
echo "You need to give a heroku app name without environment. For example when 'app-p' you give 'app'"
return
fi
if [ "$1" == "-h" ]; then
echo "Do you need help? Call the A-Team."
return
fi
if [ -n "$2" ]; then
env="$2"
else
env="p"
fi
echo "---"
echo "Heroku App: $1-$env"
echo "Local database: client_${1//\-/_}_development"
echo "---"
echo "heroku pg:transfer --from DATABASE_URL --to postgres:///client_${1//\-/_}_development -a $1-$env -c $1-$env"
echo "---"
heroku pg:transfer --from DATABASE_URL --to postgres:///client_${1//\-/_}_development -a $1-$env -c $1-$env
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment