Add make dump_production to restore production db locally - #2792
Merged
Conversation
Add a `make dump_production` target that pulls the live codebar-production Heroku database directly into the local `codebar_production_dump` postgres database, overwriting it on every run. Use it as the starting point for working against production data locally. Connection details are fetched live via `heroku pg:credentials:url` (with the postgres:// URL extracted from its multi-line output), so no credentials are hardcoded and they cannot go stale. The target pre-checks its prerequisites (Heroku CLI and login, app reachability, local postgres) and fails loudly before touching the database. The dump is written to a temporary file first; only after it succeeds is the local schema dropped and the restore run, so a failed dump never destroys the previous local copy. `--no-owner --no-acl` stops production roles colliding with local ones, and the temp file is cleaned up on success and on every failure path.
mroderick
marked this pull request as ready for review
August 7, 2026 15:38
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I often make a local snapshot of the production database to run analysis on when investigating bugs. It would be convenient, if this was a single command with solid pre-conditions check ... hence this PR.
Problem
Working against production data locally requires dumping the codebar-production Heroku database into a local postgres copy. That is currently a manual, multi-step process that hardcodes connection details and leaves
.sqldump files lying around.Change
Add a single
make dump_productiontarget to theMakefilethat pulls the livecodebar-productiondatabase directly into the localcodebar_production_dumppostgres database, overwriting it on every run.heroku pg:credentials:url, so nothing is hardcoded and it cannot go stale.--no-owner --no-aclso production roles don't collide with local ones; the temp file is cleaned up on success and on every failure path.Verification
End-to-end run restored 29,373 members in ~76s; tables owned by local user (no prod-role collisions); confirmed a failing dump aborts without printing "Done" and leaves the prior copy intact.
How to use
make dump_production