Skip to content

feat(db): run Precedent and patch notes on each site's own Postgres - #250

Merged
ryanbarlow97 merged 3 commits into
mainfrom
self-hosted-postgres
Oct 16, 2026
Merged

ryanbarlow97 merged 3 commits into
mainfrom
self-hosted-postgres

Conversation

@ryanbarlow97

@ryanbarlow97 ryanbarlow97 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Why

Precedent and patch notes lived in a Supabase project used by nothing else, and Dev had no Precedent at all (its override drops the setting). This is step 1 of moving the site off Supabase and, later, province.db into the same Postgres.

What changes

  • db service in docker-compose.yml and docker-compose.staging.yml: pgvector/pgvector:pg17 (Supabase runs 17.6), volume db, healthcheck, no host port. The backend depends_on it as healthy. www's password comes from the project's .env (${POSTGRES_PASSWORD:?}); staging has a dev default. Staging's unused patchnotes-db (pg16) is replaced.
  • SUPABASE_DB_URL → DATABASE_URL in patchnotes/db.py, precedent/db.py, the Database studio (source id supabase → postgres) and backfill_precedent_embeddings.py, with the tests renamed to match.
  • site-deploy starts db (up -d --wait) when the checked-out compose file defines it, both before the backup and before the rebuild, and writes postgres.before-deploy-<sha>-<time>.dump (pg_dump -Fc), keeping 10. It checks the compose file first, so the first deploy of this commit (whose backup runs on the old checkout) doesn't fail.

Data (12 tables, 15 MB in Supabase)

public holds only the 10 patchnote_* tables and 2 precedent_* tables: 225 cases with vector(1024) embeddings, 32 audit rows and about 2,400 patch-note rows. There are no RLS policies, triggers or functions.

Host steps

Done before merge: both project .env files have a hex POSTGRES_PASSWORD (so each db volume is created with the real one, not the staging default), and www's backend/.env has DATABASE_URL with the Supabase URL.

After merge: install scripts/site-deploy.sh from the merge commit. The Dev deploy that the merge triggers runs the old installed script, which doesn't start db. That's harmless, because Dev has no DATABASE_URL until it's switched over. Then switch each site over by hand: ps-compose <site> up -d --wait db, stop the patch-note jobs, pg_dump -n public from Supabase, restore into db, compare row counts, point DATABASE_URL at db (adding it to Dev's override), recreate the backend and restart the jobs. Dev gets a copy of www's data. Supabase is left untouched as the fallback until both sites are checked.

Tests: src/patchnotes/test_db.py, src/precedent, src/dbstudio and test_precedent_routes.py: 128 passed, 3 skipped. Both compose files pass docker compose config.

Docs: TF-Minecraft/Docs#285

🤖 Generated with Claude Code

Precedent and patch notes lived in a Supabase project shared by nothing
else, and Dev had no database at all. Each site's compose project now has
a db service (pgvector, Postgres 17 to match Supabase), reached as db with
no host port, and the backend waits for it to be healthy.

- SUPABASE_DB_URL is renamed DATABASE_URL everywhere (the Database studio
  source id becomes postgres).
- site-deploy starts db when the checked-out compose file defines it and
  writes a pg_dump next to the province.db backup, keeping 10.
- Staging's unused patchnotes-db becomes db with the same settings as www.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 22 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9983ddd0-164f-4045-8a62-d0522b4d1247
📥 Commits

Reviewing files that changed from the base of the PR and between dd1e167 and 67061c5.

📒 Files selected for processing: 12
  • backend/.env.example
  • backend/src/api/test_precedent_routes.py
  • backend/src/dbstudio/studio.py
  • backend/src/dbstudio/test_studio.py
  • backend/src/patchnotes/db.py
  • backend/src/patchnotes/test_db.py
  • backend/src/precedent/db.py
  • backend/src/precedent/test_db.py
  • backend/src/scripts/backfill_precedent_embeddings.py
  • docker-compose.staging.yml
  • docker-compose.yml
  • scripts/site-deploy.sh
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

ryanbarlow97 and others added 2 commits October 16, 2026 17:26
…ample

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ryanbarlow97

Copy link
Copy Markdown
Contributor Author

Reviewed by Muse (muse-wonder-full) over two rounds; round 2 returned VERDICT: OK. The host switchover follows.

@ryanbarlow97
ryanbarlow97 merged commit 99dc9f6 into main Oct 16, 2026
6 checks passed
@ryanbarlow97
ryanbarlow97 deleted the self-hosted-postgres branch October 16, 2026 17:32

This branch was successfully deployed

1 active deployment
preview — 67061c5f Deployed Oct 16, 2026 by ryanbarlow97 via deploy #520
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