Skip to content

Add make dump_production to restore production db locally - #2792

Merged
mroderick merged 2 commits into
masterfrom
feature/dump-production-db
Aug 7, 2026
Merged

Add make dump_production to restore production db locally#2792
mroderick merged 2 commits into
masterfrom
feature/dump-production-db

Conversation

@mroderick

@mroderick mroderick commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

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 .sql dump files lying around.

Change

Add a single make dump_production target to the Makefile that pulls the live codebar-production database directly into the local codebar_production_dump postgres database, overwriting it on every run.

  • Connection details are fetched live via heroku pg:credentials:url, so nothing is hardcoded and it cannot go stale.
  • Pre-checks prerequisites (Heroku CLI and login, app reachability, local postgres) and fails loudly before touching the database.
  • Dumps to a temporary file first; the destructive schema reset only runs after a successful dump, so a failed run never destroys the previous local copy.
  • Uses --no-owner --no-acl so 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

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
mroderick marked this pull request as ready for review August 7, 2026 15:38
@mroderick
mroderick merged commit 77f72e6 into master Aug 7, 2026
9 checks passed
@mroderick
mroderick deleted the feature/dump-production-db branch August 7, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant