Skip to content
Back to Deployment

Prisma Migrate

Type-safe ORM migrations for Postgres, MySQL, MongoDB, and SQLite.

CI/CDIntermediate

Why

Prisma Migrate generates SQL from schema changes, with type-safe client regeneration. It handles dev migrations, production deploys, and migration history.

DORA's 2024 State of DevOps report shows elite teams deploy 973x more frequently than low performers. CI/CD pipelines with automated testing reduce change failure rate to 5-15% versus 40-60% for manual deployments.

When

Use Prisma Migrate with Prisma ORM for type-safe DB access. Avoid for non-Prisma projects.

How

1. Schema — schema.prisma with datasource + generator 2. Dev — npx prisma migrate dev --name init (creates + applies) 3. Deploy — npx prisma migrate deploy (production, applies pending) 4. Reset — npx prisma migrate reset (dev only, drops data) 5. Status — npx prisma migrate status 6. Studio — npx prisma studio (GUI for data) 7. Generate — npx prisma generate (regenerate client)

Example

// schema.prisma generator client { provider = "prisma-client-js" } datasource db { provider = "postgresql"; url = env("DATABASE_URL") } model User { id Int @id @default(autoIncrement()) email String @unique posts Post[] } model Post { id Int @id @default(autoIncrement()); author User @relation(fields: [authorId], references: [id]); authorId Int } # Development — create and apply migration npx prisma migrate dev --name add_posts # Production — apply pending migrations only npx prisma migrate deploy # In CI — generate client after migrate npx prisma migrate deploy && npx prisma generate

Common Problems

  • ⚠Migration drift — schema and migrations out of sync, run prisma migrate dev to reconcile
  • ⚠Shadow DB error — needs CREATE DATABASE permission for dev migrations
  • ⚠Configuration drift between environments — use infrastructure-as-code (Terraform/Pulumi) to keep dev/staging/prod identical

Best Practices

  • ✓Use migrate deploy in production — applies pending only, no new migrations
  • ✓Commit migrations to git — team shares migration history
  • ✓Set up health checks and graceful shutdown — handle SIGTERM to drain in-flight requests before exit

FAQ