Supabase Migration Reliability (Production)
This runbook is the production-safe migration path for Switchbord.- Supabase project ref:
jazlpcbhkjtsbxeevesq - Repository:
switchbord - Migration source of truth:
supabase/migrations
1) Pre-flight checks
Run these checks before any production migration command.- Confirm you are in the correct repo and branch.
- Confirm migration SQL is reviewed and merged.
- Confirm a rollback owner and communication channel are in place.
- Confirm Supabase backup/PITR posture is healthy for the target window.
- Run the non-destructive helper script:
- env key presence and parsing pitfalls
- Supabase CLI install/login status
- link status for this repo
- migration list snapshots (linked + local when available)
2) Link the production project
Authenticate and link this working copy to the production project:3) Inspect migration drift
Before applying new migrations, inspect drift between migration files and production schema.4) Safe apply sequence for production
Use this exact sequence:- Freeze new migration merges during the window.
- Run preflight script and archive the generated snapshot files.
- Run
supabase db push --linked --dry-run --workdir .and review output. - Apply migrations:
- Immediately run verification checklist (section 6).
5) Recovery path using supabase migration repair
Use migration repair only to correct migration history metadata after you verify actual schema state.
It does not apply or revert SQL by itself.
Common cases:
- SQL already applied, but migration history is missing that version:
- Migration was marked applied, but schema change was not actually applied:
6) Verification checklist and rollback guidance
Verification checklist (run immediately after apply):supabase migration list --linked --workdir .shows expected versions applied.supabase db diff --linked --schema public --workdir .has no unexpected drift.- Runtime health checks remain green (
/health,/ready, critical endpoints). - Critical flows are smoke-tested (auth, inbox reads/writes, queue/worker path).
- No new errors in logs for RLS, missing columns, or enum cast failures.
- Default strategy is forward-fix, not in-place rollback.
- If apply fails mid-flight, pause deploys, assess schema state, and use
migration repairto realign metadata before re-running push. - For destructive mistakes or unrecoverable data impact, use Supabase backup/PITR restore to a known-good timestamp and follow incident response.
- Document the incident and the exact reconciliation steps before the next migration window.
7) Known Switchbord pitfalls
-
Enum
ALTER TYPE ... ADD VALUEmust be isolated.- We have explicit notes in migrations like:
20260417000002b_outbox_status_enum.sql20260418000001_member_role_billing.sql
- Do not combine enum value additions with schema objects that immediately depend on new enum values in the same transactional migration.
- We have explicit notes in migrations like:
-
Env parsing and alias pitfalls.
- Switchbord currently supports both canonical and legacy aliases:
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEYandNEXT_PUBLIC_SUPABASE_ANON_KEYSUPABASE_SECRET_KEYandSUPABASE_SERVICE_ROLE_KEY
- Mismatched alias values can cause inconsistent behavior across services.
- Trailing whitespace, CRLF, or accidental quoting in env values can break auth/linking unexpectedly.
- Switchbord currently supports both canonical and legacy aliases:
-
SUPABASE_DB_URLis required for direct Postgres/Vault operations.- If missing, migration-adjacent operational tasks can fail even when API key auth works.