Prisma Migrations in Production: Zero-Downtime Strategies and Rollback Patterns
Prisma Migrations in Production: Zero-Downtime Strategies and Rollback Patterns Running prisma migrate deploy in production without a plan is how you cause outages. Here's how to do database migrat...

Source: DEV Community
Prisma Migrations in Production: Zero-Downtime Strategies and Rollback Patterns Running prisma migrate deploy in production without a plan is how you cause outages. Here's how to do database migrations safely. The Problem Most migration guides show you the happy path. Production is messier: Live traffic during the migration window Old app version still running until deployment completes Failed migrations that need rollback Long-running migrations that lock tables Non-Destructive Migration Pattern The safest approach: expand, then contract. Step 1 — Expand (backward-compatible change): -- Add new column as nullable (safe while old code runs) ALTER TABLE users ADD COLUMN display_name TEXT; Step 2 — Backfill (background job): // scripts/backfill-display-name.ts const batchSize = 1000 let cursor: string | undefined while (true) { const users = await prisma.user.findMany({ take: batchSize, skip: cursor ? 1 : 0, cursor: cursor ? { id: cursor } : undefined, where: { displayName: null }, }) if