db migrate
Apply pending Prisma ORM migrations.
db migrate applies pending on-disk migrations to advance the database. It walks every contract space and applies migrations in canonical order: extensions alphabetically, then the app. It applies only the migrations that exist on disk and never generates new operations.
Prisma ORM keeps one migration history for your own models, called the app space, in migrations/app/, and one for each extension package that ships its own migrations, such as pgvector. Each of these histories is a contract space.
Use it from a controlled deployment step after reviewing migration packages.
bunx prisma db migrate --db "$DATABASE_URL"pnpm prisma db migrate --db "$DATABASE_URL"yarn prisma db migrate --db "$DATABASE_URL"npx prisma db migrate --db "$DATABASE_URL"Options
Section titled “Options”| Option | What it does |
|---|---|
--db <url> |
Connects to the database. |
--to <contract> |
Applies migrations up to a target contract state. Accepts a contract reference: a hash, a hash prefix, a ref name, a migration directory name, or <dir>^. With --show, it also accepts the tokens @contract and @empty. |
--advance-ref <name> |
Advances the named ref to the post-apply marker after success. |
--show |
Previews the migration route without applying (read-only). |
--from <contract> |
Use it with --show, where it sets the starting state for the preview. Accepts a contract reference: a hash, a hash prefix, a ref name, a migration directory name, <dir>^, @contract, @db, or @empty. |
--config <path> |
Read this config file instead of ./prisma.config.ts. |
--json |
Prints a machine-readable result. |
Contract references
Section titled “Contract references”A ref name is a name you gave a contract state with migration ref set, such as prod. <dir>^ is a migration directory name followed by ^, and it names the contract state before that migration, while the directory name alone names the state after it. Contract references each command accepts lists the forms for every command.
@contract names the contract in contract.json, which contract emit writes. The database stores a marker, a row that says which contract state it matches. @db names that state. @empty names the empty database, before any migration.
Recommended flow
Section titled “Recommended flow”bunx prisma migration status --db "$DATABASE_URL"
bunx prisma db migrate --db "$DATABASE_URL"
bunx prisma migration status --db "$DATABASE_URL"
bunx prisma db verify --db "$DATABASE_URL"pnpm prisma migration status --db "$DATABASE_URL"
pnpm prisma db migrate --db "$DATABASE_URL"
pnpm prisma migration status --db "$DATABASE_URL"
pnpm prisma db verify --db "$DATABASE_URL"yarn prisma migration status --db "$DATABASE_URL"
yarn prisma db migrate --db "$DATABASE_URL"
yarn prisma migration status --db "$DATABASE_URL"
yarn prisma db verify --db "$DATABASE_URL"npx prisma migration status --db "$DATABASE_URL"
npx prisma db migrate --db "$DATABASE_URL"
npx prisma migration status --db "$DATABASE_URL"
npx prisma db verify --db "$DATABASE_URL"Run migration status before and after applying migrations to see what changed.
Previewing the route
Section titled “Previewing the route”--show prints the route db migrate would take without touching the database:
bunx prisma db migrate --show
bunx prisma db migrate --show --from @contract --to productionpnpm prisma db migrate --show
pnpm prisma db migrate --show --from @contract --to productionyarn prisma db migrate --show
yarn prisma db migrate --show --from @contract --to productionnpx prisma db migrate --show
npx prisma db migrate --show --from @contract --to productionApplying to a target
Section titled “Applying to a target”If your project uses named refs, apply up to a target ref:
bunx prisma db migrate --db "$DATABASE_URL" --to productionpnpm prisma db migrate --db "$DATABASE_URL" --to productionyarn prisma db migrate --db "$DATABASE_URL" --to productionnpx prisma db migrate --db "$DATABASE_URL" --to productionManage refs with migration ref.