Last active
January 4, 2016 10:49
-
-
Save matthewlehner/8610839 to your computer and use it in GitHub Desktop.
zsh (maybe bash too?) scripts for pulling and pushing Heroku dbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Postgres equivalent to heroku db:pull. | |
# Pulls latest heroku pgbackups dump into local database | |
# | |
# Usage: | |
# | |
# $ heroku_pg_pull [appname] [local database name] | |
# | |
function heroku_pg_pull(){ | |
echo "! WARNING: Data in the local database '$2' will be destroyed." | |
echo " Type '$2' to overwrite data in local database '$2'" | |
read "local_database_name?> " | |
echo | |
if [[ "$local_database_name" == "$2" ]]; then | |
curl -o heroku_pg_pull_latest_backup.dump `heroku pgbackups:url -a $1`; | |
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U `whoami` -d $2 heroku_pg_pull_latest_backup.dump; | |
rm heroku_pg_pull_latest_backup.dump; | |
else | |
echo "Aborted" | |
fi | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Postgres equivalent to heroku db:push. | |
# Pushes local database up to heroku application database. | |
# Requirements: psql --version >= 9.2.2 | |
# | |
# Usage: | |
# | |
# $ heroku_pg_push [appname] [local database name] | |
# | |
function heroku_pg_push(){ | |
echo "! WARNING: Data in the Heroku app '$1' will be destroyed." | |
echo " Type '$1' to overwrite data in Heroku app '$1'" | |
read "heroku_app_name?> " | |
echo | |
if [[ "$heroku_app_name" == "$1" ]]; then | |
heroku pg:reset DATABASE_URL -a $1 | |
pg_dump -xO $2 | psql `heroku config:get DATABASE_URL -a $1` | |
else | |
echo "Aborted" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment