Skip to content

Exclude django_session data from DB dumps (#979)#1262

Open
IshanA2007 wants to merge 1 commit into
devfrom
979-exclude-sessions-db-backup
Open

Exclude django_session data from DB dumps (#979)#1262
IshanA2007 wants to merge 1 commit into
devfrom
979-exclude-sessions-db-backup

Conversation

@IshanA2007

@IshanA2007 IshanA2007 commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Closes #979

Problem

DB backups (latest.dump) were bloated (~150MB) because pg_dump included the django_session table. The app uses the cached_db session backend, so sessions are written to Postgres.

Fix

Added --exclude-table-data=django_session to the pg_dump command in both scripts/prod_dump.sh and scripts/local_dump.sh. This drops session rows while keeping the table schema, so restores recreate an empty-but-valid django_session.

Verification

  • bash -n on both scripts — clean.
  • Confirmed scripts/reset-db.sh restore (pg_restore --no-owner, --format=custom) stays compatible; no application code reads session rows directly.

Caveats

  • A restored DB starts with an empty session table (users re-login) — expected and harmless.
  • This does not prune the live DB's session table (the startup clearsessions step was dropped during the Terraform migration). A scheduled clearsessions is a reasonable follow-up if live-table growth is a concern.

🤖 Implemented with Claude Code.

Summary by CodeRabbit

  • Chores
    • Updated database dump behavior to omit session data from exported backups.
    • Kept all other dump settings, connection steps, and file output behavior unchanged.

Add --exclude-table-data=django_session to pg_dump in both
prod_dump.sh and local_dump.sh. This keeps the django_session
table schema but drops its rows, which were bloating the backup
(~150MB). The cached_db session backend recreates rows on demand,
so restores are unaffected.
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 40c5e1fd-d474-4c5d-8c0b-bdbab21665db

📥 Commits

Reviewing files that changed from the base of the PR and between ed955fb and 9a43582.

📒 Files selected for processing (2)
  • scripts/local_dump.sh
  • scripts/prod_dump.sh

📝 Walkthrough

Walkthrough

Both the local and production database dump scripts were updated to add --exclude-table-data=django_session to their respective pg_dump commands, excluding session table data from generated database dump files while preserving all other dump behavior.

Changes

DB dump exclusion

Layer / File(s) Summary
Exclude session data in dump commands
scripts/local_dump.sh, scripts/prod_dump.sh
Both pg_dump invocations are updated with --exclude-table-data=django_session to omit session row data from generated dumps.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main change: excluding django_session data from database dumps.
Description check ✅ Passed It covers the issue, problem, fix, verification, and notes, though it doesn't follow the exact template headings and omits screenshots.
Linked Issues check ✅ Passed The PR directly addresses #979 by excluding django_session rows from both dump scripts while preserving schema and restore compatibility.
Out of Scope Changes check ✅ Passed The changes are limited to the two dump scripts and match the stated backup-size reduction goal.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 979-exclude-sessions-db-backup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@IshanA2007
IshanA2007 marked this pull request as ready for review July 8, 2026 18:53
@IshanA2007 IshanA2007 self-assigned this Jul 8, 2026
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.

Clean Up Session Data in DB Backup

1 participant