Last active
January 17, 2018 15:13
-
-
Save adamlogic/37faf41cbfc97cb20e58d828632c2d80 to your computer and use it in GitHub Desktop.
Wrapper script around `heroku pg:pull` for loading a local database
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/bash | |
# Example: | |
# pgpull -r production | |
# | |
# Options are passed through to `heroku pg:pull`, so this would look for a git branch | |
# named "production". | |
opts=$* | |
# Replace this with your local database name | |
local_db=my_app_development | |
remote_db=$(heroku pg:info $opts | grep 'Add-on' | cut -d: -f2 | tr -d '[:space:]') | |
echo "--- killing any connections to the local DB so we can drop it" | |
psql -d $local_db -c "select pg_terminate_backend(pid) from pg_stat_activity where datname='$local_db';" > /dev/null 2>&1 | |
echo "--- dropping local DB" | |
dropdb $local_db --if-exists | |
echo "--- pulling remote DB" | |
heroku pg:pull $remote_db $local_db $opts | |
echo "--- wiping sensitive data" | |
# This is a placeholder. Wipe out any data that's personally identifying or could result in impacting real users. | |
psql -d $local_db -c "update users set email = 'REDACTED';" > /dev/null 2>&1 | |
psql -d $local_db -c "update apps set slack_webhook_url = 'REDACTED';" > /dev/null 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@adamlogic, I had to change line 12 to cut field 3, not 2 in order for it to grab the correct database name. I am running
heroku-cli/6.15.13-3dce47c
if it matters.