Skip to content

Instantly share code, notes, and snippets.

@zbruhnke
Created January 14, 2014 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zbruhnke/8412187 to your computer and use it in GitHub Desktop.
Save zbruhnke/8412187 to your computer and use it in GitHub Desktop.
heroku_pg_pull and heroku_pg_push -- for those of us who miss heroku pg:pull and heorku pg:push
# 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 -p "> " 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
}
# 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 -p "> " 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