Prisma Migrations in Production: Zero-Downtime Deployments With Expand-Contract
Prisma migrations can take your app down if done wrong. Running prisma migrate deploy on a live database while traffic is flowing is how you get a 3 AM incident. Here's the zero-downtime migration ...

Source: DEV Community
Prisma migrations can take your app down if done wrong. Running prisma migrate deploy on a live database while traffic is flowing is how you get a 3 AM incident. Here's the zero-downtime migration strategy. Why Migrations Break Production The danger zone: your migration runs while old code is still serving requests. Example: You rename column user_name to username Migration runs -- old column gone, new column exists Old app instances still query user_name -- crash Even a 2-second deploy window causes errors. At scale, deploys take minutes. The Expand-Contract Pattern The solution: never remove or rename in one step. Expand first, contract later. Phase 1: Expand (backwards-compatible) Add new column alongside old one New code writes to both columns Old code still reads from old column -- no breakage Phase 2: Migrate data Backfill new column from old column Verify all rows have new column populated Phase 3: Contract (after all old instances are gone) New code reads from new column only D