Command: Make Migrations (/mm)
Purpose: Create and deploy Prisma migrations for the backend when the schema changes.
When to use
- You modified
backend/prisma/schema.prismaand need to generate a migration. - The pre-commit migration guard indicates a missing migration.
What it does
- Generate a migration (files only) with a given or auto-generated name
- Deploy all pending migrations to the database
- Regenerate Prisma Client
Usage
# From repo root — auto name: auto_YYYYMMDD_HHMMSS
npm --prefix backend run prisma:migrate:dev -- --name "auto_$(date +%Y%m%d_%H%M%S)" --create-only
# Deploy and regenerate client
npm --prefix backend run prisma:migrate:deploy
npm --prefix backend run prisma:generate
Or with a custom name:
npm --prefix backend run prisma:migrate:dev -- --name my_change --create-only
npm --prefix backend run prisma:migrate:deploy
npm --prefix backend run prisma:generate
Requirements
- Environment variables configured as per
backend/docs/migration-structure.md:DATABASE_URL(pooled)DIRECT_URL(direct for migrations)SHADOW_DATABASE_URL(shadow schema/DB)
Troubleshooting
- Generation fails — Fix schema errors and re-run.
- Shadow DB error — Check
SHADOW_DATABASE_URLin.env. Must be a separate DB, not the main one. - Migration drift — Run
npx prisma migrate diffto inspect. May needprisma migrate resolve. - Dirty database — If dev DB has manual changes, consider
prisma migrate reset(destroys data).
See also
- Full migration docs:
backend/docs/migration-structure.md - Schema file:
backend/prisma/schema.prisma
Notes
- This command is non-interactive and safe for CI usage.