# Zero-Downtime Supabase Migration Examples

Companion files for:

https://www.iloveblogs.blog/guides/zero-downtime-supabase-migrations

These examples show the expand/contract rollout for safely renaming `profiles.name` to `profiles.display_name` in a live Supabase Postgres project.

## Files

- `expand-contract-profiles.sql` - Complete staged SQL migration example.
- `batch-backfill.ts.txt` - Browser-readable TypeScript script that repeatedly calls a Supabase RPC backfill function until all rows are migrated.
- `github-actions-supabase-migrations.yml` - GitHub Actions workflow for local migration validation, dry-run, and production push.
- `migration-safety-check.js` - Conservative migration linter for risky SQL patterns.

## Rollout Order

1. Run the expand migration.
2. Deploy app code that dual-writes `name` and `display_name`.
3. Run the backfill script until it reports `0` remaining rows.
4. Run the validation migration.
5. Deploy app code that reads only `display_name`.
6. Run the contract migration in a later release.

Do not run the contract step until old application code is no longer serving traffic.
