Skip to content

Prisma 8 compatibility policy: from 8.0.0, upgrading to any later 8.x needs no changes - #31193

Draft
wmadden-electric wants to merge 84 commits into
mainfrom
ga-compatibility
Draft

wmadden-electric wants to merge 84 commits into
mainfrom
ga-compatibility

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue

n/a. This is the compatibility policy for the general availability (GA) of Prisma 8.

Summary

Draft. Nothing needs approving yet; it is here to be read.

From 8.0.0, upgrading an application to any later 8.x release needs no changes. This is what we promise a user:

$ pnpm update @prisma/orm-postgres    # 8.0.0 → 8.4.0
$ pnpm typecheck && pnpm test         # passes, with no edits
$ prisma db migrate                   # works on the same files and the same database

The user edits no code, generates no file again, and repairs nothing in the database.

This pull request adds that policy and the plan to make it true, as documents in projects/ga-compatibility/. It changes no code.

Why

A user who trusts that an upgrade will not break their application upgrades as soon as a release is out. They get every fix without setting time aside for it. We in turn maintain one release line for each major version instead of several.

What this reverses

Two things the repository says today:

  • "Prisma 8 keeps nothing for backward compatibility." This is in CONTRIBUTING.md, the architecture overview and the repository rules. It stays true until 8.0.0 and ends there.
  • "We raise floors freely." This is the decision record on the minimum versions of Node.js, TypeScript and databases we support. Under the policy a minimum rises only in a major version, or when its maker ends support for it.

This pull request does not change those docs. Each project below changes the docs for its own part of the policy, in the same pull requests that change the code. So nothing on main describes a rule the code does not yet follow.

What the promise covers

Everything that is GA:

  • the TypeScript API;
  • runtime behaviour that the reference documentation states;
  • CLI commands, their machine-readable output, and the config file;
  • error codes;
  • what Prisma stores. In the user's repository that is contract.json (the description of their database that Prisma generates) with its types, and their migration files. In their database it is two small tables Prisma keeps for itself: one records which contract the database matches, the other which migrations were applied.

How a user tells what is GA

Not everything ships finished: MySQL support, for example, is still early. There are three levels: Early Access, Preview and GA. Only GA is covered. A user must be able to tell the level without looking anything up, so it is written in two places in their own project.

A package's level is in its version:

// package.json
"@prisma/orm-postgres": "^8.0.0",          // plain version: GA, covered
"@prisma/orm-mysql": "8.1.0-preview.3",    // Preview: not covered
"@prisma/orm-sqlite": "8.1.0-ea.1"         // Early Access: not covered

A single API below GA inside a GA package has its level at the start of its name:

db.orm.preview_explain(query)   // illustrative: not covered, whatever the package

Packages stop sharing one version number

Today all 21 published packages have the same version and are released together. Under this policy a database that is not finished must not carry a GA version, so each package has its own. That lets each database reach GA on its own date. How the versions of packages at different levels relate to each other is not settled; maturity-levels.md lists the open points in its section 6, and project 6 settles them.

What can still change in an 8.x release

  • Additions, as long as they do not affect code that does not use them.
  • Fixes to behaviour that was wrong.
  • Detail we never specified, such as the SQL text we generate or the wording of an error message.
  • Security fixes, with a published notice.

A change to specified behaviour waits for the next major version.

How far the code is from this

The policy makes 135 separate statements that can each be checked against the code. On 2026-11-23 we checked them all: 19 are true today. Three examples of the others:

  • The 21 published packages have 1,036 import paths, and nothing says which ones we mean to keep. Fifteen contain the word internal.
  • A PostgreSQL database set up before June 2026 fails on db migrate today. The table that records applied migrations gained columns, and nothing adds them to a table that already exists.
  • Nothing compares the API of a release with the one before it.

The work

The plan groups the work into 11 projects, each sized for one to four pull requests. Each brings its code changes, its checks and its documentation together. Each is placed by when GA needs it:

  • Must: GA does not ship without it. A project is Must when doing it after 8.0.0 would itself break the promise, such as changing a stored format or removing an import path.
  • Aim: wanted at GA, but it can ship just after.
  • Later: after GA.
# Project Needed for GA
2 Make later releases read the files and database records of earlier releases Must
3 Minimize the exported TS APIs of GA packages and guarantee them until the next major version Must
4 Catch breaking changes and accidental new exports in CI, by comparing each package's API with the last release Must
5 Prevent new error codes, built-in names and builder methods from breaking user code Must
6 Show whether something is GA in a package's version and an API's name, and release each package at its own level Must
7 Bring Prisma's own database tables up to date in each release, so no upgrade fails on them Must
8 Define promised behaviour in reference documentation shipped inside each package Later
9 Classify every change to behaviour in its pull request, and list it by class in the release notes Aim
10 Make the changes an upgrade needs with a deterministic tool, not a guide Later
11 Follow each maker's lifetime for supported versions of Node.js, TypeScript and databases, and test them in CI Later
12 Publish the compatibility policy in the user docs Aim

Two notes on that table:

  • There is no project 1. It was to document the whole policy on main before the code followed it, and was dropped for the reason above.
  • Project 8 is Later, and that has a cost. Only behaviour the reference documentation states is promised, and that documentation does not exist yet. At 8.0.0 the promise therefore holds for types, import paths, file formats and stored data. Behaviour joins it as the reference is written.

What is in the folder

File What it holds
spec.md The policy in full
maturity-levels.md The three levels and how they are written
plan.md Each project's purpose, what is true when it is done, and how we expect to do it
designs/ The agreed design for a project, written when its design discussion ends
analysis.md, research/ Facts about the code today, how other projects handle each topic, and the check of the 135 statements

Testing performed

None. The change is documents only.

Skill update

n/a. No user-facing surface changes.

Checklist

  • All commits are signed off (git commit -s) per the DCO.
  • Tests are updated: n/a, documents only.
  • For a bug fix: n/a, not a bug fix.
  • The Skill update section above is filled in.

Notes for the reviewer

This is a draft while the plan is still being worked on. Nothing needs approving yet.

Alternatives considered

To the promise itself:

  • Breaking changes in minor releases, each with an upgrade guide. This is what the release candidates do today. Rejected: every upgrade becomes a task to schedule, users fall behind, and we end up supporting several release lines.
  • Deprecating an API and removing it later in the same major version. Rejected: nothing that is GA is removed within a major version. A replaced API keeps working until the next one.

To how the level is shown:

  • Feature flags for functionality that is not ready. Rejected: flags leave conditional code in the core with no path to removing it. Such functionality ships in its own package below GA, or under a name that carries its level.
  • A separate word, such as unstable_, for an API that may change. Rejected: users would learn two scales that say almost the same thing, and "unstable" suggests the behaviour is unreliable.
  • The level in the import path, such as …/preview/config-loader. Rejected: it is a third place to look, after the version and the name, and those two already say it.
  • Keeping one shared version number for all packages. Rejected: a database that is not finished would carry a GA version.

To what defines promised behaviour:

  • Guides or the agent skill. Rejected: only reference documentation is precise enough, and two sources would disagree.

Agent: jagger-60

🤖 Generated with Claude Code

wmadden-electric and others added 5 commits November 24, 2026 13:51
…plan of 12 projects

Moves the policy for upgrading within Prisma 8, the maturity levels, the analysis and the research from the planning branch into projects/ga-compatibility. The plan is reorganised from 23 tasks into 12 projects, each with its purpose, what it achieves and how.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…h project corrects which record

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@pkg-pr-new

pkg-pr-new Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma/orm-better-auth

npm i https://pkg.pr.new/@prisma/orm-better-auth@31193

@prisma/orm-extension-arktype-json

npm i https://pkg.pr.new/@prisma/orm-extension-arktype-json@31193

@prisma/orm-extension-middleware-cache

npm i https://pkg.pr.new/@prisma/orm-extension-middleware-cache@31193

@prisma/orm-extension-paradedb

npm i https://pkg.pr.new/@prisma/orm-extension-paradedb@31193

@prisma/orm-extension-pgvector

npm i https://pkg.pr.new/@prisma/orm-extension-pgvector@31193

@prisma/orm-extension-postgis

npm i https://pkg.pr.new/@prisma/orm-extension-postgis@31193

@prisma/orm-extension-supabase

npm i https://pkg.pr.new/@prisma/orm-extension-supabase@31193

@prisma/orm-family-mongo

npm i https://pkg.pr.new/@prisma/orm-family-mongo@31193

@prisma/orm-family-sql

npm i https://pkg.pr.new/@prisma/orm-family-sql@31193

@prisma/orm-framework

npm i https://pkg.pr.new/@prisma/orm-framework@31193

@prisma/orm-mariadb

npm i https://pkg.pr.new/@prisma/orm-mariadb@31193

@prisma/orm-mongo

npm i https://pkg.pr.new/@prisma/orm-mongo@31193

@prisma/orm-mysql

npm i https://pkg.pr.new/@prisma/orm-mysql@31193

@prisma/orm-postgres

npm i https://pkg.pr.new/@prisma/orm-postgres@31193

@prisma/orm-postgres-contrib

npm i https://pkg.pr.new/@prisma/orm-postgres-contrib@31193

@prisma/orm-sqlite

npm i https://pkg.pr.new/@prisma/orm-sqlite@31193

@prisma/orm-target-mariadb

npm i https://pkg.pr.new/@prisma/orm-target-mariadb@31193

@prisma/orm-target-mongo

npm i https://pkg.pr.new/@prisma/orm-target-mongo@31193

@prisma/orm-target-mysql

npm i https://pkg.pr.new/@prisma/orm-target-mysql@31193

@prisma/orm-target-postgres

npm i https://pkg.pr.new/@prisma/orm-target-postgres@31193

@prisma/orm-target-sqlite

npm i https://pkg.pr.new/@prisma/orm-target-sqlite@31193

@prisma/orm-toolchain

npm i https://pkg.pr.new/@prisma/orm-toolchain@31193

commit: e1e2391

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
postgres / no-emit 305.25 KB (0%)
postgres / emit 266.21 KB (0%)
mongo / no-emit 240.6 KB (0%)
mongo / emit 194.51 KB (0%)
cf-worker / no-emit 369.54 KB (0%)
cf-worker / emit 326.21 KB (0%)

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric wmadden-electric changed the title docs: from 8.0.0, upgrading within Prisma 8 needs no changes — the policy and the work to make it true Prisma 8 compatibility policy: from 8.0.0, upgrading to any later 8.x needs no changes Nov 24, 2026
wmadden-electric and others added 20 commits November 24, 2026 14:52
…ed files

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…ting it

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…g 8.0.0

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
… at 8.0.0, and the deferred hash migration step

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…s a file used

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
… files do

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…framework owns, and the project is needed for GA

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…remaining details of the stored files design

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
… said nothing useful

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…mentation together; project 1 is dropped

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…pull request

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…from the closed pull request

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…stream folder

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…endencies, and the install trial behind it

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…before GA

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…each package's level at 8.0.0

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
wmadden-electric and others added 5 commits November 27, 2026 20:39
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…ects 12 and 13 sit with the projects GA requires

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…hand-over of its public docs to project 12 and the docs stream

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…s dropped

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
wmadden-electric and others added 9 commits November 28, 2026 08:45
…h its own last release can follow GA

We release all packages in sync, so TML-3977 is not needed for GA.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…wn copy of the ORM toolchain

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eck moves to project 13

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…contract check in the PostgreSQL facade

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…equired member, instead of keeping a list of interfaces

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s own toolchain; project 13 builds it before 8.0

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-prisma__orm that referenced this pull request Nov 28, 2026
…hey do not know (prisma#31200)

## At a glance

**The decision: every file Prisma stores in a project states the version
of its format, a reader refuses a version or a field it does not know,
and until `8.0.0` it still reads the files a release candidate wrote.**
`8.0.0` is the first stable release of Prisma 8, which has not shipped;
release candidates (`8.0.0-rc.N`) continue until then.

**Two things need the reviewer's decision:**

1. **This adds one concept to the framework domain,** which the
repository's rules reserve: the shared reader of a stored file's format
version, with its converters. It is there because some paths read a
contract before any family sees it. I recommend accepting it. Details
are under "API changes".
2. **Whether the framework should read a migration's operations strictly
when it loads them.** Today only the commands that act on a database do,
so `migration check` can pass a migration that `db migrate` refuses.
Fixing it adds a hook to the framework. I recommend adding it, in this
pull request or the next. Details are under "Known limits".

Suppose Prisma `8.3` changes how a migration is written, and a teammate
on `8.0` pulls a migration that `8.3` wrote. Without this pull request,
`8.0` could read it and apply only the part it understood. With it,
`8.0` stops before it touches the database (an example of the output):

```text
✘ [MIGRATION.FORMAT_VERSION_NEWER] The migration file (migration.json) "migrations/app/20270301_add_tags/migration.json" was written by a newer release of Prisma
  It is in format version 2, and this release of Prisma reads format version 1 only.
  Upgrade Prisma to the release that wrote the file, or a later one, and run the command again.
```

To make that possible, every file Prisma writes into a project and reads
back later starts with the version of its format:

```text
contract.json             before: { "schemaVersion": "1", "targetFamily": "sql", ... }
                          after:  { "formatVersion": 1,   "targetFamily": "sql", ... }
migration.json            before: { "from": "6c26…", "to": "6b46…", ... }
                          after:  { "formatVersion": 1, "from": "6c26…", "to": "6b46…", ... }
refs/production.json      before: { "hash": "6b46…", "invariants": [] }
                          after:  { "formatVersion": 1, "hash": "6b46…", "invariants": [] }
```

What it costs and what it does not:

- **A project a release candidate wrote keeps working with no step.**
Its files have no `formatVersion`. This release reads them as "format
version 0" and converts them in memory. Each file becomes version 1 the
next time a command writes it. `8.0.0` stops reading version 0, and a
script in the upgrade instructions rewrites the files before that
upgrade.
- **A file with a key Prisma does not define is now refused,** in a
contract, a migration, a ref or an operation. A hand-edited file with a
stray key stops reading. One exception until `8.0.0`: a ref file a
release candidate wrote is read with a stray key dropped, as the release
candidates did.
- **A MongoDB migration that passes `sort` or `returnDocument` to
`rawFindOneAndUpdate`, or `sort` to `rawFindOneAndDelete`, now sends
them to the database.** Earlier releases dropped them when they read the
migration back, so the command ran without them. Applying such a
migration to another database now does what its author wrote.
- **A SQL target built outside this repository must supply a new
function, `readOperations`,** and a contract serializer overrides a
different method. The full list is under "API changes".

About 600 of the changed files are the repository's own contracts,
snapshots, migrations and refs, rewritten by a script; each differs from
`main` only in the version field.

A **snapshot** is the copy of a contract that a migration keeps beside
it. A **ref** is a file that gives a contract a name, such as
`production`. `ops.json` holds the operations of a migration, beside its
`migration.json`.

## The decisions

All are recorded in a new decision record, [ADR
331](docs/architecture%20docs/adrs/ADR%20331%20-%20Stored%20files%20carry%20a%20format%20version%2C%20and%20a%20reader%20refuses%20one%20it%20does%20not%20know.md).

1. **`contract.json`, each snapshot, `migration.json` and each ref file
carry `formatVersion`.** A migration's version also covers its
`ops.json`.
2. **A reader looks at the version first.** A version it knows: it reads
the file. A higher version: it stops and says a newer release wrote the
file. No version: it stops and says how to get a file it can read,
unless the file is one only a release candidate wrote (decision 5).
3. **A reader refuses a field it does not know.** So a release cannot
add a field to a format without raising its version.
4. **A writer writes the oldest version that can hold the data,** so
newer tooling does not force an upgrade on everyone who reads its files.
With one version there is nothing to choose yet; the rule binds the
first release that adds a second.
5. **Until `8.0.0`, files a release candidate wrote are read as version
0 and converted in memory.** Until `8.0.0` the content of format 1 is
also not final: a release candidate may still change it, with upgrade
instructions.
6. **Format 1 of `ops.json` reads every shape of an operation that a
release candidate wrote, for the whole of Prisma 8.**

### Decisions 1 and 2: why the version and the refusal must be in
`8.0.0`

The Prisma 8 compatibility policy promises (its page is a draft,
prisma#31193; the promise itself is agreed) that a later 8.x release
reads every file an earlier one wrote, and the user regenerates nothing.
An `8.0.0` reader stays in use for the whole major. So it must already
know how to recognise a file it cannot read, and it must already refuse
what it does not understand. A reader that ignores an unknown key in
`8.0.0` will ignore, for the whole major, a field a later release adds.
Neither can be added afterwards.

A reader is strict because a migration is an instruction to change a
database. Acting on one that is only partly understood is the failure
the rule prevents.

### Decision 3: what "refuses a field it does not know" changed

Before this pull request several readers ignored unknown keys:

| Reader | Before | Now |
| --- | --- | --- |
| `migration.json` and ref files | A ref ignored unknown fields | Strict
in format 1; a release-candidate ref still has unknown fields dropped |
| Contract (SQL family, PostgreSQL entry kinds, MongoDB family) | About
25 kinds of object ignored an unknown key | Strict; the error names the
key's full path |
| MongoDB `ops.json` | Every object ignored an unknown key | Strict |
| SQL `ops.json` | No reader: the runners treated the parsed file as
operations | A strict reader in the SQL family, to which each SQL target
supplies its own fields |
| A type's parameters | Prisma's own types ignored an unknown parameter,
and no command checked them | Each of Prisma's 16 parameter schemas is
strict, and it is applied when a command reads a contract and when a
client builds the type |
| A contract snapshot | Read strictly only by `migration plan` | Read
strictly by whatever interprets it: planning, signing, `db migrate --to`
and `db update --to` for the snapshot a ref names, and `migration check`
for every snapshot a ref names or a graph ends at. A snapshot a command
only records or identifies by hash is not read |

A **family** is the code shared by databases of one kind (SQL, MongoDB);
a **target** is one database, such as PostgreSQL.

The rule stops at content Prisma carries for someone else, where any key
is accepted. These are the **open places**: `meta`, `capabilities`, an
extension's own section, a generator's parameters, a literal default's
value, an index's options, a SQL statement's parameters, and the MongoDB
documents handed to the database as they are. ADR 331 lists them.

SQL operations are read strictly by everything that acts on their
statements: the runners, the statement preview, and the checks `db
migrate` runs on a recorded path.

A command reads strictly what it interprets in that run, and no more.
`db migrate` records the snapshot of each migration it applies as it is
stored, and `migration status`, `list`, `graph` and `ref set` use hashes
only. This matters for old projects: one with a snapshot in a shape from
before `8.0.0-rc.1`, which no reader of this release reads, still
applies its migrations. The repository's telemetry app is such a
project.

A command that cannot read a stored file names it and says why, and
never calls it unknown or missing. It refuses when it acts on the file;
`migration list`, `graph`, `status` and `check` report it and go on with
the rest. `db update` is the one command that goes on past a file it
acts on: when the snapshot of the contract the database was last at
cannot be read, it warns and continues as for a database with no
recorded origin. Before this, several commands dropped such a file
without a word: `migration list` and `graph` left out a migration,
`migration new` started from the empty contract when its ref could not
be read, and `migration check` reported the migrations after an
unreadable one as unreachable, with advice to delete them. Every command
and entry point that loads a stored file was listed and checked for
this.

The advice a refusal gives follows one rule: restore the file from
version control first; name a command only where that command writes the
file again, and say what else it does; never give a new hash to a
migration a database has applied; never name a contract for the `db` ref
by hand. For example, a lost `migration.json` is written again by
running the migration's `migration.ts`, which gives it a new hash, so
that advice is offered only when no database has applied the migration.
The database commands warn about a migration whose snapshot they cannot
record only when the run applies it.

### Decision 5: why release-candidate files are read, and only until
`8.0.0`

Release-candidate users have asked for fewer forced rewrites. Reading
their files costs them nothing now. It also runs the "convert an earlier
format" path on real files before the first format change after `8.0.0`
depends on it.

A release-candidate file is recognised without guessing: a contract has
`"schemaVersion": "1"` and no `formatVersion`; a `migration.json` or ref
has neither. Only a release candidate wrote those. A contract with
neither field is refused, because no release wrote it. Version 0 has a
converter and no printer, so no release writes it. A test fails if a
release that is not a pre-release still reads version 0, so `8.0.0`
cannot ship with it.

prisma#31203, built on this pull request, changes how contract
hashes are computed. The parts of release-candidate reading that depend
on that are there.

### Decision 6: why older operation shapes are read for the whole major

From `8.0.0` no release may change a migration's hash, and `ops.json` is
covered by that hash. So from `8.0.0` an older shape of an operation can
only be read, never rewritten, and format 1 has to read it for the whole
major. Before `8.0.0` a script could still have rewritten those shapes,
because the hash rules change once before `8.0.0` (prisma#31203).
Reading them was chosen because it is small and costs users no step. The
reader converts each to the current shape before it checks the
operation, so nothing after it sees the older form:

- **SQLite, up to `8.0.0-rc.19`:** every operation carried `"schema":
"main"`. It is dropped. Any other value is refused.
- **PostgreSQL and SQLite, `8.0.0-rc.21` and `rc.22`:** an entry in a
step's `meta` tells the runner to count the rows that still hold a
removed enum value. In those releases it had fewer fields. The reader
fills them in from the same places those releases' runners read them.
- **MongoDB:** a field the query builder writes into a query plan is
declared, and two command options that earlier readers dropped, `sort`
and `returnDocument` on `rawFindOneAndUpdate` and `sort` on
`rawFindOneAndDelete`, are now passed to the command. That changes what
such a migration does when it is applied again: it now does what its
author wrote.

These were found by going through the history of every planner,
operation class and serializer across all 485 published `8.0.0-rc` tags
(each release candidate and the development builds between them),
because the repository holds no saved file of most of them. Contract
shapes from earlier release candidates need no such acceptance:
published upgrade instructions already rewrite them.

## Known limits

Recorded in the project's follow-up list,
`projects/ga-compat-stored-files/deferred.md`:

- **`migration check`, `status`, `list` and `graph` do not read a
target's own operation fields.** They load `ops.json` in the framework
and use only the fields every target shares. So `migration check` can
pass a migration that `db migrate` refuses. Fixing it means the
framework asks the family to read each operation when it loads the file,
which adds to the framework. It is listed in ADR 331 as an alternative
not chosen here, and it is the second decision asked of the reviewer
above.
- **A migration written in code can write an operation that `db migrate`
then refuses,** for the same reason.
- **An index's `type` and `options` are not checked when a contract is
read,** only by the TypeScript builder.
- **SQLite creates an empty database file when `db migrate` refuses a
migration,** because the refusal comes after the database is opened to
read its marker. That was so before this change.
- **Nothing tests that the open places stay open.** A reader that starts
acting on a key inside one needs a new format version, and only the
author of the change knows.

## For users of a release candidate

Nothing to do for this change. [The upgrade
instructions](upgrade-instructions/pending/stored-files-format-version/app/instructions.md),
for applications and for extensions, still ship a script that rewrites
every file to version 1. It is required before upgrading to `8.0.0`, and
optional until then:

```bash
node upgrade-instructions/pending/stored-files-format-version/app/scripts/stored-files-format-version/stored-files-format-version.ts
```

That is its path in this repository. A user gets it with the release's
upgrade guide in the Prisma 8 skill and runs it from their project root.

It renames `schemaVersion` in every contract and snapshot, adds
`formatVersion` to every `migration.json` and ref file, changes no other
byte and no hash, removes an unknown field from a ref file and lists it,
and changes nothing when run again.

## API changes

Application code changes nothing. The changes are for authors of a
family, a target, an extension or a tool built on the toolchain.

- `@prisma/orm-framework`: new entries `contract/format-version`
(`convertContractDocument`, which reads a stored contract's version and
converts an earlier one; `NEWEST_CONTRACT_FORMAT_VERSION`, which a
family writes into the contracts it prints; `isFormatVersionError`; and
their types), so a family built outside this repository reads and writes
a contract the way Prisma does (the same names are also on the
`contract` entry); `contract/internal/format-version`, the shared reader
and its converters for every kind of file (`readStoredDocument`,
`StoredFormat` and their types), which Prisma's own packages reach each
other through and which is not for outside code; and
`utils/upgrade-guides`, the addresses a refusal points to.
`CanonicalizeContractOptions` loses `schemaVersion`, because
`canonicalizeContract` no longer takes or writes it.
`errorContractValidationFailed` accepts the file's path and what kind of
file it is in its options, so a refused contract or snapshot names its
file.
- `@prisma/orm-postgres`, `@prisma/orm-mysql`, `@prisma/orm-mariadb`,
`@prisma/orm-sqlite` and `@prisma/orm-mongo`: each re-exports the three
new framework entries, because a database package re-exports every
framework entry so that code built on it needs no direct dependency on
the framework. That includes the `internal` entry, which Prisma's own
packages use to reach each other and which is not for outside code.
- `@prisma/orm-family-sql`: `SqlContractSerializerBase` gains protected
`parseContractV1` and `printContractV1`, the parser and printer of
contract format 1; the base class reads and writes the version around
them. New: `createSqlOperationsReader`, `SqlOperationsReader`,
`SqlTargetOperationsFormat` and `SqlOperationsLocation`, the strict
reader of SQL operations and what a target supplies to it; and
`probeUnknownKeys`, `SQL_OPERATIONS_OPEN_PLACES`, `DocumentPlace` and
`UnknownKeyProbe`, a test helper with which a SQL target's author checks
that its reader refuses an unknown key everywhere outside the open
places. `SqlControlTargetDescriptor` gains a required `readOperations`,
so **a SQL target built outside this repository must now supply it**.
Its `api-breaks.json` records the breaks against `8.0.0-rc.25`.
- `@prisma/orm-family-mongo`: `MongoContractSerializerBase` and
`MongoContractSerializer` gain `parseContractV1` and `printContractV1`,
for the same reason as the SQL base.
- `@prisma/orm-target-postgres`: `PostgresContractSerializer` overrides
`printContractV1` where it overrode `serializeContract`, because the
base class now writes the version around it.
- `@prisma/orm-target-mysql`: `MysqlContractSerializer` overrides
`printContractV1` for the same reason, and the target supplies
`readOperations`. Its `api-breaks.json` records the breaks.
- `@prisma/orm-target-sqlite`: `SqliteContractSerializer` overrides
`printContractV1` for the same reason.
- `@prisma/orm-target-mongo`: `MongoTargetContractSerializer` overrides
`printContractV1` for the same reason. `deserializeMongoOps` takes an
optional `MongoOperationsLocation`, so a refusal names the migration and
the operation.
- `@prisma/orm-toolchain`: new `parseMigrationMetadataDocument`,
`printMigrationMetadataDocument`, `parseRefDocument`, `printRefDocument`
and their document types, the parser and printer of each version of
`migration.json` and ref files. `computeMigrationHash` accepts
`formatVersion` and leaves it out of the hash. `contractSpaceFromJson`
requires `spaceId`, so an error in a file an extension ships names the
extension. `assertDescriptorSelfConsistency` takes the whole
`contractJson`, so it can read the version first. `buildReadAggregate`
gains `onUnreadableFile`, which refuses an unreadable ref or migration
by default and lets a listing command report it and keep going.
`IntegrityViolation`'s `contractUnreadable` gains the snapshot's `hash`,
so a refusal names the file; the functions that carry that type are
recorded as breaks for it. `DbUpdateOptions` gains an optional
`onUnreadableOrigin`. `enumerateCheckSpaces` takes one options object
(`EnumerateCheckSpacesInputs`) with the family's contract reader, and
`CheckSpace` carries that reader and the migrations that could not be
read; `checkSingleTarget` and `runMigrationCheck` follow. Its
`api-breaks.json` records these. The breaks recorded against
`8.0.0-rc.25` are `contractSpaceFromJson`,
`assertDescriptorSelfConsistency`, `buildReadAggregate`,
`enumerateCheckSpaces`, `checkSingleTarget` and `runMigrationCheck`.

The repository's rule is that the framework domain,
`packages/1-framework`, gains no new concepts. This pull request adds
one there (the first decision asked of the reviewer above): the shared
reader of a stored file's format version, with its converters. It is in
the framework because some paths read a contract before any family sees
it (the CLI's contract reader, the snapshot store, an extension's
bundled files). The strict readers added nothing to the framework. This
addition needs the reviewer's agreement.

## Reviewing the diff

<details>
<summary>A suggested reading order</summary>

1. ADR 331.
2. `packages/1-framework/0-foundation/contract/src/format-version.ts`:
the shared reader, the refusals and their advice, version 0.
3. `packages/1-framework/3-tooling/migration/src/formats/`: one unit per
version of `migration.json` and ref files.
4. Each family's contract serializer base, and the strict contract
validators (`packages/2-sql-family/1-core/contract/src/validators.ts`,
`packages/2-mongo-family/1-foundation/mongo-contract/src/contract-schema.ts`).
5. The SQL operations reader,
`packages/2-sql-family/9-family/src/core/migrations/operations-reader.ts`,
and each SQL target's `read-operations.ts`.
6. The MongoDB operations reader,
`packages/3-targets/mongo/1-target/src/core/migrations/mongo-ops-serializer.ts`.
7. The upgrade instructions and script, with tests in
`test/integration/test/upgrade-instructions/stored-files-format-version/`.

</details>

## How it was verified

- **Each parser and printer:** print, parse, same data back. Each
refusal and each reading path has a test.
- **Strictness:** for each object made strict, a test adds one unknown
key and expects a refusal that names its path. A one-off probe added an
unknown key at every place in the 368 saved contracts that read: 403
distinct places accepted it before, and only the open places do now. A
committed test does the same for every saved SQL `ops.json` of each
target.
- **Nothing saved stops reading:** tests read every saved
`contract.json` and every saved SQL and MongoDB `ops.json`, and fail on
an empty list. They exclude, by name, 46 contracts in shapes from before
`8.0.0-rc.1`, which the published `rc.25` reader refuses too, and the
fixtures of earlier upgrade scripts. Stored contracts under other file
names (112, mostly expected-output files of tests) are not in that test;
a one-off run read all but one deliberate "before" fixture.
- **Older shapes:** each one reads and gives the current shape; a
malformed one is refused. For the enum-value mark, the conversion was
checked against the `rc.22` runner's code.
- **Release-candidate files:** a PostgreSQL and a MongoDB project that
`8.0.0-rc.25` wrote are read file by file. The three tests on `main`
that give an `rc.25` contract to a client pass.
- **The script:** `before` and `after` project trees, a second run, and
files it must refuse.
- **By hand, with the built CLI, on real `8.0.0-rc.25` PostgreSQL and
MongoDB projects with no script run:** `contract emit`, `migration
status`, `migration check`, `migration plan` of a change, `db migrate`,
`db verify` and a query worked, and only the files the commands wrote
moved to version 1.
- **By hand, strictness:** an unknown key was planted in each kind of
stored file and each kind of place, for both databases. Every strict
place refused it, every open place accepted it, the refusal's advice
worked when followed, and no file or database changed. A file at version
2 was refused by every command. The first run found two gaps (a snapshot
and a column's type parameters were accepted) and three commands that
hid or misreported an unreadable file. They are fixed and the fixes
confirmed by hand. One fix first went too far, reading every recorded
snapshot strictly, which stopped the telemetry app migrating an empty
database; review caught it and it was narrowed.
- **By hand, older shapes:** a migration with the older enum-value mark
was applied to a real PostgreSQL database, with and without a row
holding the value, with the same result and messages as the current
shape. On SQLite, `"schema": "main"` applied and `"schema": "other"` was
refused. On MongoDB, the `sort` of a raw command decided which document
changed.
- **By hand, repair advice:** every command a refusal advises was run on
copies of PostgreSQL and MongoDB projects, in the application's space
and an extension's, with and without `--db` and `--config`, and the
project checked afterwards with `migration check` and `db migrate`. Four
review rounds found advice that refused, had side effects it did not
state, or changed a hash; the last round fixed six such findings, and a
final check covered only those six.
- **The merge queue's integration tests** found that the new read-time
check of type parameters reported a refused `varchar(0)` as a generic
"contract validation failed". It now reports the data type's own
`CONTRACT.TYPE_PARAMS_INVALID`, as main did. The CLI passes that error
through as itself, alongside the format version errors. That is a list
of codes chosen by name, not a rule for every library error: these are
the read errors whose own message tells the user what to change, where
the generic wrapper's advice (emit again) would not help. The commands
that only list migrations still report it and go on.
- **Decision record:** reviewed by fresh agents under the repository's
rule for documentation: a cold reader, three times, and a fact checker
against the code, five times, with its last findings corrected.
- **CI** runs on this branch. The whole package, integration and
end-to-end suites were not run locally.
- **Independent review,** design and code separately, on each part, in
several rounds.

## Alternatives considered

- **Refuse a release-candidate file and leave it to the upgrade
script.** Rejected while release candidates continue: every user would
rewrite every stored file for a change that adds one field, and the
conversion path would first run on real files only after `8.0.0`.
- **Read a file with no version as version 1, with no "version 0".**
Rejected: a reader that assumes a version is what the opening example
shows going wrong. Version 0 is recognised by what only a release
candidate wrote, and it has an end date.
- **Ignore fields a reader does not know,** as Protocol Buffers readers
do. Rejected: Prisma would apply a migration while ignoring part of it.
- **Let each new field say whether an older release may ignore it.**
Rejected: someone would have to judge that correctly for every field
ever added. Writing the oldest version that holds the data serves the
same case.
- **Rewrite an older operation shape with an upgrade script.** Possible
before `8.0.0` and not chosen: reading the shapes is small and costs
users no step. From `8.0.0` it is not possible, because a migration's
hash may not change.
- **Read operations strictly when the framework loads `ops.json`.** Not
chosen here, because it adds to the framework. See "Known limits".
- **Record which Prisma release wrote the file.** Rejected: most
releases change no format, so a release number would refuse files an
older release reads perfectly well.
- **A version string such as `"1.2"`.** Rejected: a reader refuses any
version it does not know, so there is no compatible minor step to
express.
- **A version only in `contract.json`, or one for the whole project.**
Rejected: migrations and refs are read on their own, and the files
change independently.
- **A version inside `ops.json`, by wrapping the array in an object.**
Rejected: it would change every migration's hash, and `ops.json` is
never read without its `migration.json`.
- **Include `formatVersion` in the migration hash.** Rejected:
converting a migration to a later format would change its hash.
- **Tell a stored file from a contract Prisma built in memory by which
fields it has.** A command accepts either. Rejected: a file with no
version field at all would be taken for a built contract and accepted.

Agent: alexvanhalen-55

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-authored-by: Claude Fable 5.2 <[email protected]>
wmadden-electric and others added 13 commits November 29, 2026 08:14
…isma

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
… prisma, without an underscore

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…1-29

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…c 5.1, project 5)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant