Schema management in teams
Plan, merge, and apply Prisma ORM migrations when several developers change the schema at the same time.
Introduction
When a team works on one schema, two people change it at the same time. In Prisma ORM, migrations form a graph rather than a numbered list, so parallel changes do not force anyone to rename files or rebuild history. This guide shows how that works day to day: what to commit, how to incorporate a teammate's migration, and how to resolve the case where two branches planned a migration from the same starting point and both merged.
Every command and every output below was run against a Git repository with three checkouts (two teammates and you), each with its own local PostgreSQL database.
Prisma ORM 8 is a release candidate. Prisma ORM 7 remains fully supported; the Prisma ORM 7 version of this guide is at /guides/v7/database/schema-changes.
Prerequisites
- Node.js 22.18 or newer on the 22 line, 24.11 or newer on the 24 line, or 26 or newer (24 recommended)
- A Prisma ORM project with a contract and at least one migration (Create a new app with PostgreSQL gives you one)
- A PostgreSQL database per developer, reachable as
DATABASE_URL - Basic familiarity with Git branches and merges
- The migration loop:
contract emit,migration plan,db migrate
Use with your agent
To delegate the pull-and-apply part of this guide to your coding agent, copy the prompt below and hand it over:
1. Understand migration basics
1.1. Migrations form a graph
Each migration directory records the contract state it starts from and the state it ends at, to, as hashes in its migration.json. Those links are the migration history. The timestamp in the directory name is for humans; nothing depends on it. That is why two developers can plan migrations from the same state on separate branches and merge without renaming anything. The migration graph explains the model in full.
Three commands answer the questions a team asks most:
| Question | Command | Needs a database? |
|---|---|---|
| What does the history look like? | npx prisma migration graph | No |
| Where is my database, and what is pending? | npx prisma migration status | Yes |
| Do the migration files on this branch hold together? | npx prisma migration check | No |
1.2. Commit these files
Commit everything Prisma ORM needs to rebuild a database from scratch:
src/prisma/contract.prisma, the schema you authorsrc/prisma/contract.jsonandsrc/prisma/contract.d.ts, the emitted contract (generated, but committed;orm initmarks themlinguist-generatedin.gitattributes)migrations/app/, every migration directory:migration.ts,ops.json, andmigration.jsontogethermigrations/snapshots/, the contract snapshots migrations are typed againstmigrations/app/refs/, named refs, including thedbref described nextprisma.config.ts
Do not commit .env. orm init already lists it in .gitignore.
1.3. Where a plan starts
migration plan is offline. It never asks the database which contract state it matches, so you have to tell it which state to plan from. It resolves the origin in this order: an explicit --from, otherwise the ref named db in migrations/app/refs/db.json, otherwise the empty database. Keep the db ref pointing at the state your local database matches by applying with --advance-ref db:
bunx prisma db migrate --advance-ref dbDo that every time you apply, and every plan chains from the right place without flags. Section 3 shows what happens when it cannot.
1.4. The project this guide starts from
The project was created with npx prisma@latest orm init --yes --target postgres --authoring psl and has this contract:
// use prisma-8
model User {
id Int @id @default(autoincrement())
email String @unique
username String?
name String?
posts Post[]
createdAt TimestamptzString @default(now())
updatedAt DateTime(as: string) @onCreate(now()) @onUpdate(now())
}
model Post {
id Int @id @default(autoincrement())
title String
content String?
author User @relation(fields: [authorId], references: [id])
authorId Int
createdAt TimestamptzString @default(now())
updatedAt DateTime(as: string) @onCreate(now()) @onUpdate(now())
}Its first migration was planned and applied on main with:
bunx prisma migration plan --name init
bunx prisma db migrate --advance-ref db✔ Applied 1 migration(s) (6 operation(s)) across 1 contract space(s)
App space
├─ Create schema "public"
├─ Create table "Post"
├─ Create table "User"
├─ Add unique constraint on "User" (email)
├─ Create index "Post_authorId_idx_e47547ed" on "Post"
├─ Add foreign key "Post_authorId_fkey" on "Post"
└─ marker 91e7f9f035806fa2789a4d726ef7724cad434fd6b00014d47ebf12d6e6bb784e
✔ Advanced ref "db" → 91e7f9f035806fa2789a4d726ef7724cad434fd6b00014d47ebf12d6e6bb784e
→ Check every space against the database: prisma migration statusEvery developer clones this repository, points DATABASE_URL in their .env at their own database, and runs npx prisma db migrate once to bring it to the same state.
2. Incorporate team changes
2.1. Pull, check, apply
When a teammate merges a schema change, it arrives as three things: an edited contract.prisma, the re-emitted contract.json and contract.d.ts, and a new migration directory. Pull them, then ask Prisma which contract state your database matches:
git pullbunx prisma migration statusIf nothing changed, you see the whole history marked applied:
○ 91e7f9f @contract @db (db)
│↑ 20260910T1543_init ∅ → 91e7f9f 6 ops ✓ applied
○ ∅
✔ Up to date@db marks the contract state your database matches, @contract the emitted contract, and (db) the state the db ref names. When migrations are pending, the tree flags each one with ⧗ pending and a summary line tells you how many. Apply them and update the db ref in one step:
bunx prisma db migrate --advance-ref dbThere is no generate step after applying: your typed client reads contract.json, which you just pulled.
2.2. Example scenario
The rest of this guide follows three developers changing the same contract. Ania adds a favoriteColor field, Javier adds a Tag model, and you add a bestPacmanScore field:
model User {
id Int @id @default(autoincrement())
email String @unique
username String?
name String?
posts Post[]
createdAt TimestamptzString @default(now())
updatedAt DateTime(as: string) @onCreate(now()) @onUpdate(now())
}3. Handle concurrent changes
Ania and Javier both branch from the same commit on main, where the db ref points at the init state.
3.1. Ania adds a field
On her branch, Ania adds the field:
model User {
/* ... */
favoriteColor String?
}Then she emits, plans, and applies to her own database:
bunx prisma contract emit
bunx prisma migration plan --name add_favorite_color✔ Planned 1 operation(s)
migrations/app/20260910T1546_add_favorite_color
└─ Add column "favoriteColor" to "User"
from: 91e7f9f035806fa2789a4d726ef7724cad434fd6b00014d47ebf12d6e6bb784e
to: b29af3990b528c7a67809a2ac609305c59aa9c0af1ed0e4591cc0a727b38b1d1
app space: migrations/app/20260910T1546_add_favorite_color
ℹ DDL preview
ALTER TABLE "public"."User" ADD COLUMN "favoriteColor" text;The from: line is the init state, taken from the db ref. She applies and commits:
bunx prisma db migrate --advance-ref db✔ Applied 1 migration(s) (1 operation(s)) across 1 contract space(s)
App space
├─ Add column "favoriteColor" to "User"
└─ marker b29af3990b528c7a67809a2ac609305c59aa9c0af1ed0e4591cc0a727b38b1d1
✔ Advanced ref "db" → b29af3990b528c7a67809a2ac609305c59aa9c0af1ed0e4591cc0a727b38b1d1git add -A
git commit -m "Add User.favoriteColor"3.2. Javier adds a model
On his branch, from the same starting commit, Javier adds a model:
model Tag {
tagName String @id
tagCategory String
}bunx prisma contract emit
bunx prisma migration plan --name add_tag_model✔ Planned 1 operation(s)
migrations/app/20260910T1547_add_tag_model
└─ Create table "Tag"
from: 91e7f9f035806fa2789a4d726ef7724cad434fd6b00014d47ebf12d6e6bb784e
to: 18b24e59a8b291a37b50e0d82c7afb58b314a2b64920d530627c73bd6e2d9768
app space: migrations/app/20260910T1547_add_tag_model
ℹ DDL preview
CREATE TABLE "public"."Tag" (
"tagCategory" text NOT NULL,
"tagName" text NOT NULL,
PRIMARY KEY ("tagName")
);His plan also starts from: the init state. He applies with db migrate --advance-ref db and commits. Both migrations now leave the same node and arrive at different ones. Neither developer knows about the other yet, and neither needs to.
3.3. Merge both branches
Ania's branch merges into main first, as a fast-forward. Javier's merge conflicts:
git merge javier/tag-modelAuto-merging migrations/app/refs/db.json
CONFLICT (content): Merge conflict in migrations/app/refs/db.json
Auto-merging src/prisma/contract.d.ts
CONFLICT (content): Merge conflict in src/prisma/contract.d.ts
Auto-merging src/prisma/contract.json
CONFLICT (content): Merge conflict in src/prisma/contract.json
Auto-merging src/prisma/contract.prisma
Automatic merge failed; fix conflicts and then commit the result.Read the list carefully. contract.prisma, the file you author, merged cleanly: the two edits touch different parts of the schema. The three conflicts are all in files Prisma writes for you, and none of them needs hand editing:
contract.jsonandcontract.d.tsare emitted fromcontract.prisma. Re-emit and they are regenerated from the merged source, conflict markers and all:
bunx prisma contract emit✔ Emitted contract.json and contract.d.ts
storageHash: 1e5059c1976c2439863eae8ac13211916ca411614c917394c413346f0d00f60bmigrations/app/refs/db.jsonrecords the contract state a local database last matched. Each branch pointed it at its own state, and neither is the state your database matches now. Take either side; you will set it correctly when you apply in section 3.5.
git checkout --ours migrations/app/refs/db.jsonDo not commit yet. The graph is not finished.
3.4. What Prisma reports after the merge
Draw the graph:
bunx prisma migration graph○ 1e5059c @contract
○ b29af39 (db)
│↑ 20260910T1546_add_favorite_color 91e7f9f → b29af39 1 ops
│ ○ 18b24e5
│ │↑ 20260910T1547_add_tag_model 91e7f9f → 18b24e5 1 ops
│─╯
○ 91e7f9f
│↑ 20260910T1543_init ∅ → 91e7f9f 6 ops
○ ∅
1 space(s), 4 contract(s), 3 migration(s)Read it bottom-up. From init (91e7f9f) two branches leave: Ania's ends at b29af39, Javier's at 18b24e5. The merged contract you just emitted, 1e5059c, sits at the top with no edge arriving at it. No database can reach it yet. migration status draws the same graph and marks where your database is, which is still on init (@db):
bunx prisma migration status○ 1e5059c @contract
○ b29af39 (db)
│↑ 20260910T1546_add_favorite_color 91e7f9f → b29af39 1 ops
│ ○ 18b24e5
│ │↑ 20260910T1547_add_tag_model 91e7f9f → 18b24e5 1 ops
│─╯
○ 91e7f9f @db
│↑ 20260910T1543_init ∅ → 91e7f9f 6 ops ✓ applied
○ ∅
⚠ No migration path from the database state (91e7f9f03580) to the application's contract (1e5059c1976c). Run `prisma migration plan --name <name>` to author one.Do not follow that hint literally. Without --from, the planner takes the db ref as its origin, and after git checkout --ours that ref is Ania's tip, so migration plan --name merge_schema writes only the half of the merge her branch is missing. Javier's database would still have no path to the top. Had the ref still pointed at init, the planner would have started a third branch from the divergence point instead, with a warning that it forks the graph. Neither is the merge. Do not delete either branch's migration directory to get out of this: Ania's and Javier's databases have already applied those migrations. Name the origin yourself, once per tip.
3.5. Close the diamond
Plan one merge migration from each tip. Each one carries the change its branch is missing, and both arrive at the merged contract:
bunx prisma migration plan --from 20260910T1546_add_favorite_color --name merge_add_tag_model✔ Planned 1 operation(s)
migrations/app/20260910T1550_merge_add_tag_model
└─ Create table "Tag"
from: b29af3990b528c7a67809a2ac609305c59aa9c0af1ed0e4591cc0a727b38b1d1
to: 1e5059c1976c2439863eae8ac13211916ca411614c917394c413346f0d00f60bbunx prisma migration plan --from 20260910T1547_add_tag_model --name merge_add_favorite_color✔ Planned 1 operation(s)
migrations/app/20260910T1550_merge_add_favorite_color
└─ Add column "favoriteColor" to "User"
from: 18b24e59a8b291a37b50e0d82c7afb58b314a2b64920d530627c73bd6e2d9768
to: 1e5059c1976c2439863eae8ac13211916ca411614c917394c413346f0d00f60b--from accepts a migration directory name, as here, or a contract hash from the graph. The planner diffs the two contract snapshots and writes exactly the operations that are missing on that side. Review both DDL previews the way you would review any migration. The graph is now a diamond, and every database on either branch has a path to the top:
bunx prisma migration graph○ 1e5059c @contract
│─╮
│↑│ 20260910T1550_merge_add_tag_model b29af39 → 1e5059c 1 ops
│ │↑ 20260910T1550_merge_add_favorite_color 18b24e5 → 1e5059c 1 ops
○ │ b29af39 (db)
│↑│ 20260910T1546_add_favorite_color 91e7f9f → b29af39 1 ops
│ ○ 18b24e5
│ │↑ 20260910T1547_add_tag_model 91e7f9f → 18b24e5 1 ops
│─╯
○ 91e7f9f
│↑ 20260910T1543_init ∅ → 91e7f9f 6 ops
○ ∅
1 space(s), 5 contract(s), 5 migration(s)Your own database is still on init, so two migrations are pending for it. Apply them and let --advance-ref db set the db ref to where the database actually ends up, which also settles the db.json conflict from section 3.3:
bunx prisma db migrate --advance-ref db✔ Applied 2 migration(s) (2 operation(s)) across 1 contract space(s)
App space
├─ Add column "favoriteColor" to "User"
├─ Create table "Tag"
└─ marker 1e5059c1976c2439863eae8ac13211916ca411614c917394c413346f0d00f60b
✔ Advanced ref "db" → 1e5059c1976c2439863eae8ac13211916ca411614c917394c413346f0d00f60bThe runner walked init → add_favorite_color → merge_add_tag_model. It could equally have walked the other side; both paths end at the same contract. Now commit the merge, the re-emitted contract, both merge migrations, and the db ref together:
git add -A
git commit -m "Merge javier/tag-model and plan merge migrations"3.6. Every database runs only the migrations it needs
Ania pulls main. Her database matches b29af39, so only the migration that adds Javier's table is pending for her:
bunx prisma migration status○ 1e5059c @contract (db)
│─╮
│↑│ 20260910T1550_merge_add_tag_model b29af39 → 1e5059c 1 ops ⧗ pending
│ │↑ 20260910T1550_merge_add_favorite_color 18b24e5 → 1e5059c 1 ops
○ │ b29af39 @db
│↑│ 20260910T1546_add_favorite_color 91e7f9f → b29af39 1 ops ✓ applied
│ ○ 18b24e5
│ │↑ 20260910T1547_add_tag_model 91e7f9f → 18b24e5 1 ops
│─╯
○ 91e7f9f
│↑ 20260910T1543_init ∅ → 91e7f9f 6 ops ✓ applied
○ ∅
⚠ 1 pending: run `prisma db migrate --to 1e5059c1976c`bunx prisma db migrate --advance-ref db✔ Applied 1 migration(s) (1 operation(s)) across 1 contract space(s)
App space
├─ Create table "Tag"
└─ marker 1e5059c1976c2439863eae8ac13211916ca411614c917394c413346f0d00f60bJavier does the same, and for him the pending migration is merge_add_favorite_color, which adds Ania's column. Nobody re-created anything, and the database's own ledger shows the route each one took:
bunx prisma migration logApplied at Migration Change Ops
2026-09-10 17:45:41 +02:00 20260910T1543_init ∅ → 91e7f9f 6 ops
2026-09-10 17:46:17 +02:00 20260910T1546_add_favorite_color 91e7f9f → b29af39 1 ops
2026-09-10 17:52:47 +02:00 20260910T1550_merge_add_tag_model b29af39 → 1e5059c 1 ops4. Integrate your changes
4.1. Pull first
With main merged and your database on the merged state, add your own field. Always pull and apply before you plan, so your plan chains from the state everyone shares:
git pullbunx prisma migration status4.2. Edit, emit, plan
model User {
/* ... */
favoriteColor String?
bestPacmanScore Int?
}bunx prisma contract emit
bunx prisma migration plan --name add_best_pacman_score✔ Planned 1 operation(s)
migrations/app/20260910T1554_add_best_pacman_score
└─ Add column "bestPacmanScore" to "User"
from: 1e5059c1976c2439863eae8ac13211916ca411614c917394c413346f0d00f60b
to: 4961e5b3ceb00cb24a60245343f288095c5a00fc2344d02db1b68509a8b91440
app space: migrations/app/20260910T1554_add_best_pacman_score
ℹ DDL preview
ALTER TABLE "public"."User" ADD COLUMN "bestPacmanScore" int4;No --from was needed: the db ref points at the merged state because the last apply advanced it. Check the from: line anyway. If it does not name the state you expect, stop and read Common gotchas.
4.3. Apply and check
bunx prisma db migrate --advance-ref db
bunx prisma migration check✔ Applied 1 migration(s) (1 operation(s)) across 1 contract space(s)
App space
├─ Add column "bestPacmanScore" to "User"
└─ marker 4961e5b3ceb00cb24a60245343f288095c5a00fc2344d02db1b68509a8b91440
✔ Advanced ref "db" → 4961e5b3ceb00cb24a60245343f288095c5a00fc2344d02db1b68509a8b91440✔ All checks passedmigration check is offline and verifies every migration's hash and the graph's integrity. Run it after you edit a migration by hand, so an ops.json or migration.json that no longer matches its hash shows up before you commit. A pipeline does not need it, because db migrate refuses such a migration too.
migration check reads only the files, so it cannot tell you whether a database matches them. db verify does. Run npx prisma db verify --db "$DATABASE_URL" after db migrate, and it fails if the database's marker or its tables differ from the contract you emitted. A pipeline that migrates a shared database runs db migrate alone; it refuses a database whose marker is outside your history with MIGRATION.MARKER_MISMATCH before it runs anything. Migrate a shared database from a workflow shows the job.
4.4. Commit
Commit the same set of files your teammates did:
git add src/prisma/contract.prisma src/prisma/contract.json src/prisma/contract.d.ts migrations
git commit -m "Add User.bestPacmanScore"The final graph on main is a diamond with one more step on top, and your application code can use all three changes right away:
const user = await db.orm.public.User.create({
email: "pacman@prisma.io",
favoriteColor: "yellow",
bestPacmanScore: 3333360,
});
const tag = await db.orm.public.Tag.create({ tagName: "arcade", tagCategory: "games" });Common gotchas
migration plan fails with MIGRATION.PLAN_ORIGIN_UNKNOWN when the project has migrations but no db ref and you passed no --from. This happens in a fresh clone that has never run db migrate --advance-ref db, or after a merge dropped refs/db.json. The error lists the three exits:
✘ [MIGRATION.PLAN_ORIGIN_UNKNOWN] Cannot determine the plan origin: migrations exist but no origin is named
why: Migrations exist on disk, but there is no `db` ref and no --from was given, so the plan origin would silently fall back to an empty database and the resulting migration would recreate everything the existing migrations already create.
→ Point the db ref at the origin contract: prisma migration ref set db <contract>
→ Plan from an explicit origin: prisma migration plan --from <contract>
→ Plan from an empty database deliberately: prisma migration plan --from @emptyPick the first or second. --from @empty over an existing history is only right for a deliberate rebuild.
Never run db update against a database that changes only through migrations, such as production. It reconciles the database to your contract directly and leaves no migration behind, so when the contract it applied is one no migration starts or ends at, the next db migrate there finds a marker the graph does not know. Use db update only on a database whose migration history does not need to be kept, and switch to migration plan before you open a pull request. A db update without --db moves the db ref to the contract it applied, and migration plan starts from that ref. So to keep that change in your migration history, plan it from the state before it: npx prisma migration plan --from <dir>, where <dir> is your newest migration directory. If a shared database such as staging fails with MIGRATION.MARKER_MISMATCH, the error's db update commands move it back; Drift explains.
The merge conflict in migrations/app/refs/db.json is expected whenever two branches both applied with --advance-ref db. The file records where one developer's database was, so no merged value is "correct" for everyone. Resolve it with either side and let your next db migrate --advance-ref db write the truth.
Renaming a field plans as a destructive drop column plus add column, because the planner has no rename hint yet. Before a rename reaches a shared database, edit the migration to replace the pair with a rawSql ALTER TABLE ... RENAME COLUMN, then recompile it with node migration.ts.
Prompt your coding agent
Run npx prisma@latest init once to install the Prisma ORM skills for your coding agent and keep them matching your installed packages. Prompts that map to this guide:
- "Using the prisma-8 skill, check whether my database is behind the migrations on this branch and apply what is pending."
- "Two branches both added migrations from the same state. Draw the migration graph and plan the merge migrations from each tip."
- "Run
migration checkand explain any integrity failure before I open this pull request."
Next steps
- The migration graph: refs, markers, and how
db migratefinds a path - Applying a migration: the status, preview, apply rhythm for staging and production
- Rollbacks and recovery: planning a backwards edge when a merged change has to come out
- Editing a migration: backfills and raw SQL when a schema change needs a data step
Updated
