/prisma-migrate-safe — schema change that won't blow up prod
Prisma migrations have one infamous failure mode: an un-git-added migration.sql never reaches the prod box, and prisma migrate deploy silently no-ops it. This skill prevents that and the destructive-change traps.
Locate
- Glob
**/prisma/schema.prisma; migrations sit beside it inprisma/migrations/. - In a monorepo the schema usually lives under the API package (e.g.
apps/api/prisma/) — glob rather than guess.
Procedure
- Edit
schema.prisma— make the model change. Match existing field naming, relations, and@map/@@mapconventions already in the file. - Generate the migration from the dir holding
prisma/:npx prisma migrate dev --name <verb_noun>(e.g.add_status_to_asset). - READ the generated
migration.sqlbefore trusting it. Confirm it does what you intended and nothing more. - Destructive-change gate 🔴 — if the SQL contains
DROP COLUMN,DROP TABLE, a type change that truncates, or a newNOT NULLcolumn without a default on a populated table: STOP. Surface it, propose a safe path (add nullable → backfill → enforce), and get the user's OK before continuing. git add prisma/migrations/— the new folder +migration.sqlMUST be staged. This is the #1 reason a migration "didn't run" in prod.- Regenerate client if needed:
npx prisma generate. Typecheck:npx tsc --noEmit. - Prod: do NOT run migrate against prod by hand. Let it ship through your normal deploy path (
prisma migrate deployruns on the box).
Output
Report: schema diff summary, the migration name, the SQL verdict (safe / destructive-needs-plan), and confirmation that migrations are git-tracked.
Hard rules
- ⚠️ Never edit an already-applied migration file — create a new one.
- ⚠️ Never
migrate resetagainst anything with real data. - cwd discipline: background shells may start in the wrong repo — verify
git rev-parse --show-toplevelbeforegit add.