Uh oh!
There was an error while loading. Please reload this page.
feat(db): migration runner + ordered migrations (#197, #196) - #252
Conversation
App runtime stays on PostgREST via db/connection.py; psycopg is admin tooling for db/migrate.py, which needs a direct Postgres connection to run DDL. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Numeric NNNN_ prefixes lock apply order so the runner (and humans) have a single documented sequence. seed.sql and archive/ stay put — they are not migrations. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure, DB-free functions (ordered discovery + pending filter) with unit tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Adds schema_migrations tracking, per-file transactional apply, a --baseline mode to adopt the runner on an already-migrated DB, and a CLI that reads SUPABASE_DB_URL. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Guard each ADD CONSTRAINT on pg_constraint so re-running the migration no longer fails on already-present constraints. Verified at runtime once a DB exists (Phase 1). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Warning Review limit reached
More reviews will be available in 45 minutes and 52 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (21)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Deploying with |
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ❌ Deployment failed View logs | frontend | 3541cb9 | Jun 22 2026, 04:11 AM |
What
Phase 0 of the staging-environment plan (#246): a minimal, reproducible migration runner so migrations apply identically across environments instead of being hand-pasted into the Supabase SQL editor. Self-contained and useful on its own.
Closes#197. Closes#196.
Changes
backend/db/migrate.py— the runner.discover_migrations(ordered) +pending_migrations(pure, unit-tested);ensure_tracking_table/applied_filenames/apply_migrationover psycopg; a--baselinemode to adopt the runner on an already-migrated DB; a CLI readingSUPABASE_DB_URL(Supabase direct connection, not the pooler).backend/db/migrations/— existingmigration_*.sql+supabase_schema.sqlmoved here withNNNN_prefixes that lock apply order (pure renames, zero content change).seed.sqlandarchive/stay put.backend/db/migrations/0009_cosmetics.sql— everyADD CONSTRAINTguarded onpg_constraintso re-runs no longer error (migration_cosmetics.sql adds FK constraints non-idempotently — re-run fails #196).backend/requirements.txt—psycopg[binary]>=3.2,<4, clearly scoped as admin-only tooling (app runtime stays on PostgREST viadb/connection.py).Why a direct Postgres connection
App runtime goes through PostgREST (
db/connection.py::table()), which cannot run DDL. Migrations are raw DDL, so the runner is the one sanctioned direct-Postgres path. This is documented in the module docstring.Testing
pytest tests/test_migrate.py— 2 passed (ordering + pending-filter logic).SUPABASE_DB_URLprints a friendly error and exits 1.apply/--baselineand the migration_cosmetics.sql adds FK constraints non-idempotently — re-run fails #196 idempotency re-run need a live Postgres, which lands with the staging project (Phase 1). Thepg_constraintguard is the standard idempotency pattern.Adoption note
Before first use against the existing prod DB, run
python -m db.migrate --baselineonce to record all current migrations as applied (so it doesn't try to re-run already-applied SQL). Fresh DBs (staging) just runpython -m db.migrate.Relates to #246 (design + full plan).
🤖 Generated with Claude Code