Repository navigation
Description
At a glance
Today, a developer who applies a migration and forgets one flag gets a second migration that repeats the first:
npx prisma migration plan --name add_phone
npx prisma db migrate # forgot --advance-ref db
npx prisma migration plan --name add_avatar # plans phone againNothing catches it: the db ref exists, it is just stale, so MIGRATION.PLAN_ORIGIN_UNKNOWN does not fire. The docs carry a whole paragraph on recovering from this, and it was the most-asked question in every reader round on the migrations pages.
The decision
Make db migrate follow the rule db init and db update already have: advance the db ref after a successful apply when the connection comes from prisma.config.ts, and never when --db is passed. Two additions specific to db migrate, because it is the one command that also runs in pipelines:
| Situation | Ref advancement |
|---|---|
Connection from prisma.config.ts, CI unset |
Advance db |
Connection from prisma.config.ts, CI set (any value but false) |
Do not advance |
--db <url> |
Do not advance |
--advance-ref <name> |
Advance <name> instead, in every case above |
--no-advance-ref |
Never advance |
And: a ref write that fails, for example on a read-only filesystem in a deploy image, is a warning, not an error. The migration has already applied at that point, and failing the command after the apply is the worst order to fail in.
--advance-ref <name> and --no-advance-ref are the two flags db sign already has, so the vocabulary does not grow.
Why the current design's reason no longer holds
Apply-time advancement was made opt-in so that a CI or deploy run never writes a file into the repository (ADR 218; skills/prisma-8/references/migration-model.md, "Who advances refs"). Two things have changed:
- The config-versus-
--dbrule already exists fordb initanddb updateand transfers as is. A pipeline usually reaches the URL through an environment variable read byprisma.config.ts, which is equally true ofdb inittoday, so the design already lives with it. - The CLI already detects CI: the
CIvariable turns off telemetry, the skills notice, and prompts. Keying the default on it keeps pipelines untouched without a new mechanism.
What was checked
- The failure mode was reproduced on rc.15 while writing the docs: the second plan repeats the first migration's operations; applying it is harmless because each operation's postcheck already passes, but the migration file is wrong and confusing.
db sign(fix(cli): after db sign, migration plan proposes only the change instead of every table #30251) already advances with or without--dband ships--no-advance-ref; this proposal is thedb migratehalf of the same convergence.
Not covered
A bot that runs db migrate from prisma.config.ts outside CI and commits back to the repository would now commit a moved db ref. No such setup is known; if one exists, --no-advance-ref is the opt-out.
Docs impact
The migrations pages lose the "you forgot --advance-ref db" recovery paragraph and the flag in the five-command tip; cli/db-migrate.mdx gains the table above.
Decided with Will on 2026-09-22.
🤖 Generated with Claude Code
Activity
fix(cli): db migrate advances the db ref when the connection comes fr…
fix(cli): after db migrate, the next migration plan starts from what …