Skip to content

db migrate: advance the db ref by default when the connection comes from prisma.config.ts #30370

Closed

Description

@wmadden-electric

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 again

Nothing 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---db rule already exists for db init and db update and transfers as is. A pipeline usually reaches the URL through an environment variable read by prisma.config.ts, which is equally true of db init today, so the design already lives with it.
  • The CLI already detects CI: the CI variable 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 --db and ships --no-advance-ref; this proposal is the db migrate half 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

  1. added a commit that references this issue on Nov 23, 2026
    0124360
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions