# Preview environments for database changes

Application preview deployments without a matching database preview prove nothing about migrations. Pair them: one Supabase branch per pull request, wired to that PR's preview deployment.

## Checkable procedure

1. On PR open, create a Supabase branch. Apply the PR's migrations to it. Point the PR's preview deployment at the branch credentials.
2. Seed the branch with production-shaped data (anonymized). An empty database passes tests that real data would fail, especially around constraints and RLS.
3. Run CI against the branch database: migrations apply cleanly, the test suite passes, and the app's critical paths work end to end.
4. Review the migration diff as part of the PR review. The branch proves it applies; the review proves it is correct and reversible.
5. On merge, apply the migrations to production and delete the branch. Stale branches accumulate data and cost; the merge is the trigger for cleanup.

## Ordering constraints

Branch before preview deploy. Migrations on the branch before CI. Production migration only after PR merge. The sequence is the safety.

## Verification

Open a PR with a deliberately breaking migration and confirm CI fails against the branch before it ever touches production. That failure is the system working.