@prisma/orm-mongo 8.0.1-dev.43 → 8.0.1-dev.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dist/{mongo-static-D0gxIAFR-D4Ugp6Ri.mjs → mongo-static-DXgxqad2-EexeYfrg.mjs} +3 -3
  2. package/dist/{mongo-static-D0gxIAFR-D4Ugp6Ri.mjs.map → mongo-static-DXgxqad2-EexeYfrg.mjs.map} +1 -1
  3. package/dist/runtime.mjs +1 -1
  4. package/dist/runtime.mjs.map +1 -1
  5. package/dist/static.mjs +1 -1
  6. package/package.json +12 -12
  7. package/skills/prisma-8/SKILL.md +3 -3
  8. package/skills/prisma-8/references/contract.md +1 -1
  9. package/skills/prisma-8/references/scripts/find-detection-hits.ts +57 -0
  10. package/skills/prisma-8/references/upgrade-app.md +29 -10
  11. package/skills/prisma-8/references/upgrade-extension.md +24 -7
  12. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/instructions.md +139 -42
  13. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-hash-inputs/contract-hash-inputs.ts +164 -12
  14. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-signature-names/contract-signature-names.ts +110 -18
  15. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/facade-paths-an-application-uses/facade-paths-an-application-uses.ts +28 -6
  16. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/platform-paths-an-extension-uses/platform-paths-an-extension-uses.ts +70 -13
  17. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/stored-files-format-version/stored-files-format-version.ts +98 -13
  18. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.26-to-8.0.0-rc.27/instructions.md +102 -0
  19. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.27-to-8.0.0-rc.28/instructions.md +5 -0
  20. package/skills/prisma-8/upgrading/extension/upgrades/0.10-to-0.11/instructions.md +2 -1
  21. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/instructions.md +33 -19
  22. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-hash-inputs/contract-hash-inputs.ts +164 -12
  23. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-signature-names/contract-signature-names.ts +110 -18
  24. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/facade-paths-an-application-uses/facade-paths-an-application-uses.ts +28 -6
  25. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/platform-paths-an-extension-uses/platform-paths-an-extension-uses.ts +70 -13
  26. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/stored-files-format-version/stored-files-format-version.ts +98 -13
  27. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.26-to-8.0.0-rc.27/instructions.md +56 -0
  28. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.27-to-8.0.0-rc.28/instructions.md +5 -0
@@ -59,7 +59,7 @@ changes:
59
59
  - '@prisma/orm-(?:postgres|sqlite|mysql|mariadb|mongo)/contract-types[''"]'
60
60
  - id: contract-signature-flag
61
61
  summary: |
62
- `prisma db verify --marker-only` is now `prisma db verify --signature-only`; the old flag is refused. Run this guide's colocated script: it changes the flag wherever it is written as a whole word, in `package.json` scripts, CI workflow files, shell scripts, Markdown and code, including an argument array that spreads the command over several lines.
62
+ `prisma db verify --marker-only` is now `prisma db verify --signature-only`; the old flag is refused. Run this guide's colocated script: it changes the flag wherever it is written as a whole word, in `package.json` scripts, CI workflow files, shell scripts and code, including an argument array that spreads the command over several lines.
63
63
  detection:
64
64
  glob: "**/*"
65
65
  matches:
@@ -67,7 +67,7 @@ changes:
67
67
  script: ./scripts/contract-signature-names/contract-signature-names.ts
68
68
  - id: contract-signature-error-codes
69
69
  summary: |
70
- Nine error codes are renamed. Six say SIGNATURE where they said MARKER, such as `CONTRACT.MARKER_MISSING`, now `CONTRACT.SIGNATURE_MISSING`; `MIGRATION.MARKER_MISMATCH` and `MIGRATION.MARKER_NOT_IN_HISTORY`, which reported one condition from two commands, are one code, `MIGRATION.SIGNATURE_NOT_IN_GRAPH`; `MIGRATION.MARKER_CAS_FAILURE` is `MIGRATION.CONCURRENT_CHANGE`. `CONTRACT.MARKER_REQUIRED` and `CONFIG.FAMILY_READ_MARKER_REQUIRED`, which no command raised, are gone. The script renames the nine wherever they are written; remove code that matches the two removed ones.
70
+ Nine error codes are renamed. Six say SIGNATURE where they said MARKER, such as `CONTRACT.MARKER_MISSING`, now `CONTRACT.SIGNATURE_MISSING`; `MIGRATION.MARKER_MISMATCH` and `MIGRATION.MARKER_NOT_IN_HISTORY`, which reported one condition from two commands, are one code, `MIGRATION.SIGNATURE_NOT_IN_GRAPH`; `MIGRATION.MARKER_CAS_FAILURE` is `MIGRATION.CONCURRENT_CHANGE`. `CONTRACT.MARKER_REQUIRED` and `CONFIG.FAMILY_READ_MARKER_REQUIRED`, which no command raised, are gone. The script renames the nine wherever they are written outside Markdown, and lists the lines of Markdown that name them; remove code that matches the two removed ones.
71
71
  detection:
72
72
  glob: "**/*"
73
73
  matches:
@@ -189,7 +189,7 @@ changes:
189
189
  script: ./scripts/stored-files-format-version/stored-files-format-version.ts
190
190
  - id: contract-hash-inputs
191
191
  summary: |
192
- Every storage, profile and execution hash takes a new value, once: each now covers only its own section of the contract, and no longer the target or the family, and the rules that compute them do not change again within Prisma 8. Before upgrading, deploy every pending migration, the application's and every extension's, to every database with the release you are on: the upgrade assumes every database is at the newest contract. Then upgrade Prisma in a release of its own: run the colocated script on the project, which rewrites every hash in the emitted contract, `contract.d.ts`, the snapshot directories, each `migration.json` and `ops.json`, each ref file and each `migration.ts`, and renames each contract's `capabilities` to `requiredCapabilities` with keys prefixed by who provides them (`db.` or `conn.`), then `prisma contract emit`, and commit. This release refuses a contract or snapshot that still has `capabilities`. If the emitted contract's storage hash then differs from the one the script wrote, because the contract source holds a `false`, `[]` or `{}` that the earlier release left out of `contract.json`, plan a migration for it in the same release. That release's deploy runs `prisma db sign --no-advance-ref` (signed at the directory name of the migration before that new one, if there is one, such as `prisma db sign --no-advance-ref 20261128T0807_add_post_meta`; with `--force` where the change policy permits only migrations) and then `prisma db migrate` against every database that existed before it; a database created later needs only `prisma db migrate`. A database with at least one of the application's migrations, and none of an extension's, still pending is signed at the directory name of the migration it is at; a database with nothing pending is signed with plain `prisma db sign --no-advance-ref`, never at a directory.
192
+ Every storage, profile and execution hash takes a new value, once: each now covers only its own section of the contract, and no longer the target or the family, and the rules that compute them do not change again within Prisma 8. Before upgrading, deploy every pending migration, the application's and every extension's, to every database with the release you are on: the upgrade assumes every database is at the newest contract. Then upgrade Prisma in a release of its own: run the colocated script on the project, which rewrites every hash in the emitted contract, `contract.d.ts`, the snapshot directories, each `migration.json` and `ops.json`, each ref file and each `migration.ts`, and renames each contract's `capabilities` to `requiredCapabilities` with keys prefixed by who provides them (`db.` or `conn.`), then `prisma contract emit`, and commit. This release refuses a contract or snapshot that still has `capabilities`. If the emitted contract's storage hash then differs from the one the script wrote, because the contract source holds a `false`, `[]` or `{}` that the earlier release left out of `contract.json`, plan a migration for it in the same release. That release's deploy runs `prisma db sign --no-advance-ref` (signed at the directory name of the migration before that new one, if there is one, such as `prisma db sign --no-advance-ref 20261128T0807_add_post_meta`; with `--force` where the change policy permits only migrations) and then `prisma db migrate` against every database that existed before it, the run at each database guarded so that it signs only a database the earlier release signed; a database created later needs only `prisma db migrate`, once a `prisma contract emit` of `8.0.0-rc.27` or later has brought the snapshot of the emitted contract up to date. A database with at least one of the application's migrations, and none of an extension's, still pending is signed at the directory name of the migration it is at; a database with nothing pending is signed with plain `prisma db sign --no-advance-ref`, never at a directory. Do not run a planned `migration.ts` again after the upgrade: this release can write other checks into its `ops.json`, so its `migrationHash` changes.
193
193
  script: ./scripts/contract-hash-inputs/contract-hash-inputs.ts
194
194
  - id: migration-ts-proto-key-computed
195
195
  summary: |
@@ -281,7 +281,7 @@ changes:
281
281
  On MongoDB, `--rename` of a model whose collection another root model shares is now refused, where it used to rename the whole collection and take the other models' documents with it.
282
282
  - id: mongo-create-collection-postcheck
283
283
  summary: |
284
- On MongoDB, `createCollection` now checks after it runs that the collection exists with the options it sets, so a migration that created a collection and then stopped can be run again. Migrations emitted before keep the old create, with no such check, until their `ops.json` is written again.
284
+ On MongoDB, `createCollection` now checks after it runs that the collection exists with the options it sets, so a migration that created a collection and then stopped can be run again. Migrations emitted before keep the old create, with no such check; do not run their `migration.ts` again to change that.
285
285
  - id: runtime-signature-check-only-warns
286
286
  summary: |
287
287
  On its first use of the database, the runtime compares the contract with the database's contract signature. When the signature cannot be read, or its row cannot be decoded, that first call no longer rejects with `CONTRACT.SIGNATURE_READ_FAILED` or `CONTRACT.SIGNATURE_ROW_CORRUPT`. The runtime passes one warning with that code to the `log` option and runs the query. Such a check is not tried again on later calls. When the signature read fails with a connection error, for example because the server does not answer, the call rejects with that error, no warning is logged, and the next call makes the check. Code that caught either code from a query, for example a startup check, no longer sees it there: run `prisma db verify` in the deploy, or read the warnings that `log` receives.
@@ -399,14 +399,18 @@ This release changes every hash Prisma stores, moves Prisma's own tables, and re
399
399
 
400
400
  Do the steps in this order, and skip a step that does not apply to the project:
401
401
 
402
- 1. Before you upgrade, with the release you are on now, deploy every pending migration, the application's and every extension's, to every database (`contract-hash-inputs`, its step 1). On PostgreSQL, check that every database runs PostgreSQL 15 or later (`postgres-signing-refuses-servers-older-than-15`). Tell the user that every service, deploy script and pipeline that runs a `prisma` command against a database must move to this release at the same time (`prisma-tables-move-to-prisma-schema` on PostgreSQL, `sqlite-prisma-tables-renamed` on SQLite). If the contract declares a namespace `prisma` or `prisma_contract`, settle its new name with the user before anything else (`rename-a-namespace-named-prisma`). Check every database for what would stop the move of Prisma's own tables in the deploy, with the read-only queries `prisma-tables-move-to-prisma-schema` gives under "Check each database before the deploy", and fix what they find. If an extension the project uses has no release for `8.0.0-rc.26`, such as `@prisma/orm-extension-paradedb`, stop and tell the user: the project cannot upgrade until the extension publishes one. On MongoDB, if a relation or a member of a composite type or value object is named `__proto__`, rename it and move its values with the release you are on (`mongo-proto-field-and-relation-names-refused`), so the upgrade carries no change of its own to what is stored.
403
- 2. Upgrade Prisma in a release of the application that carries no new migration of its own. Move `prisma`, the package that provides the `prisma` command, to `8.0.0-rc.37` or later, the first release built on this one. `prisma` `8.0.0-rc.36` runs the toolchain of `8.0.0-rc.25`, but loads this release's database package through the project's config. The old toolchain passes this release's contract reader a contract with no format version it recognises, and reports the reader's `CONTRACT.FORMAT_VERSION_MISSING` error under its own code. So once the guide's scripts have upgraded the project, its commands fail with `CONTRACT.VALIDATION_FAILED` and "The contract file has no format version". If a `prisma` command fails that way, the `prisma` the project runs is still an earlier one: move it to `8.0.0-rc.37` or later and install. Before you run the install, fix `package.json`: list the platform packages beside the database package (`list-the-platform-packages`), and change the config to import `prisma/config` and remove the `@prisma/cli-engine` line where its section says so (`config-imports-prisma-config`). Put each other required peer dependency, such as `temporal-polyfill`, `pg` and `@types/pg`, where `list-the-platform-packages` says. Then move every `@prisma/orm-*` package, and each extension released with the ORM, to `8.0.0-rc.26` and install. This is the only step that upgrades the extensions.
404
- 3. Run the three scripts that rewrite import paths and names, in this order, and make the changes by hand that each one lists: `facade-paths-an-application-uses`, then `platform-paths-an-extension-uses`, then `contract-signature-names` (`contract-signature-flag` and the entries after it). Each later script reads what the earlier one wrote. Then change any value imported from a database package's `contract-types` (`contract-types-exports-types-only`). A type check at this step finds the imports to fix (`TS2307`, `TS2305`, `TS1361`, `TS1362`). Until step 5 emits the contract, `contract.d.ts` still has the old shape, so expect errors that name the contract's `capabilities` or `requiredCapabilities`, and do not fix them by hand. Expect too the errors that step 6 fixes, such as `TS2339` for `fragment` on the ORM client (`fragment-on-the-client`) and `TS2769` for a call whose arguments changed.
402
+ 1. Before you upgrade, write down every database the project uses, as `contract-hash-inputs` says in its step 1 under "Which databases this means". Then, with the release you are on now, deploy every pending migration, the application's and every extension's, to each of them (`contract-hash-inputs`, its step 1). On PostgreSQL, check that every database runs PostgreSQL 15 or later (`postgres-signing-refuses-servers-older-than-15`). Tell the user that every service, deploy script and pipeline that runs a `prisma` command against a database must move to this release at the same time (`prisma-tables-move-to-prisma-schema` on PostgreSQL, `sqlite-prisma-tables-renamed` on SQLite). If the contract declares a namespace `prisma` or `prisma_contract`, settle its new name with the user before anything else (`rename-a-namespace-named-prisma`). Check every database for what would stop the move of Prisma's own tables in the deploy, with the read-only queries `prisma-tables-move-to-prisma-schema` gives under "Check each database before the deploy", and fix what they find. If an extension the project uses has no release for `8.0.0-rc.26`, such as `@prisma/orm-extension-paradedb`, stop and tell the user: the project cannot upgrade until the extension publishes one. On MongoDB, if a relation or a member of a composite type or value object is named `__proto__`, rename it and move its values with the release you are on (`mongo-proto-field-and-relation-names-refused`), so the upgrade carries no change of its own to what is stored.
403
+ 2. Upgrade Prisma in a release of the application that carries no new migration of its own. Move `prisma`, the package that provides the `prisma` command, to the version whose `@prisma/orm-toolchain` dependency is exactly the ORM version this step installs, and write that version exactly, as [Choosing the `prisma` version](../../../../references/upgrade-app.md#choosing-the-prisma-version) describes. Read its dependencies, not its own number: `prisma` `8.0.0-rc.37` depends on `@prisma/orm-toolchain` `8.0.0-rc.26`, so it runs with `8.0.0-rc.26` and not with `8.0.0-rc.27`. `prisma` `8.0.0-rc.36` runs the toolchain of `8.0.0-rc.25`, but loads this release's database package through the project's config. The old toolchain passes this release's contract reader a contract with no format version it recognises, and reports the reader's `CONTRACT.FORMAT_VERSION_MISSING` error under its own code. So once the guide's scripts have upgraded the project, its commands fail with `CONTRACT.VALIDATION_FAILED` and "The contract file has no format version". If a `prisma` command fails that way, the `prisma` the project runs is still an earlier one: choose its version again as above and install. Before you run the install, fix `package.json`: list the platform packages beside the database package (`list-the-platform-packages`), and change the config to import `prisma/config` and remove the `@prisma/cli-engine` line where its section says so (`config-imports-prisma-config`). Put each other required peer dependency, such as `temporal-polyfill`, `pg` and `@types/pg`, where `list-the-platform-packages` says. Then move every `@prisma/orm-*` package, and each extension released with the ORM, to `8.0.0-rc.26` and install. This is the only step that upgrades the extensions. If `8.0.0-rc.27` or later is published, take this step together with the steps up to it, as [Steps taken together](../../../../references/upgrade-app.md#steps-taken-together) describes, and install that release here instead, with the `prisma` version that fits it: its `prisma contract emit` brings the application's snapshot of the emitted contract up to date, which `8.0.0-rc.26`'s does not (`contract-hash-inputs`, under "A database created during or after the deploy").
404
+ 3. Run the three scripts that rewrite import paths and names, in this order, and make the changes by hand that each one lists: `facade-paths-an-application-uses`, then `platform-paths-an-extension-uses`, then `contract-signature-names` (`contract-signature-flag` and the entries after it). Each later script reads what the earlier one wrote. Then change any value imported from a database package's `contract-types` (`contract-types-exports-types-only`). A type check at this step finds the imports to fix (`TS2307`, `TS2305`, `TS1361`, `TS1362`). Until step 5 emits the contract, `contract.d.ts` still has the old shape, so code that uses the client can report errors that do not name the contract. Besides errors that name the contract's `capabilities` or `requiredCapabilities`, expect, for example, `TS2349` "This expression is not callable" on a method that a capability enables, such as `.returning()`, `TS2339` "Property 'title' does not exist on type '{}'" on the row such a query returns, `TS2769` "No overload matches this call" on `.distinctOn()`, and `TS2345` on a `transaction` callback, whose message says the contract declares no dependency on `conn.interactiveTransactions`. Do not fix these by hand. Type-check again after step 5's `prisma contract emit`, and fix only what is left then. Some of that is for step 6, such as `TS2339` for `fragment` on the ORM client (`fragment-on-the-client`).
405
405
  4. Change the code that reads a contract's capabilities (`code-reads-required-capabilities`, `required-capabilities-as-list`, `postgres-hand-built-contract-lists-capabilities`, `postgres-capability-flags-removed`, `postgres-capability-exports-moved`). On PostgreSQL, write the list of capabilities the contract requires where the contract is written (`postgres-contract-lists-required-capabilities`, `postgres-config-without-define-config-passes-capabilities`, `postgres-transaction-needs-interactive-transactions`). Do not run `prisma contract emit` yet.
406
- 5. Bring the stored files up to date: run the `stored-files-format-version` script, then the `contract-hash-inputs` script, then run `prisma contract emit` once, as `contract-hash-inputs` says in its steps 2 and 4 (step 2 of this order already upgraded the extensions, which is its step 3). That one emit also covers `stored-contract-needs-the-upgrade-script`, `stored-required-capabilities-as-list` and `postgres-emitted-contract-is-emitted-again`. Commit the result. If the emitted contract's storage hash differs from the one the script printed, plan the one migration `contract-hash-inputs` describes in its step 4. Rewrite a `__proto__:` key in a `migration.ts` that an earlier release generated before you run that file again (`migration-ts-proto-key-computed`).
407
- 6. Change the rest of the application code: `fragment()` on the client (`fragment-on-the-client`), `fns` comparisons (`orm-fns-comparison-takes-field-input-type`), `updateAll` and `updateAndCount` with a type argument (`update-all-explicit-type-argument`), SQL builder joins (`sql-builder-shared-join-column-name-needs-table`), list columns in the PostgreSQL SQL builder (`sql-builder-list-column-in-a-one-value-position`), code generic over a prepared declaration (`prepared-declaration-param-spec-can-be-a-list`), a check of `char(n)[]` values written with 8.0.0-rc.25 (`postgres-char-bit-list-values-check`), sets of values that may grow (`app-middleware-handles-later-activities`, `app-switches-over-later-values`, `app-geometry-may-gain-types`), the console logger (`default-logger-console`), and code that caught the signature read errors (`runtime-signature-check-only-warns`). On MongoDB, read what the planner now does with a changed stored name before you plan any migration (`mongo-stored-name-change-is-a-rename` and the entries after it). Then type-check and test the application.
408
- 7. Change the project's own text that names Prisma's tables or the old commands: SQL, scripts, grants, tests and docs that name `prisma_contract`, the `marker` table, `_prisma_marker` or `_prisma_ledger` (`name-the-prisma-schema`, `marker-table-is-signatures`, `sqlite-prisma-tables-renamed`), CI commands that run `db init` or `db update` (`db-init-db-update-ref-rule`), and scripts that pass a contract argument or match on its error codes, or resolve one through the control API (`contract-argument-one-parser`, `control-api-ref-resolution-takes-migration-dir`). Planned migrations are not edited.
409
- 8. Where the project has a staging database set up like production, with the same roles, deploy the upgrade there first, as below. That run moves the staging database's tables for good: from then on, every tool that changes the staging database must be on `8.0.0-rc.26`, as `prisma-tables-move-to-prisma-schema` says for every database. Then deploy. Against every database that existed before the deploy, run `prisma db sign --no-advance-ref` and then `prisma db migrate`, as `contract-hash-inputs` says in its step 5. That first command also moves Prisma's own tables (`prisma-tables-move-to-prisma-schema`, `sqlite-prisma-tables-renamed`); if it stops, its section says why and what to do. On PostgreSQL, right after it and before the application on the new release runs, grant a role other than the one that ran the command `SELECT` on `prisma.signatures`, and on `prisma.config` where the role runs Prisma's commands (`name-the-prisma-schema`).
406
+ 5. Bring the stored files up to date: run the `stored-files-format-version` script, then the `contract-hash-inputs` script, then run `prisma contract emit` once, as `contract-hash-inputs` says in its steps 2 and 4 (step 2 of this order already upgraded the extensions, which is its step 3). That one emit also covers `stored-contract-needs-the-upgrade-script`, `stored-required-capabilities-as-list` and `postgres-emitted-contract-is-emitted-again`. Run each of the two scripts once per Prisma project folder, giving it the folder, as `contract-hash-inputs` says in its step 2. Commit the result. If the emitted contract's storage hash differs from the one the script printed, plan the one migration `contract-hash-inputs` describes in its step 4. From here on, do not run a planned `migration.ts` again (`contract-hash-inputs`, under "Do not run a planned `migration.ts` again").
407
+ 6. Change the rest of the application code: `fragment()` on the client (`fragment-on-the-client`), `fns` comparisons (`orm-fns-comparison-takes-field-input-type`), `updateAll` and `updateAndCount` with a type argument (`update-all-explicit-type-argument`), SQL builder joins (`sql-builder-shared-join-column-name-needs-table`), list columns in the PostgreSQL SQL builder (`sql-builder-list-column-in-a-one-value-position`), code generic over a prepared declaration (`prepared-declaration-param-spec-can-be-a-list`), tests that count the SQL statements a call sends (see the paragraph below), a check of `char(n)[]` values written with 8.0.0-rc.25 (`postgres-char-bit-list-values-check`), sets of values that may grow (`app-middleware-handles-later-activities`, `app-switches-over-later-values`, `app-geometry-may-gain-types`), the console logger (`default-logger-console`), and code that caught the signature read errors (`runtime-signature-check-only-warns`). On MongoDB, read what the planner now does with a changed stored name before you plan any migration (`mongo-stored-name-change-is-a-rename` and the entries after it). Then type-check and test the application.
408
+
409
+ On PostgreSQL and SQLite, `deleteAll()` and `updateAll()` with more than one `.where()` call send one statement again, a `DELETE … RETURNING` or an `UPDATE … RETURNING`, as `8.0.0-rc.23` did. `8.0.0-rc.24` and `8.0.0-rc.25` sent a `SELECT` of the matching rows first and then the write, so a call could return a row that another connection had changed or deleted in between. A test that counts the statements such a call sends now sees one fewer for each such call: lower its expected count by one. On MySQL the statements do not change.
410
+
411
+ On PostgreSQL, when the driver takes a connection from its pool that was last used a second or more ago, it first checks that the connection still answers, and replaces it if it does not, for example because the server closed it ([prisma/orm#31229](https://github.com/prisma/orm/pull/31229)). Nothing needs to change. An application that checks for dead pooled connections itself, such as with a `SELECT 1` before each use, may remove that check for the queries Prisma runs; tell the user rather than removing it unasked. Keep it where the application calls `pool.query()` or `pool.connect()` directly on the pool it gave Prisma: the driver does not check those connections. A Prisma client built on a single `pg.Client`, or on the serverless entry, sends no such check: it has one connection and nothing to swap to.
412
+ 7. Change the project's own text that names Prisma's tables or the old commands: SQL, scripts, grants, tests and docs that name `prisma_contract`, the `marker` table, `_prisma_marker` or `_prisma_ledger` (`name-the-prisma-schema`, `marker-table-is-signatures`, `sqlite-prisma-tables-renamed`), CI commands that run `db init` or `db update` (`db-init-db-update-ref-rule`), and scripts that pass a contract argument or match on its error codes, or resolve one through the control API (`contract-argument-one-parser`, `control-api-ref-resolution-takes-migration-dir`). Do not edit planned migrations by hand. The scripts of steps 3 and 5 change `migration.ts` files, which is expected (`facade-paths-an-application-uses`, `contract-hash-inputs`).
413
+ 8. Where the project has a staging database set up like production, with the same roles, deploy the upgrade there first, as below. That run moves the staging database's tables for good: from then on, every tool that changes the staging database must be on this release or a later one, as `prisma-tables-move-to-prisma-schema` says for every database. Then deploy. Against every database that existed before the deploy, run `prisma db sign --no-advance-ref` and then `prisma db migrate`, as `contract-hash-inputs` says in its step 5, which gives a form of the first command that signs only a database that still needs it, and, for a deploy that does not sign, the order to follow when CI deploys on every merge. The same step lists two CI changes the upgrade's pull request may need: an exception for a check that runs `migration.ts` files, and making read-only checks against shared databases non-blocking during the switch. That first command also moves Prisma's own tables (`prisma-tables-move-to-prisma-schema`, `sqlite-prisma-tables-renamed`); if it stops, its section says why and what to do. On PostgreSQL, right after it and before the application on the new release runs, grant a role other than the one that ran the command `SELECT` on `prisma.signatures`, and on `prisma.config` where the role runs Prisma's commands (`name-the-prisma-schema`).
410
414
 
411
415
  ## The application lists the platform packages
412
416
 
@@ -484,7 +488,7 @@ import { definePrismaConfig } from 'prisma/config';
484
488
  // package.json, when no source file imports the engine and Yarn does not limit hoisting
485
489
  "devDependencies": {
486
490
  - "@prisma/cli-engine": "^0.10.4",
487
- "prisma": "^8.0.0-rc.37"
491
+ "prisma": "<the version step 2 of the order chose>"
488
492
  }
489
493
  ```
490
494
 
@@ -505,11 +509,11 @@ From release 8.0 every path a Generally Available Prisma package publishes is ke
505
509
  - `@prisma/orm-target-<database>`, such as `@prisma/orm-target-postgres`: the target, adapter and driver of one database.
506
510
  - `@prisma/orm-toolchain`: the command-line tooling, such as the migration tools.
507
511
 
508
- This guide's script rewrites each import of a removed path. Files Prisma generated, such as `contract.d.ts` and migration files, import nothing that was removed. The extension guide has a script of the same file name, which sends every import to a platform package; this one sends a few to the database package's own modules. The folder each sits in, `upgrading/app/` or `upgrading/extension/`, tells them apart.
512
+ This guide's script rewrites each import of a removed path. Files Prisma generated, such as `contract.d.ts`, import nothing that was removed. A `migration.ts` can, when code in it, such as a data transform, imports a removed path like `@prisma/orm-postgres/adapter/runtime`. The script rewrites that import too, so that the file still compiles. That is expected and harmless: the migration's hash covers its `migration.json` and `ops.json`, not its `migration.ts`, and `ops.json` does not change. Commit the change, and do not run that `migration.ts` again (`contract-hash-inputs`, under "Do not run a planned `migration.ts` again"). The extension guide has a script of the same file name, which sends every import to a platform package; this one sends a few to the database package's own modules. The folder each sits in, `upgrading/app/` or `upgrading/extension/`, tells them apart.
509
513
 
510
514
  #### Where the guide and its script are
511
515
 
512
- This guide is part of the `prisma-8` skill. The skill ships inside the database package; after you install the new version, `prisma skills sync` copies it into the agent skills folder of each harness the project uses: `.agents/skills/prisma-8/`, `.claude/skills/prisma-8/`, `.cursor/skills/prisma-8/` or `.windsurf/skills/prisma-8/`. Any one of these copies will do. The script sits beside this guide in that copy, for example:
516
+ This guide is part of the `prisma-8` skill. Read it, and run its scripts, from the skill of the newest published release, which [Step 0 of the upgrade reference](../../../../references/upgrade-app.md#step-0--read-the-newest-releases-skill) unpacks in a folder outside the project. The commands in this guide name the copy that `prisma skills sync` writes into the project, `.agents/skills/prisma-8/` (or `.claude/skills/prisma-8/`, `.cursor/skills/prisma-8/` or `.windsurf/skills/prisma-8/`); put the newest release's folder in its place. The script sits beside this guide in that copy, for example:
513
517
 
514
518
  ```text
515
519
  .agents/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/facade-paths-an-application-uses/facade-paths-an-application-uses.ts
@@ -517,7 +521,7 @@ This guide is part of the `prisma-8` skill. The skill ships inside the database
517
521
 
518
522
  Run it from that copy, not from the one under `node_modules/@prisma/orm-<database>/skills/`: Node does not strip types from a file under `node_modules`, so it refuses to run the script there. You need Node.js 24 or later, which Prisma 8 already requires; it runs the TypeScript file directly. It may print an `ExperimentalWarning` about type stripping, which is harmless.
519
523
 
520
- The script works on the folder you give it, or on the working directory, and every folder below it except `node_modules`, `dist`, `build` and folders whose name starts with a dot. In a monorepo, one run at the repository root covers every project in it; a run in each project that imports Prisma works too.
524
+ The script works on the folder you give it, or on the working directory, and every folder below it except `node_modules`, `dist`, `build`, folders whose name starts with a dot, and, in a git repository, the files and folders git ignores (through `.gitignore`, `.git/info/exclude` or the user's global ignore file). A file git tracks inside an ignored folder is still read, and so is the folder you give it, even if git ignores it. The two scripts that rewrite stored files, `stored-files-format-version` and `contract-hash-inputs`, also read a migrations folder that git ignores, and every file in it: nothing else writes those files again, and this release refuses a snapshot they have not upgraded. They recognise a migrations folder by what it holds, a contract snapshot store, a migration package or a ref file, directly or in a space folder. A copy of one inside a folder git ignores, such as `wip/`, is still skipped. The ignore rules of a nested repository or a submodule are not applied, so the scripts walk the folders it ignores. In a monorepo, a run at the repository root covers every package in it, and so does a run in each package that imports Prisma. The two scripts that read code with TypeScript, `platform-paths-an-extension-uses` and `contract-signature-names`, load the `typescript` package that code in the folder you give them would import, so where packages use different TypeScript versions, run those two once in each package. The two scripts that rewrite stored files, `stored-files-format-version` and `contract-hash-inputs`, are different: run each of them once per Prisma project folder, as `contract-hash-inputs` says in its step 2.
521
525
 
522
526
  #### Run the script
523
527
 
@@ -799,7 +803,14 @@ Commit your work first, so the script's changes can be reviewed and undone with
799
803
  node .agents/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/platform-paths-an-extension-uses/platform-paths-an-extension-uses.ts .
800
804
  ```
801
805
 
802
- As with the other script, run it from the skills copy, not from `node_modules`, with Node.js 24 or later. It reads each file with the project's own TypeScript compiler, so run it in a project whose `typescript` package is installed; if it finds none, it says so and stops without changing any file. It skips `node_modules`, `dist`, `build` and folders whose name starts with a dot.
806
+ As with the other script, run it from the skills copy, not from `node_modules`, with Node.js 24 or later. It reads each file with the project's own TypeScript compiler, so run it in a project whose `typescript` package is installed; if it finds none, it says so and stops without changing any file. It needs TypeScript 5 or 6: the `typescript` package of TypeScript 7 has no compiler API that a script can call. The script tries the project's `typescript` first, then one installed beside the script, and uses the first that has a compiler API. If neither has one, it changes no file, says that it needs TypeScript 5 or 6, and exits with code 1. Then do one of the two things its message offers:
807
+
808
+ - Leave the project unchanged: make an empty folder outside the project, write a `package.json` in it that holds `{"type": "module"}`, run `pnpm add typescript@5` in that folder, copy the script's `.ts` file into it, and run the copy with the project folder as its argument: `node <folder>/<script>.ts <project folder>`. Without that `package.json`, Node prints a `MODULE_TYPELESS_PACKAGE_JSON` warning, which is harmless.
809
+ - Install TypeScript 5 in the project for the run: `pnpm add -D typescript@5`, with `-w` added at the root of a pnpm workspace. This changes `package.json` and the lockfile, so after the run put back the `typescript` version you had, with `pnpm add -D typescript@<your version>` (with `-w` again where you used it), or `pnpm remove typescript` if the project had none; do not use `git checkout` on those files, which would also undo the other uncommitted changes the upgrade made to them.
810
+
811
+ If the script fails on an error it did not expect, it says "The script failed on an unexpected error, before it changed any file. This is a fault in the script; report it to Prisma with this output", prints the stack trace, and exits with code 1.
812
+
813
+ It skips `node_modules`, `dist`, `build`, folders whose name starts with a dot, and, in a git repository, the files and folders git ignores.
803
814
 
804
815
  The script:
805
816
 
@@ -825,7 +836,7 @@ The script reads only source files. Rename the old names in your Markdown and ot
825
836
  - An import of a name no published path exports any more, such as `planIssues` from `@prisma/orm-target-postgres/target` or `target/issue-planner`, `MigrationToolsError` from `@prisma/orm-toolchain/migration-tools`, `validateSqlContractFully` from `@prisma/orm-family-sql/contract`, `Tokenizer` from `@prisma/orm-framework/psl-parser/tokenizer` or `BuiltinFunctions` from `@prisma/orm-family-sql/relational-core/functions`.
826
837
  - A namespace import, an `export *`, a dynamic `import()` or a `require` of a path whose names are no longer published together, and one it moved, so you check the names it uses.
827
838
  - A `vi.mock` or `jest.mock` of a path this change moves. Point the mock at the module the code under test now imports, and rename what its factory returns.
828
- - A file that re-exports a renamed name under its old name. Rename the name where the project imports it, then drop the alias.
839
+ - A file that re-exports a renamed name under its old name. Rename the name where the project imports it, then drop the alias. When the project re-exports Prisma's error from a module of its own, such as a shared database package, every file that imports it from there uses the old name, which can mean a rename across most of the repository. The alias keeps those files compiling, so you can make that rename in a change of its own. Until then, make sure none of them tests the error's `name` against `'InternalError'`, which no error of this release has.
829
840
  - A check of `name` against `'InternalError'` in a file with no Prisma import of `InternalError`, or of `isPrismaInternalError` in a file that imports nothing from Prisma. If it means Prisma's error, use `isInvariantError`.
830
841
  - A `vi.mock` or `jest.mock` with a factory of a kept path that exports a renamed name, such as `@prisma/orm-family-sql/runtime`. Rename what its factory returns.
831
842
 
@@ -887,7 +898,7 @@ Every other name that is no longer published was a part of how Prisma builds its
887
898
 
888
899
  #### Check the result
889
900
 
890
- Type-check and test the application. A local binding of the same name as a renamed import, such as a parameter destructured as `{ InternalError }`, keeps its name, and so does a member read through a local binding that has the name of a namespace import, such as `errors.InternalError` on a parameter `errors`. Then run the script again: once you have rewritten everything it listed, it changes nothing and lists nothing.
901
+ Type-check and test the application. The script renames a check of `name` against `'InternalError'` only in a comparison or a `case`. A test that matches the name another way, such as `expect.objectContaining({ name: 'InternalError' })`, keeps it and fails; search the project for `'InternalError'` and change each match that means Prisma's error to `'InvariantError'`. A local binding of the same name as a renamed import, such as a parameter destructured as `{ InternalError }`, keeps its name, and so does a member read through a local binding that has the name of a namespace import, such as `errors.InternalError` on a parameter `errors`. Then run the script again: once you have rewritten everything it listed, it changes nothing and lists only what you chose to keep, such as a re-export alias or a check of your own error's name.
891
902
 
892
903
  ## `contract-types` exports types only
893
904
 
@@ -1028,14 +1039,16 @@ Commit your work first, so the script's changes can be reviewed and undone with
1028
1039
  node .agents/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-signature-names/contract-signature-names.ts .
1029
1040
  ```
1030
1041
 
1031
- With another copy, replace `.agents` with `.claude`, `.cursor` or `.windsurf`. Run it from that copy, not from `node_modules`, where Node does not strip the types. It walks the folder, skipping `node_modules`, `dist`, `build` and folders whose name starts with a dot other than `.github`, `.circleci`, `.gitlab` and `.buildkite`, prints each file it changed, and a second run changes nothing. In a file that uses a renamed name through an import, it reads the code with the project's own TypeScript compiler, so that a local binding of that name, such as a parameter destructured as `{ errorMarkerMissing }`, keeps its name, and so does a member read through a local binding that has the name of a namespace import, such as a parameter `errors` in a file that imports `@prisma/orm-framework/errors` as the namespace `errors`; if it finds no `typescript` package, it says so and stops without changing any file. It changes:
1042
+ With another copy, replace `.agents` with `.claude`, `.cursor` or `.windsurf`. Run it from that copy, not from `node_modules`, where Node does not strip the types. It walks the folder, skipping `node_modules`, `dist`, `build`, folders whose name starts with a dot other than `.github`, `.circleci`, `.gitlab` and `.buildkite`, and, in a git repository, the files and folders git ignores. It prints each file it changed, and a second run changes nothing. In a file that uses a renamed name through an import, it reads the code with the project's own TypeScript compiler, so that a local binding of that name, such as a parameter destructured as `{ errorMarkerMissing }`, keeps its name, and so does a member read through a local binding that has the name of a namespace import, such as a parameter `errors` in a file that imports `@prisma/orm-framework/errors` as the namespace `errors`; if it finds no `typescript` package, it says so and stops without changing any file. Like `platform-paths-an-extension-uses`, it needs TypeScript 5 or 6: it tries the project's `typescript` and then one beside the script, and when it needs TypeScript and finds only TypeScript 7, it changes no file and exits with code 1, with the same message and the same two ways out. It changes:
1032
1043
 
1033
- - `--marker-only` to `--signature-only` wherever it is written as a whole word, in code, `package.json`, shell scripts, YAML, TOML, Markdown, `Makefile`, `Dockerfile` and `justfile`;
1034
- - each of the nine renamed codes, wherever it is written;
1044
+ - `--marker-only` to `--signature-only` wherever it is written as a whole word, in code, `package.json`, shell scripts, YAML, TOML, `Makefile`, `Dockerfile` and `justfile`;
1045
+ - each of the nine renamed codes, wherever it is written outside Markdown;
1035
1046
  - in code, the values `'orphanMarker'`, `'markerChanged'` and `'marker-verification'`, written as strings;
1036
1047
  - in a code file that imports a renamed name from an `@prisma/orm-*` package, that import and the file's uses of it, keeping the key of an object written in shorthand (`{ errorMarkerMissing }` becomes `{ errorMarkerMissing: errorSignatureMissing }`), and in a file that imports from such a package, a renamed option or method where the file passes or calls it, such as `verifyMarker: false` or `.readMarker(…)`;
1037
1048
  - in a code file that runs `db verify`, `db init`, `db update` or `db migrate` with `--json`, the fields `marker` and `markerHash` where the file reads them, writes them as keys, or destructures them (`const { marker } = …`, `const { marker }: T = …`, `({ marker }) => …`), and the mode `'marker-only'`; and in a script or CI file, `.marker` and `.markerHash` on a line that runs one of those commands with `--json`.
1038
1049
 
1050
+ In Markdown files it changes nothing. It lists each place in them that names the old flag or an old code, or an old `--json` field on a line that runs `db verify`, `db init`, `db update` or `db migrate` with `--json`, because a sentence around it usually needs rewriting too, and a dated record, such as a changelog or a log of past problems, should keep the old names. It prints them last, under `Not changed:`, one line each, as `file:line: old -> new`, and still exits with code 0. Change by hand the places that describe how the project works now.
1051
+
1039
1052
 
1040
1053
  ```ts
1041
1054
  // before
@@ -1069,6 +1082,7 @@ The script finds names by searching the text of your code. It uses TypeScript on
1069
1082
  grep -rnE --exclude-dir=node_modules --exclude-dir=dist --exclude-dir=build --exclude-dir=upgrading '\.marker(Hash)?\b|\[.marker(Hash)?.\]|\{[^}]*\bmarker(Hash)?\b[^}]*\}[[:space:]]*[=:)]' .
1070
1083
  ```
1071
1084
 
1085
+ - **Messages.** The script renames codes and `--json` fields, not the text of messages. `db verify` now reports "The database's contract signature and schema match the contract" where it reported "Database marker and schema match contract", and, with `--signature-only`, "The database's contract signature matches the contract" where it reported "Database marker matches contract". Change a test or script that matches the old text.
1072
1086
  - **An option or name in a file with no Prisma import.** Options built in a separate object, or a file that uses a Prisma name without importing it from an `@prisma/orm-*` package, keep the old names. This search lists the old names left; change each one that is Prisma's:
1073
1087
 
1074
1088
  ```sh
@@ -1409,15 +1423,17 @@ Each file Prisma writes into your repository now says which version of its forma
1409
1423
 
1410
1424
  This release, and every release candidate after it, still reads a `migration.json` or a ref file a release candidate wrote without it: it converts the file in memory and leaves it on disk as it is, so you need not run this script now for those files. A contract or a migration snapshot a release candidate wrote is different. The contract stores what it requires as `capabilities`, which this release refuses, whatever its format version, with `CONTRACT.VALIDATION_FAILED` and the message "This contract was written by an earlier release of Prisma, in a format this release no longer reads. Prisma includes a tool that brings your stored contracts up to date. How to run it: https://docs.prisma.io/docs/orm/v8/reference/error-reference#CONTRACT.VALIDATION_FAILED" A snapshot is refused before that check, with `MIGRATION.CONTRACT_SNAPSHOT_CONTENT_MISMATCH`, because its storage hash was computed by the old hash rules. The `contract-hash-inputs` step of this release's upgrade instructions fixes both: it rewrites every hash, the contract and every snapshot. A `migration.json` or ref file from the newest release candidate is otherwise read as that release candidate wrote it, and holds this release's hashes once the `contract-hash-inputs` step has run. A file from an earlier release candidate also needs the other upgrade steps of each release since the one that wrote it; the command that reads the file names the step for content it no longer accepts. `8.0.0` reads only files that have it. Without it, `prisma db migrate`, `prisma db update`, `prisma migration plan` and the other commands stop with `CONTRACT.FORMAT_VERSION_MISSING` (for a contract or a snapshot) or `MIGRATION.FORMAT_VERSION_MISSING` (for a `migration.json` or a ref file), naming the file. So does a client given a `contract.json` that lacks it. Run the script before you upgrade to `8.0.0`. A contract that Prisma built in memory, by the TypeScript contract builder or by `contractFromJson`, has no format version and needs none.
1411
1425
 
1412
- Commit your work first, so the script's changes can be reviewed and undone with git. Then run the script from the project root:
1426
+ Commit your work first, so the script's changes can be reviewed and undone with git. Then run the script once for each Prisma project folder, the folder that holds a `prisma.config.ts` and the migrations folder it configures, from the folder that holds the skills copy, usually the repository root. Give it the project folder as its one argument, relative to where you run it; without one, it works on the working directory. For a project at the repository root, the argument is `.`; for one in `packages/database`:
1413
1427
 
1414
1428
  ```sh
1415
- node .agents/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/stored-files-format-version/stored-files-format-version.ts
1429
+ node .agents/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/stored-files-format-version/stored-files-format-version.ts packages/database
1416
1430
  ```
1417
1431
 
1418
- The path names the copy of the `prisma-8` skill in `.agents/skills/`. Where the project has no `.agents` folder, use the copy in the agent's own skills folder instead: `.claude/skills/`, `.cursor/skills/` or `.windsurf/skills/`.
1432
+ Do not give it a folder that holds more than Prisma projects, such as the root of a monorepo whose projects are in packages: it would also reach files that look like Prisma's but are not, such as test fixtures copied from another project. If one of them cannot be read as Prisma's, the script changes no file at all and exits with code 1. The script takes one argument at most, the folder, and no option; given more, it prints its usage line and exits with code 1.
1419
1433
 
1420
- Node 24 or later runs the TypeScript script directly; it needs no `tsx`. It reads and writes files only and needs no database. It walks the project, skipping `node_modules`, `dist`, `build` and directories whose name starts with a dot, and:
1434
+ The path names the copy of the `prisma-8` skill in `.agents/skills/`. Put the folder of the newest release's skill in its place, as [Step 0 of the upgrade reference](../../../../references/upgrade-app.md#step-0--read-the-newest-releases-skill) says.
1435
+
1436
+ Node 24 or later runs the TypeScript script directly; it needs no `tsx`. It reads and writes files only and needs no database. It walks the folder you gave it, skipping `node_modules`, `dist`, `build`, directories whose name starts with a dot, and, in a git repository, the files and folders git ignores other than a migrations folder and what is in it, and:
1421
1437
 
1422
1438
  - in every contract (any `*.json` file with `targetFamily`, `storage` and `schemaVersion` at the top level: the emitted `contract.json` and each snapshot's), replaces `"schemaVersion": "1"` with `"formatVersion": 1`;
1423
1439
  - in every `migration.json` that has an `ops.json` next to it, and every ref file under `<migrations>/<space>/refs/`, adds `"formatVersion": 1` as the first field. `<migrations>` is a folder that holds Prisma's contract snapshot store (a `snapshots` folder with a `<hash>/contract.json` in it) or a migration (a folder with both `migration.json` and `ops.json`), whatever the folder is named, so a migrations folder configured under another name is found too, and another tool's folder named `migrations` is not. A JSON file in any other `refs` folder is a ref when its content is one: a `hash` that is `empty` or a 64-character storage hash, and an `invariants` list of strings. So the refs of a space with no migrations are found even when `migrations/snapshots/` was deleted. Any other JSON file in a `refs` folder is not Prisma's, and the script leaves it alone.
@@ -1426,7 +1442,7 @@ It edits each file in place and keeps the rest of its bytes and layout. It print
1426
1442
 
1427
1443
  A ref file may have fields a ref does not have, for example a note added by hand. Earlier releases ignored such a field when they read the ref, and dropped it when they wrote the ref again. A ref file with `formatVersion` and such a field is refused, so the script drops the field and lists each field it dropped.
1428
1444
 
1429
- The script leaves a file unchanged, says what is wrong with it and what to do, and exits 1 when it cannot tell the file is one a release of Prisma wrote: a `contract.json`, `migration.json` or ref file it cannot read or parse; a ref file in a migrations folder it recognises without a `hash` or an `invariants` list; a `migration.json` next to an `ops.json` with a field the format does not have or without one it has; a contract with both `formatVersion` and `schemaVersion`; a `contract.json` holding a contract with neither; a contract whose `schemaVersion` is not `"1"`; a stored file whose `formatVersion` is not `1`; a snapshot's `contract.json` that is not a JSON object; and a directory it cannot list. It still changes every other file. Fix each reported file by hand as the report says, then run the script again.
1445
+ The script says what is wrong with a file and what to do, and exits 1, when it cannot tell the file is one a release of Prisma wrote: a `contract.json`, `migration.json` or ref file it cannot read or parse; a ref file in a migrations folder it recognises without a `hash` or an `invariants` list; a `migration.json` next to an `ops.json` with a field the format does not have or without one it has; a contract with both `formatVersion` and `schemaVersion`; a `contract.json` holding a contract with neither; a contract whose `schemaVersion` is not `"1"`; a stored file whose `formatVersion` is not `1`; a snapshot's `contract.json` that is not a JSON object; and a directory it cannot list. It checks every file before it writes any, so in that case it changes no file: it prints `Changed no file, because:` and one line for each problem. Fix each reported file by hand as the report says, then run the script again.
1430
1446
 
1431
1447
  Outside a migrations folder the script recognises, it cannot tell a broken ref from another tool's file, so it leaves alone, without a report, any file in a `refs` folder that does not have a ref's content. If a command still refuses a ref file after the script ran, that ref was already invalid, and earlier releases refused it too. Restore it from version control, or delete it and set it again with `prisma migration ref set <name> <contract>`.
1432
1448
 
@@ -1452,19 +1468,34 @@ Before you upgrade Prisma, deploy every pending migration to every database the
1452
1468
 
1453
1469
  The upgrade signs each database at the newest contract, which is safe only for a database that is already there. Signing a database that is behind either fails, because its schema does not match, and leaves `db migrate` refusing to run, or, when its pending migrations only drop something or move data, succeeds and marks it as up to date, so those migrations never run. A database that is still behind when the upgrade is deployed is covered in step 5, under "A database that is still behind".
1454
1470
 
1471
+ ##### Which databases this means
1472
+
1473
+ "Every database" is easy to get wrong, because some databases are set up by CI or by a deploy and are not named in the project's config. Before you deploy anything, make a list with the user: each database that a `prisma` command or a Composer deploy touches, grouped by environment, with where its connection string comes from. Look at least for:
1474
+
1475
+ - production, and staging or any other environment set up like it;
1476
+ - development databases, such as a shared development workspace;
1477
+ - the database of each pull request environment, if pull requests get one. Such an environment is often deployed from the pull request merged with the main branch, so its database moves to this release as soon as the upgrade is merged;
1478
+ - preview and demo databases;
1479
+ - databases that CI sets up with `prisma db init` or `prisma db migrate` and keeps between runs, such as a cache of a migrated test database;
1480
+ - databases that live on developers' machines for a long time, such as a local `prisma dev` or Docker database.
1481
+
1482
+ Do step 1 for each database on the list, and step 5 for each one that exists when the upgrade is deployed. For each database you cannot reach, ask the user to check it.
1483
+
1455
1484
  #### 2. Upgrade Prisma and run the script
1456
1485
 
1457
- Upgrade Prisma in a release of its own, with no new migration of your own in it. The script works on files with or without `formatVersion`, and leaves their format as it is, so it does not matter whether you have run the upgrade step for the stored-file format version (`stored-files-format-version`). Commit your work, so the script's changes can be reviewed and undone with git. Then run the script from the project root:
1486
+ Upgrade Prisma in a release of its own, with no new migration of your own in it. The script works on files with or without `formatVersion`, and leaves their format as it is, so it does not matter whether you have run the upgrade step for the stored-file format version (`stored-files-format-version`). Commit your work, so the script's changes can be reviewed and undone with git. Then run the script once for each Prisma project folder, the folder that holds a `prisma.config.ts` and the migrations folder it configures, from the folder that holds the skills copy, usually the repository root. Give it the project folder as its one argument, relative to where you run it; without one, it works on the working directory. For a project at the repository root, the argument is `.`; for one in `packages/database`:
1458
1487
 
1459
1488
  ```sh
1460
- node .agents/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-hash-inputs/contract-hash-inputs.ts
1489
+ node .agents/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-hash-inputs/contract-hash-inputs.ts packages/database
1461
1490
  ```
1462
1491
 
1463
- The path names the copy of the `prisma-8` skill in `.agents/skills/`. Where the project has no `.agents` folder, use the copy in the agent's own skills folder instead: `.claude/skills/`, `.cursor/skills/` or `.windsurf/skills/`.
1492
+ Do not give it a folder that holds more than Prisma projects, such as the root of a monorepo whose projects are in packages. The script checks every stored file below the folder before it changes anything. A hand-written `migration.json` whose `migrationHash` does not match its migration, or a snapshot with hashes no release wrote, such as in a test fixture written to look like another project, makes it change no file at all and exit with code 1. The script takes one argument at most, the folder, and no option; given more, it prints its usage line and exits with code 1. It skips a file git ignores, such as an emitted `contract.json` the project does not commit; the `prisma contract emit` of step 4 writes that file again.
1493
+
1494
+ The path names the copy of the `prisma-8` skill in `.agents/skills/`. Put the folder of the newest release's skill in its place, as [Step 0 of the upgrade reference](../../../../references/upgrade-app.md#step-0--read-the-newest-releases-skill) says.
1464
1495
 
1465
- Node 24 or later runs the TypeScript script directly. It reads and writes files only and needs no database. It walks the project, skipping `node_modules`, `dist`, `build` and directories whose name starts with a dot, and finds the same files the format version script does: every contract (any `*.json` file with `targetFamily` and `storage`, so the emitted `contract.json` and each snapshot), every `migration.json` with an `ops.json` beside it, and every ref file.
1496
+ Node 24 or later runs the TypeScript script directly. It reads and writes files only and needs no database. It walks the folder you gave it, skipping `node_modules`, `dist`, `build`, directories whose name starts with a dot, and, in a git repository, the files and folders git ignores other than a migrations folder and what is in it, and finds the same files the format version script does: every contract (any `*.json` file with `targetFamily` and `storage`, so the emitted `contract.json` and each snapshot), every `migration.json` with an `ops.json` beside it, and every ref file.
1466
1497
 
1467
- First it checks every contract: each stored hash, and each snapshot directory's name, must be the hash the old rules or the new rules give the contract's content. A storage hash that matches neither means the file was edited by hand or comes from another release. The script then changes no file, names each such file, and exits 1. The one exception is a contract that is not a snapshot and whose storage hash no migration, ref or snapshot names, such as a hand-made test fixture: the script leaves that file alone, prints the hashes its content gives, still upgrades the rest of the project, and exits 1. Restore the file from version control, or emit it again if it is the emitted contract (`prisma contract emit` rewrites only the head snapshot of each extension, not the application's snapshots), and run the script again. It does the same for a `migration.json` whose `migrationHash` does not match the migration. Two kinds of snapshot are accepted although a stored hash does not match. An earlier release may have written a snapshot's profile or execution hash by other rules, and no version of the file has the right one; `prisma db sign <contract reference>` copies a snapshot's profile hash into the database's contract signature, so the script gives such a snapshot the hashes its content gives, before any database is signed, and lists it. And the upgrade steps that renamed MongoDB indexes and field storage names rewrote snapshots in place and kept their storage hashes, because contract signatures, the ledger and migrations name a snapshot by its hash; such a MongoDB snapshot, whose directory name and stored hash agree, takes the new hash of its content, every file that names it follows, and the script lists it.
1498
+ First it checks every contract: each stored hash, and each snapshot directory's name, must be the hash the old rules or the new rules give the contract's content. A storage hash that matches neither means the file was edited by hand or comes from another release. The script then changes no file, names each such file, and exits 1. The one exception is a contract that is not a snapshot and whose storage hash no migration, ref or snapshot names, such as a hand-made test fixture: the script leaves that file alone, prints the hashes its content gives, still upgrades the rest of the project, and exits 1. Restore the file from version control, or emit it again if it is the emitted contract (`prisma contract emit` rewrites only the head snapshot of each extension, not the application's snapshots), and run the script again. It does the same for a `migration.json` whose `migrationHash` does not match the migration. An intermediate contract beside a migration's `migration.ts` is left alone the same way, but does not make the script exit 1 and is not to be restored or emitted, as "An intermediate contract" below says. Two kinds of snapshot are accepted although a stored hash does not match. An earlier release may have written a snapshot's profile or execution hash by other rules, and no version of the file has the right one; `prisma db sign <contract reference>` copies a snapshot's profile hash into the database's contract signature, so the script gives such a snapshot the hashes its content gives, before any database is signed, and lists it. And the upgrade steps that renamed MongoDB indexes and field storage names rewrote snapshots in place and kept their storage hashes, because contract signatures, the ledger and migrations name a snapshot by its hash; such a MongoDB snapshot, whose directory name and stored hash agree, takes the new hash of its content, every file that names it follows, and the script lists it.
1468
1499
 
1469
1500
  Then it computes each contract's new hashes and rewrites, keeping every other byte of each file:
1470
1501
 
@@ -1484,10 +1515,15 @@ The script changes no file at all, names the cause and exits 1 when a link leads
1484
1515
  The script exits 1 without changing that file when it cannot finish one:
1485
1516
 
1486
1517
  - A `migration.json` or ref file names a storage hash that no contract or snapshot in the project has, so the script cannot tell its new value. Prisma copies an extension's migrations into `migrations/<extension>/`, without a snapshot of every contract in between. For a migration there, delete its folder: after you upgrade the extension, `prisma contract emit` writes it again from the extension's new version, with the new hashes, and the script accepts it from then on, because those migrations lead to the extension's head, which already has its new hash. Restore anything else from version control, or set a ref again with `prisma migration ref set` after the upgrade.
1518
+
1519
+ This happens in many projects that use an extension, such as pgvector, whose earlier releases shipped migrations the project's snapshots do not cover. The run has then rewritten every other file, often hundreds, and exits with code 1 although it did its work. That exit is expected: delete the folders it names, as above, and go on to step 3 and step 4, whose `prisma contract emit` writes them again.
1487
1520
  - A contract file that is not a snapshot, and whose storage hash no migration, ref or snapshot names, such as a hand-made test fixture, has a hash its content does not give. The script leaves it alone and prints the hashes its content gives; set them, or emit it again if Prisma writes it. The rest of the project is still upgraded.
1488
1521
  - A `contract.json` has neither `formatVersion` nor `schemaVersion`, so no release of Prisma wrote it. The script leaves it alone.
1489
1522
  - A `contract.d.ts` names a hash that is not one of its contract's. Emit the contract again with `prisma contract emit` (or, for a snapshot, restore both files from version control) and run the script again.
1490
1523
  - A contract's capabilities cannot be renamed: two old keys become one key with different values (such as `sql.distinctOn: false` beside `postgres.distinctOn: true`, which both become `db.distinctOn`), the file has both `capabilities` and `requiredCapabilities`, `requiredCapabilities` is neither a list of strings nor an object, or a `sql` or `postgres` namespace of `capabilities`, or a provider of a grouped `requiredCapabilities`, is not an object. The script changes no file and names the contract and the reason. Emit the contract again with `prisma contract emit` if Prisma writes it, or fix the file by hand (for a snapshot, keep one value per key and one of the two fields), and run the script again.
1524
+ - A contract's `execution.mutations.defaults` refs still have the keys `table` and `column`, which 8.0.0-rc.13 renamed to `entry` and `field`. When the contract is a snapshot, or a migration, ref or snapshot names its storage hash, the script changes no file, exits 1, and names the contract and its refs under "Changed no file, because:". For such a contract under a `migrations` folder, run the command the message gives from the project root. It runs the script of the 8.0.0-rc.12 to 8.0.0-rc.13 step `execution-ref-entry-field` from the same skill copy, which renames the keys in every contract under `migrations/`: `node <skill>/upgrading/app/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/scripts/execution-ref-entry-field/rename-execution-ref-keys.ts`, where `<skill>` is the folder of the `prisma-8` skill copy, such as `.agents/skills/prisma-8`. For any other such contract, emit it again with `prisma contract emit`, as that step says. Then run this script again. A contract with such refs that nothing names, and that is not a snapshot, does not stop the run: an intermediate contract is listed as one, as below, and any other, such as a hand-made test fixture, is listed under "Left unchanged:" and makes the script exit 1. Emit that one again if Prisma writes it, or rename the keys by hand.
1525
+
1526
+ An intermediate contract is a contract emitted into a migration's directory, such as `intermediate.json`, that its `migration.ts` imports to type the queries of a data migration against a state between its two contracts. When its stored hashes are the ones the earlier release gave its content, the script rewrites it like any other contract. When they are not, for example because a release before 8.0.0-rc.25 emitted it, or it was edited by hand, or when its execution default refs still have the keys from before 8.0.0-rc.13, the script leaves it alone and lists it last, under "Intermediate contracts, left as they are". Such a file does not make the script exit with code 1: when it is all that is left, the script exits with code 0, and a second run lists it again and still exits with code 0. Leave such a file as it is, and do not set its hashes. It keeps its old `capabilities`, so running that `migration.ts` again would fail with `CONTRACT.VALIDATION_FAILED`. The file is read only when that `migration.ts` runs, and after this upgrade you do not run it again (see "Do not run a planned `migration.ts` again" below). The script takes a contract for an intermediate one only when its directory also holds the migration's `migration.json`, `ops.json` and `migration.ts`. A contract with wrong hashes elsewhere, whose storage hash nothing names, is listed under "Left unchanged:" as in the list above, and makes the script exit with code 1. A contract with wrong hashes whose storage hash a migration, ref or snapshot names, in a migration's directory or not, stops the run as described above.
1491
1527
 
1492
1528
  #### 3. Upgrade every extension with Prisma
1493
1529
 
@@ -1537,11 +1573,19 @@ import { Migration, MigrationCLI, rawSql } from '@prisma/orm-postgres/migration'
1537
1573
 
1538
1574
  Each database is then at the contract the script's hashes name, which is the `to` of the migration before the new one, not at the emitted contract. So in step 5 sign each database at that migration's directory name, `prisma db sign --no-advance-ref <migration directory name>`, for example `prisma db sign --no-advance-ref 20261128T0807_add_post_meta` (with `--force` where the change policy permits only migrations), and then `prisma db migrate` applies the new migration. This is the route under "A database that is still behind" in step 5, with the directory name of your last migration before the new one.
1539
1575
 
1576
+ ##### Do not run a planned `migration.ts` again
1577
+
1578
+ Running a migration's `migration.ts` writes its `ops.json` and the `migrationHash` in its `migration.json`. This release can write other checks into `ops.json` than the release that planned the migration, such as new prechecks and postchecks. So after this upgrade, running a `migration.ts` that an earlier release planned changes its `ops.json` and its `migrationHash`, and the migration is no longer the one every database applied in step 1. Do not run a planned `migration.ts` again: after step 1, a database has applied every one in the project. The one `migration.ts` this upgrade runs is a new one you write in the step above, which no database has applied yet.
1579
+
1580
+ The scripts change planned `migration.ts` files without running them: `contract-hash-inputs` rewrites the hashes in each, and `facade-paths-an-application-uses` may rewrite an import. Neither changes what the migration does, and the migration's hash does not cover `migration.ts`.
1581
+
1582
+ Some projects have a CI check that runs each `migration.ts` a pull request changes and fails when the files it writes differ from the committed ones. On the upgrade's pull request that check runs every planned `migration.ts`, because the script changed each one, and it fails. Make an exception for that one pull request, for example by skipping the check on it, and keep the check for later pull requests. Tell the user before you change CI.
1583
+
1540
1584
  #### 5. Sign every database in that release's deploy
1541
1585
 
1542
1586
  Each database records the storage and profile hash of the contract it was last moved to, in its contract signature. That is the old hash, so each database must be signed with this release. `db sign` checks that the database's schema matches the contract and then writes the new hashes into the signature; it changes no table.
1543
1587
 
1544
- In the deploy of the release that upgrades Prisma, run these two lines, in place of `prisma db migrate`, against every database that existed before that deploy:
1588
+ In the deploy of the release that upgrades Prisma, run these two lines, in place of `prisma db migrate`, against every database that existed before that deploy. In a deploy script, guard the first line as "Sign only a database that still needs it" below shows.
1545
1589
 
1546
1590
  ```sh
1547
1591
  prisma db sign --no-advance-ref
@@ -1554,20 +1598,73 @@ If step 4 gave the release a migration, name the directory of the migration befo
1554
1598
 
1555
1599
  A database whose change policy permits only migrations, usually production, refuses `db sign` with "This database's change policy permits only migrations". For it, the first line is `prisma db sign --no-advance-ref --force`. `--force` overrides only the change policy's refusal: `db sign` changes no schema, still checks that the database matches the contract of the application and of each extension before it writes a signature, and leaves the database's policies as they were.
1556
1600
 
1557
- A database created during or after that deploy, such as a preview or test database, has no signature and needs only `prisma db migrate`. Do not run `db sign` on it: it checks the contract against the empty database, which does not match, and exits with code 4, which stops a deploy script before `db migrate` runs. If the same deploy script also creates databases, let it tell the two apart: `prisma db verify --json` reports the code `CONTRACT.SIGNATURE_MISSING` for a database with no signature. For a database a release candidate signed it reports another code: `CONTRACT.PRISMA_SPACE_BEHIND` on PostgreSQL and SQLite, whose Prisma tables have not moved yet, and `CONTRACT.SIGNATURE_MISMATCH` on MySQL and MongoDB. Each exits with a code other than 0, so read the code from the output:
1601
+ ##### Sign only a database that still needs it
1602
+
1603
+ A deploy script runs on every deploy, and it may also create databases. So guard the `db sign` line: let it run only against a database that a release candidate signed, and not against a database the deploy creates or one this release already signed. Do not leave the bare line in the deploy for someone to remove later. If it is forgotten, a later deploy signs the newest contract over a database that a pending migration has not reached yet, which either fails or marks that migration as applied, so it never runs.
1604
+
1605
+ `prisma db verify --signature-only --json` tells the cases apart. It exits with a code other than 0 for every database that is not yet signed with this release, whatever the reason, so read the output, not the exit code. It writes one JSON object per line.
1606
+
1607
+ On PostgreSQL and SQLite, it stops against a database a release candidate signed with the code `CONTRACT.PRISMA_SPACE_BEHIND` and, in the error's `meta`, `"situation":"releaseCandidateSchema"`, because Prisma's own tables have not moved yet. Sign when the output has that situation. Match the situation and not the code alone: the code has other situations too, where signing would be wrong.
1558
1608
 
1559
1609
  ```sh
1560
1610
  verify=$(prisma db verify --signature-only --json || true)
1561
1611
  case "$verify" in
1562
- *'"code":"CONTRACT.SIGNATURE_MISSING"'*) ;;
1563
- *) prisma db sign --no-advance-ref ;;
1612
+ *'"situation":"releaseCandidateSchema"'*) prisma db sign --no-advance-ref ;;
1564
1613
  esac
1565
1614
  prisma db migrate
1566
1615
  ```
1567
1616
 
1568
- This tells the two apart because no database that existed before the deploy lacks a signature: the release you are on writes one with every `db migrate`, `db init`, `db update` and `db sign`, and step 1 ran `db migrate` against every database. A database that has tables but no signature is one no Prisma 8 command has set up, such as a database from before Prisma 8. The script would treat it as new, and `db migrate` would apply every migration to it from the first. If the user names such a database, stop and tell them that this step does not cover it, and leave it out of the deploy until it is set up for Prisma 8.
1617
+ On MySQL, MariaDB and MongoDB, Prisma's tables do not move, and `db verify` reports a database a release candidate signed with `CONTRACT.SIGNATURE_MISMATCH`. That code also comes back for a database that a pending migration has not reached, so match the hash the database is signed with instead. That is the old storage hash of the contract every database is at after step 1: the `to` of the application's last migration before the script rewrote it, which `git diff` on that `migration.json` shows, and which the script printed under "Storage hashes (old -> new)" beside the new one; in a project with no migrations, take the line whose new hash is the `storageHash` in `contract.json`. The output names the database's hash, so sign when it contains the old one:
1618
+
1619
+ ```sh
1620
+ old=<the old storage hash>
1621
+ verify=$(prisma db verify --signature-only --json || true)
1622
+ case "$verify" in
1623
+ *"\"$old\""*) prisma db sign --no-advance-ref ;;
1624
+ esac
1625
+ prisma db migrate
1626
+ ```
1627
+
1628
+ In both forms, add to each command the options the deploy gives `prisma db migrate`, such as `--db` and `--config`, and add `--force` to `db sign` where the database's change policy permits only migrations. If step 4 gave the release a migration, name the directory of the migration before it in the `db sign` line, as step 4 says.
1629
+
1630
+ The guard relies on step 1: every database that existed before the deploy is at the newest contract. A database that is still behind needs the route under "A database that is still behind" below, run by hand; leave it out of the deploy until then.
1631
+
1632
+ On PostgreSQL and SQLite the guard matches only until Prisma's tables have moved. If a command of this release that changes the database already ran against it, for example a first deploy that stopped after `db migrate` moved the tables, or a `db sign` refused by the change policy, which moves the tables before it checks the policy, the guard no longer signs, and `prisma db migrate` stops with `MIGRATION.SIGNATURE_NOT_IN_GRAPH`. Sign that database by hand with `prisma db sign --no-advance-ref` (with `--force` where its change policy permits only migrations; if step 4 gave the release a migration, name the directory of the migration before it, as step 4 says), then run the deploy again.
1633
+
1634
+ After the deploy, `prisma db verify --signature-only` passes against every database on your list, because each signature then holds the emitted contract's storage and profile hash. Once every database on the list is signed, remove the guard, and later deploys run `prisma db migrate` alone. Until then it is safe to keep: it signs no database that this release signed or created.
1635
+
1636
+ ##### A database created during or after the deploy
1637
+
1638
+ A database created during or after the deploy, such as a preview or test database, has no signature. `db verify` reports it with `CONTRACT.SIGNATURE_MISSING`, the guard leaves it alone, and `prisma db migrate` sets it up and signs it. Do not run `db sign` on it: it checks the contract against the empty database, which does not match, and exits with code 4, which stops a deploy script before `db migrate` runs.
1639
+
1640
+ The guard tells such a database from one that existed before the deploy because no database that existed before the deploy lacks a signature: the release you are on writes one with every `db migrate`, `db init`, `db update` and `db sign`, and step 1 ran `db migrate` against every database. A database that has tables but no signature is one no Prisma 8 command has set up, such as a database from before Prisma 8. The guard would treat it as new, and `db migrate` would apply every migration to it from the first. If the user names such a database, stop and tell them that this step does not cover it, and leave it out of the deploy until it is set up for Prisma 8.
1641
+
1642
+ What `db migrate` writes into the new signature depends on how it is run. Without `--to`, or with `--to @contract`, it signs the emitted contract, with the storage and profile hash in `contract.json`. With `--to <ref>`, as every Composer deploy runs it, it signs the contract the ref names, with the hashes in that contract's snapshot under `migrations/snapshots/`. The script gave each snapshot the profile hash of the capabilities the snapshot lists, which are your earlier release's, and `prisma contract emit` of `8.0.0-rc.26` does not change the application's snapshots. So with `8.0.0-rc.26`, a new database migrated with `--to <ref>` is signed with the earlier release's profile hash. `prisma db verify` then fails with `CONTRACT.SIGNATURE_MISMATCH`, "The database is signed for other capabilities", and the client logs a `CONTRACT.SIGNATURE_MISMATCH` warning on its first query, though queries run.
1643
+
1644
+ From `8.0.0-rc.27`, `prisma contract emit` also brings the application's snapshot up to date when its storage hash is the emitted contract's (a ref that names an older contract still has that contract's old profile hash): it writes the emitted contract's required capabilities and profile hash into that snapshot's `contract.json` and `contract.d.ts`, and says so. It writes the snapshot's `contract.d.ts` again from its `contract.json`, so a diff of that file can show the whole file as changed. Its `contract.json` changes only in the profile hash and the required capabilities; its `contract.d.ts` is what this release writes for that `contract.json`, which for a snapshot an earlier release wrote can differ in other declarations too. Type-check the project after the emit. So:
1645
+
1646
+ - Run this upgrade with `8.0.0-rc.27` or later installed, as step 2 of the order at the top of this guide says, so that step 4's `prisma contract emit` is that release's.
1647
+ - A project that upgraded with `8.0.0-rc.26` installed: after upgrading to `8.0.0-rc.27` or later, run `prisma contract emit` and commit the snapshot it rewrites. Then run `prisma db sign --no-advance-ref` against each database created since the upgrade, with `--force` where its change policy permits only migrations. `prisma db verify` then passes against it.
1648
+
1649
+ ##### When CI deploys on every merge
1650
+
1651
+ With the guard, the deploy of the release that upgrades Prisma signs, which is the safe moment, and this section does not apply. It is for a deploy with no `db sign` line, where a person signs by hand: for example because the role the deploy runs as may not sign, or because someone runs the read-only checks of `prisma-tables-move-to-prisma-schema` first. When CI deploys the main branch on every merge, follow this order for each database the deploy migrates:
1652
+
1653
+ 1. Merge the upgrade. Merge nothing else until the last step.
1654
+ 2. Let the deploy run. Its `prisma db migrate` stops with `MIGRATION.SIGNATURE_NOT_IN_GRAPH` and applies no migration; on PostgreSQL and SQLite it has first moved Prisma's own tables. The deploy stops there, and the application already running keeps serving.
1655
+ 3. Sign the database: `prisma db sign --no-advance-ref`, with `--force` where its change policy permits only migrations. If step 4 gave the release a migration, name the directory of the migration before it, as step 4 says, so that `db migrate` then applies that migration.
1656
+ 4. Run the deploy again.
1657
+
1658
+ Do not sign before the merge. Until the upgrade is merged, any other merge deploys the earlier release, and that release does not work against a database this release signed. On PostgreSQL and SQLite its `prisma db migrate` does not see the tables `db sign` moved, creates new, empty ones and applies every migration again (`prisma-tables-move-to-prisma-schema`). On MySQL, MariaDB and MongoDB it finds a signature that none of its migrations leads to, and stops.
1659
+
1660
+ ##### Read-only checks in CI during the switch
1661
+
1662
+ Some projects run a command that only reads the database on every pull request, such as `prisma migration status --to <ref>` against production. Expect it to fail while the project switches to this release:
1663
+
1664
+ - Until a database is signed with this release, this release's read commands do not recognise how it is signed. On PostgreSQL and SQLite they stop with `CONTRACT.PRISMA_SPACE_BEHIND`, because Prisma's own tables have not moved yet; on MySQL, MariaDB and MongoDB, `migration status` warns with `MIGRATION.SIGNATURE_NOT_IN_GRAPH` and exits 0, which fails a check that reads the warning. So the check fails on the upgrade's own pull request.
1665
+ - Once the database is signed, a pull request whose branch is still on the earlier release runs that release's command. On PostgreSQL and SQLite it does not find the signature where that release looks for it; on MySQL, MariaDB and MongoDB it finds a signature none of its migrations leads to. So the check fails the other way, on every open pull request that has not merged the upgrade yet.
1569
1666
 
1570
- After the deploy, `prisma db verify --signature-only` passes against every database, because each signature then holds the emitted contract's storage and profile hash. Remove the `db sign` line once the release is deployed. Later deploys run `prisma db migrate` alone.
1667
+ Make such a check non-blocking for the length of the switch: from the upgrade's pull request until every open pull request has merged the main branch with the upgrade in it. Then make it blocking again. Tell the user before you change CI.
1571
1668
 
1572
1669
  ##### A database that is still behind
1573
1670
 
@@ -1580,12 +1677,12 @@ prisma db migrate
1580
1677
 
1581
1678
  Add `--force` to the first line where the change policy permits only migrations. `db sign` takes the directory name of a migration as its contract and signs the contract that migration leads to; `db migrate` then applies the migrations after it. Give its name, for example `prisma db sign --no-advance-ref 20261128T0807_add_post_meta`. A path to the directory, such as `migrations/app/20261128T0807_add_post_meta`, works too (`contract-argument-one-parser`).
1582
1679
 
1583
- The directory must be that of the migration that brought the database to the contract it is at, usually the last one it applied. On PostgreSQL, a database a release candidate set up keeps Prisma's own tables in the schema `prisma_contract`, and until a command that changes the database has moved them to `prisma` (see `prisma-tables-move-to-prisma-schema`), `migration status` and `migration log` stop with `CONTRACT.PRISMA_SPACE_BEHIND`. Run `prisma db migrate` once first: it moves Prisma's tables, then stops with `MIGRATION.SIGNATURE_NOT_IN_GRAPH` and changes nothing else. That error's advice does not apply here; follow this route. To find the directory, run two commands against the database:
1680
+ The directory must be that of the migration that brought the database to the contract it is at, usually the last one it applied. On PostgreSQL, a database a release candidate set up keeps Prisma's own tables in the schema `prisma_contract`, and until a command that changes the database has moved them to `prisma` (see `prisma-tables-move-to-prisma-schema`), `migration status` and `migration log` stop with `CONTRACT.PRISMA_SPACE_BEHIND`. Run `prisma db migrate` once first: it moves Prisma's tables, then stops with `MIGRATION.SIGNATURE_NOT_IN_GRAPH` and changes nothing else. From `8.0.0-rc.28`, when the database's ledger shows that an earlier release migrated it, that error says so and points to this step; it prints no command. Whatever that error advises, sign the database as this section says. To find the directory, run two commands against the database:
1584
1681
 
1585
1682
  - `prisma migration status` warns "The database's contract signature <hash> is not in the on-disk migration graph". That hash, shortened, is the contract the database is at, under the old hash rules.
1586
1683
  - `prisma migration log` lists the migrations the database applied, oldest first, each with its directory name and the contracts it moved the database from and to, under the old hashes and shortened to their first 7 characters. It shows a Space column only when more than one space has run migrations on the database; without it, every row is the application's. Take the directory of the last application row whose second hash is the first 7 characters of the signature's.
1587
1684
 
1588
- If that directory is the application's last migration, the one whose `migration.json` has as its `to` the `storageHash` in the emitted `contract.json`, nothing is pending on the database and it is not behind. Sign it with the two lines at the top of this step, which sign the emitted contract, and not at that directory. On PostgreSQL, signing it at the directory gives the signature the wrong profile hash. The script gave each snapshot the profile hash of the capabilities that snapshot lists, which are your earlier release's, while step 4 wrote this release's list, and its profile hash, into the emitted contract. `prisma db verify` then fails with `CONTRACT.SIGNATURE_MISMATCH`, "Contract profileHash does not match contract signature", and `prisma db migrate` says "Already up to date" and leaves the signature as it is, because it has nothing to apply. When at least one migration is pending, `db migrate` applies it and writes the emitted contract's hashes into the signature, so the route ends with both hashes right.
1685
+ If that directory is the application's last migration, the one whose `migration.json` has as its `to` the `storageHash` in the emitted `contract.json`, nothing is pending on the database and it is not behind. Sign it with the two lines at the top of this step, which sign the emitted contract, and not at that directory. Signing it at the directory can give the signature the wrong profile hash, with `8.0.0-rc.26`'s `prisma contract emit`, when step 4 changed the contract's required capabilities. The script gave each snapshot the profile hash of the capabilities that snapshot lists, which are your earlier release's, while step 4 wrote this release's list, and its profile hash, into the emitted contract. `prisma db verify` then fails with `CONTRACT.SIGNATURE_MISMATCH`, "Contract profileHash does not match the database's contract signature", and `prisma db migrate` says "Already up to date" and leaves the signature as it is, because it has nothing to apply. When at least one migration is pending, `db migrate` applies it and writes the hashes of the contract it migrates to into the signature: the emitted contract's without `--to` or with `--to @contract`, and the snapshot's with `--to <ref>`, which match the emitted contract's once `prisma contract emit` of `8.0.0-rc.27` or later has run (see "A database created during or after the deploy"). So the route ends with both hashes right.
1589
1686
 
1590
1687
  To put right a database signed at a directory with nothing pending, run `prisma db sign --no-advance-ref` against it (with `--force` where the change policy permits only migrations). It signs the emitted contract and writes its profile hash into the signature. `prisma db verify` then passes.
1591
1688
 
@@ -1597,7 +1694,7 @@ The route does not apply when an extension's migrations are pending on the datab
1597
1694
 
1598
1695
  The database stays usable, but the commands that compare it with the project see a contract they do not know:
1599
1696
 
1600
- - `prisma db migrate` stops before it applies any migration, with `MIGRATION.SIGNATURE_NOT_IN_GRAPH` (on PostgreSQL it has first moved Prisma's own tables, as `prisma-tables-move-to-prisma-schema` describes): "The database is at a contract that is not in the migration graph". Its advice does not apply here; sign the database as this step says.
1697
+ - `prisma db migrate` stops before it applies any migration, with `MIGRATION.SIGNATURE_NOT_IN_GRAPH` (on PostgreSQL it has first moved Prisma's own tables, as `prisma-tables-move-to-prisma-schema` describes): "The database is at a contract that is not in the migration graph". From `8.0.0-rc.28`, when the ledger shows an earlier release migrated the database, the error says so and points to this step. Whatever it advises, such as `prisma db update`, authoring migrations or installing a version of an extension, sign the database as this step says.
1601
1698
  - `prisma migration status` warns with `MIGRATION.SIGNATURE_NOT_IN_GRAPH`: "Database was updated outside the migration system".
1602
1699
  - `prisma db verify` fails with `CONTRACT.SIGNATURE_MISMATCH`: "The database is signed with a different contract".
1603
1700
  - At runtime, queries still run. A SQL client logs one `CONTRACT.SIGNATURE_MISMATCH` warning, to the console unless the application passes its own `log` (`default-logger-console`); a MongoDB client does not check the signature.
@@ -1612,7 +1709,7 @@ After the upgrade, `prisma migration status` shows none of the migrations applie
1612
1709
 
1613
1710
  A plan can hold a value with a `__proto__` key, for example a JSON column default. The previous release wrote that key into `migration.ts` as `__proto__:`, with or without quotes. In an object literal JavaScript reads that as the prototype of the object, not as a key. Applying the planned migration worked, because `migration plan` writes `ops.json` itself. Running `migration.ts` to regenerate `ops.json` did not: for a JSON default it failed with `CONTRACT.DEFAULT_INVALID`.
1614
1711
 
1615
- `migration plan` now writes the key as `['__proto__']:`, and a newly planned migration needs no edit. A `migration.ts` that an earlier release generated does not change by itself. In each file the detection matches, rewrite the key before you run the file again:
1712
+ `migration plan` now writes the key as `['__proto__']:`, and a newly planned migration needs no edit. A `migration.ts` that an earlier release generated does not change by itself. In each file the detection matches, rewrite the key before you run the file again. After this upgrade, that is only a migration no database has applied yet, such as one planned with the earlier release on a branch that is merged later: do not run a `migration.ts` that a database has applied (`contract-hash-inputs`, under "Do not run a planned `migration.ts` again").
1616
1713
 
1617
1714
  ```ts
1618
1715
  // before
@@ -2156,7 +2253,7 @@ Before, `createCollection` had no check after it ran. When a later operation of
2156
2253
 
2157
2254
  A collection that has the name but not those options, such as one made by hand with no validator, still stops the create: change or drop it yourself, then run the command again. The same holds when a hand-written `migration.ts` changes the options of a collection after creating it, for example with `setValidation`: a re-run then stops at the create, so give the final options in the `createCollection` call instead.
2158
2255
 
2159
- The check is written into `ops.json` when `migration.ts` is run. A migration emitted before this release keeps the old create until you run its `migration.ts` again, which changes its migration hash. Do that only if no other database has applied the migration. If one of those older migrations stops after its create, run it again once it is emitted anew. If another database has applied it, leave it as it is. Drop the collection only if it holds nothing you need, even when an earlier run of the command created it: an operation of that run may have moved documents into it from a collection it then deleted them from, and those documents are only there. After a stop on a database whose collection holds documents you need, move the collection aside, then run `prisma db migrate --to <migration directory name>` so the create makes the collection and the run stops after that migration, and copy the documents back. Follow the steps under the heading "Moving a MongoDB collection aside" in the entry for [`MIGRATION.PRECHECK_FAILED`](https://docs.prisma.io/docs/orm/v8/reference/error-reference#MIGRATION.PRECHECK_FAILED) in the error reference. They say to stop the application's writes first and keep them stopped until the last step, to apply the changes of the later operations to the moved documents, how to compare a document the run writes again under the same `_id`, how to copy a time-series collection, which MongoDB cannot rename, to drop the moved copy only once the copy back is checked, and to finish by running the command that stopped again as you ran it. That run starts again from the migration contract signature, so it may stop at another older create whose collection exists, in that migration or another one it applies; the same steps apply to it. This works under every change policy, and `migration status` then marks the migration as applied. Where the database's change policy permits `reconcile`, you can instead apply the operations that did not run by hand, then run `prisma db sign <migration directory name>`. `db sign` checks the collections, their validators and their indexes against the contract the migration leads to, not the documents, so check the documents yourself first. It then records the database at that contract, so the next `db migrate` starts after that migration; `migration status` shows the database as up to date but does not mark that migration as applied.
2256
+ The check is written into `ops.json` when `migration.ts` is run. A migration emitted before this release keeps the old create. Do not run its `migration.ts` again to get the check: every such migration was applied in step 1 of `contract-hash-inputs`, and running it again changes its `ops.json` and its migration hash, so it is no longer the migration your databases applied (`contract-hash-inputs`, under "Do not run a planned `migration.ts` again"). If one of those older migrations stops after its create, for example on a database created later, follow the steps below. Drop the collection only if it holds nothing you need, even when an earlier run of the command created it: an operation of that run may have moved documents into it from a collection it then deleted them from, and those documents are only there. After a stop on a database whose collection holds documents you need, move the collection aside, then run `prisma db migrate --to <migration directory name>` so the create makes the collection and the run stops after that migration, and copy the documents back. Follow the steps under the heading "Moving a MongoDB collection aside" in the entry for [`MIGRATION.PRECHECK_FAILED`](https://docs.prisma.io/docs/orm/v8/reference/error-reference#MIGRATION.PRECHECK_FAILED) in the error reference. They say to stop the application's writes first and keep them stopped until the last step, to apply the changes of the later operations to the moved documents, how to compare a document the run writes again under the same `_id`, how to copy a time-series collection, which MongoDB cannot rename, to drop the moved copy only once the copy back is checked, and to finish by running the command that stopped again as you ran it. That run starts again from the migration contract signature, so it may stop at another older create whose collection exists, in that migration or another one it applies; the same steps apply to it. This works under every change policy, and `migration status` then marks the migration as applied. Where the database's change policy permits `reconcile`, you can instead apply the operations that did not run by hand, then run `prisma db sign <migration directory name>`. `db sign` checks the collections, their validators and their indexes against the contract the migration leads to, not the documents, so check the documents yourself first. It then records the database at that contract, so the next `db migrate` starts after that migration; `migration status` shows the database as up to date but does not mark that migration as applied.
2160
2257
 
2161
2258
  ## The runtime's contract signature check only warns
2162
2259