Last active
May 17, 2024 21:20
-
-
Save stevenharman/6515891 to your computer and use it in GitHub Desktop.
Fork and promote one Heroku app's Postgres Database to another app.
This file contains hidden or 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
#!/bin/sh | |
set -e | |
app=${1} | |
staging_app=staging-${app} | |
db_type=${2:-crane} | |
old_db=`heroku config -a ${staging_app} | grep ^HEROKU_POSTGRESQL | cut -d : -f 1 | sed s/_URL//` | |
heroku addons:add heroku-postgresql:${db_type} --fork `heroku config -a ${app} | grep ^DATABASE_URL | cut -d : -f 2-5` -a ${staging_app} | |
# Fork and promote new db for staging | |
new_db=`heroku config -a ${staging_app} | grep ^HEROKU_POSTGRESQL | grep -v ${old_db} | cut -d : -f 1 | sed s/_URL//` | |
heroku pg:wait -a ${staging_app} | |
heroku pg:promote ${new_db} -a ${staging_app} | |
# Remove the old staging db | |
if [ ! -z "${old_db}" ]l; then | |
heroku addons:remove ${old_db} -a ${staging_app} --confirm ${staging_app} | |
fi | |
set +e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment