| name | prisma-safe-migrations |
| description | Use when modifying Prisma schema or creating migrations on tables with existing data, especially when adding columns or tightening constraints. |
Prisma Safe Migrations
Overview
Apply migration changes safely so production deploys do not fail under Helm/ArgoCD automation.
When To Use
- Adding columns to existing tables.
- Changing nullable fields to required.
- Introducing defaults or backfills.
- Editing generated migration SQL for data safety.
Rules
- Never add required columns to populated tables without default/backfill.
- Prefer nullable/default-first migration, then backfill, then tighten.
- Test migration logic locally before merge.
- Treat generated
migration.sql as editable source-of-truth when needed.
Safe Patterns
- Nullable first:
field String?
- Default first:
field String @default("...")
- Two-step tighten:
- Add nullable
- Backfill data
- Make required in follow-up migration
Checklist
- Update Prisma schema in
packages/prisma.
- Create migration:
pnpm --filter @luckyplans/prisma db:migrate:dev -- --name <name>.
- Review/edit migration SQL when backfill/default sequencing is needed.
- Re-run migration on realistic local data.
- Run
pnpm lint, pnpm type-check, pnpm build, pnpm format:check.
Common Mistakes
- Required column without default on non-empty table.
- Assuming Prisma auto-backfills data.
- Tightening constraints in one step without data preparation.