Last active
March 4, 2020 12:08
-
-
Save richardvenneman/c4be5a9cda99448f88d43497f5ffff08 to your computer and use it in GitHub Desktop.
Pull Heroku Postgres DB excluding specific table data
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
# Using the `--exlude-table-data` argument for the `heroku pg:pull` command doesn't seem to be working. | |
# Instead we're going to copy the Heroku PG database by using the Postgres `pg_dump` and `pg_restore` commands. | |
# Get the "Connection info string" for myapp | |
heroku pg:credentials:url DATABASE_URL -a myapp | |
# Download the database, excluding the `visits` and `ahoy_events` table data. | |
pg_dump "<PASTE_CONNECTION_INFO_STRING_HERE>" --exclude-table-data visits --exclude-table-data ahoy_events -O -x -Fc -f without_vists_and_ahoy_events.out -v | |
# In myapp, setup an empty database | |
bin/rails db:drop && bin/rails db:create | |
# Finally, restore the dump | |
pg_restore --verbose --clean --no-acl --no-owner -h localhost -d myapp without_vists_and_ahoy_events.out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool! Thanks for letting me know!