@prisma/orm-mongo 8.0.0-rc.26 → 8.0.0-rc.28

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-DnxWWp96-D-vo6-SA.mjs → mongo-static-BcGm3FJA-Cu72kTZk.mjs} +3 -3
  2. package/dist/{mongo-static-DnxWWp96-D-vo6-SA.mjs.map → mongo-static-BcGm3FJA-Cu72kTZk.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
@@ -52,7 +52,7 @@ changes:
52
52
  - '@prisma/orm-(?:postgres|sqlite|mysql|mariadb|mongo)/contract-types[''"]'
53
53
  - id: contract-signature-flag
54
54
  summary: |
55
- `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.
55
+ `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.
56
56
  detection:
57
57
  glob: "**/*"
58
58
  matches:
@@ -60,7 +60,7 @@ changes:
60
60
  script: ./scripts/contract-signature-names/contract-signature-names.ts
61
61
  - id: contract-signature-error-codes
62
62
  summary: |
63
- 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.
63
+ 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.
64
64
  detection:
65
65
  glob: "**/*"
66
66
  matches:
@@ -444,8 +444,8 @@ This release changes every hash Prisma stores, so an extension built for an earl
444
444
 
445
445
  Make the changes below in this order, and skip a step that does not apply to the extension:
446
446
 
447
- 1. Fix `package.json` before you run the install: move every `@prisma/orm-*` package the extension's shipped code uses to `peerDependencies`, and list it under `devDependencies` too, at `8.0.0-rc.26` (`prisma-packages-are-peer-dependencies`). Move the `prisma` package the extension builds with to `8.0.0-rc.37` or later, the first release built on this one; an earlier `prisma` runs the toolchain of `8.0.0-rc.25` beside this release's packages. Once the bundled files are upgraded, its commands fail with `CONTRACT.VALIDATION_FAILED` and "The contract file has no format version": that is this release's `CONTRACT.FORMAT_VERSION_MISSING` error, which the old toolchain reports under its own code. Then install.
448
- 2. 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 the imports of the PostgreSQL client's parts to their Early Access names (`postgres-client-parts-early-access-names`, `sql-prepared-query-early-access-names`), and any value imported from a database package's `contract-types` (`contract-types-exports-types-only`). Until step 5 emits the contract, its `contract.d.ts` still has the old shape, so a type check before then also reports errors that name the contract's `capabilities` or `requiredCapabilities`; do not fix those by hand.
447
+ 1. Fix `package.json` before you run the install: move every `@prisma/orm-*` package the extension's shipped code uses to `peerDependencies`, and list it under `devDependencies` too, at `8.0.0-rc.26` (`prisma-packages-are-peer-dependencies`). Move the `prisma` package the extension builds with to the version whose `@prisma/orm-toolchain` dependency is exactly the ORM version the extension's `devDependencies` install, 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`. `prisma` `8.0.0-rc.36` runs the toolchain of `8.0.0-rc.25` beside this release's packages. Once the bundled files are upgraded, its commands fail with `CONTRACT.VALIDATION_FAILED` and "The contract file has no format version": that is this release's `CONTRACT.FORMAT_VERSION_MISSING` error, which the old toolchain reports under its own code. Then install.
448
+ 2. 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 the imports of the PostgreSQL client's parts to their Early Access names (`postgres-client-parts-early-access-names`, `sql-prepared-query-early-access-names`), and any value imported from a database package's `contract-types` (`contract-types-exports-types-only`). Until step 5 emits the contract, its `contract.d.ts` still has the old shape, so a type check before then also reports errors in code that uses a client of that contract, such as tests. Some name the contract's `capabilities` or `requiredCapabilities`; others do not, such as `TS2349` "This expression is not callable" on a method that a capability enables, such as `.returning()`, `TS2339` on a field of the row such a query returns, and `TS2345` on a `transaction` callback. Do not fix those by hand: type-check again after step 5's `prisma contract emit`, and fix only what is left then.
449
449
  3. Make the code changes, in any order: capabilities (`extension-code-reads-required-capabilities`, `required-capabilities-as-list`, `extension-descriptor-declares-no-capabilities`, `extension-capability-flags-removed`, `extension-client-goes-by-the-contract`, `extension-capability-exports-moved`), data types and index types (`data-type-param-keys` and the entries after it, `index-type-options-standard-schema`, `extension-index-types-checked-for-prisma-schemas`), the control API's contract resolvers (`control-api-ref-resolution-takes-migration-dir`), the database's config and Prisma's tables (`read-the-database-config`, `policy-helpers-renamed`, `name-the-prisma-schema`, `prisma-tables-api-breaks`, `sqlite-prisma-tables-renamed`, `sqlite-prisma-tables-api-breaks`), MongoDB and migration calls (`kept-enum-member-route-removed`, `mongo-runner-checked-policies-renamed`, `extension-migration-calls-use-framework-interface`), the ORM client (`fragment-on-the-client`, `aggregate-operation-names-after-8-0`, `orm-fns-comparison-takes-field-input-type`, `update-all-explicit-type-argument`, `prepared-declaration-param-spec-can-be-a-list`), sets of values that may grow (`extension-middleware-handles-later-activities`, `extension-switches-over-later-values`, `extension-more-open-sets-of-values`), and the stored-file APIs (`descriptor-self-consistency-takes-contract-json`, `contract-space-from-json-reads-stored-files`, `canonicalize-contract-takes-version-from-serializer`, `contract-serializer-prints-version-1`).
450
450
  4. On PostgreSQL, write the list of capabilities the extension's contract requires (`extension-contract-lists-required-capabilities`, its step 1). Do not run `prisma contract emit` yet.
451
451
  5. Bring the bundled files up to date: run the `stored-files-format-version` script, then the `contract-hash-inputs` script, then `prisma contract emit` once. That one emit also covers `extension-stored-contract-needs-the-upgrade-script`. If the emitted contract's storage hash differs from the one the script printed, follow `contract-hash-inputs` under "When the emitted contract gets a different storage hash". Then build, run the tests, sign each test database again (`extension-contract-lists-required-capabilities`, its step 4), and publish a new version with no new migration.
@@ -512,7 +512,7 @@ This guide's script rewrites each import of a removed path to the platform packa
512
512
 
513
513
  #### Where the guide and its script are
514
514
 
515
- 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:
515
+ 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-extension.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:
516
516
 
517
517
  ```text
518
518
  .agents/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
@@ -520,7 +520,7 @@ This guide is part of the `prisma-8` skill. The skill ships inside the database
520
520
 
521
521
  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.
522
522
 
523
- 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 package in it; a run in each package that imports Prisma works too.
523
+ 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 extension package, giving it the package's folder, as their sections say.
524
524
 
525
525
  #### Run the script
526
526
 
@@ -823,7 +823,14 @@ Commit your work first, so the script's changes can be reviewed and undone with
823
823
  node .agents/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 .
824
824
  ```
825
825
 
826
- 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.
826
+ 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:
827
+
828
+ - 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.
829
+ - 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.
830
+
831
+ 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.
832
+
833
+ It skips `node_modules`, `dist`, `build`, folders whose name starts with a dot, and, in a git repository, the files and folders git ignores.
827
834
 
828
835
  The script:
829
836
 
@@ -849,7 +856,7 @@ The script reads only source files. Rename the old names in your Markdown and ot
849
856
  - 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`.
850
857
  - 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.
851
858
  - 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.
852
- - A file that re-exports a renamed name under its old name. Rename the name where the project imports it, then drop the alias.
859
+ - A file that re-exports a renamed name under its old name. Rename the name where the project imports it, then drop the alias, unless the alias is part of the extension's published API: dropping it there breaks the extension's users, so keep it until a release that may break them. When the project re-exports Prisma's error from a module of its own, 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.
853
860
  - 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`.
854
861
  - 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.
855
862
 
@@ -911,7 +918,7 @@ Every other name that is no longer published was a part of how Prisma builds its
911
918
 
912
919
  #### Check the result
913
920
 
914
- Type-check and test the extension. 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.
921
+ Type-check and test the extension. 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 that is part of the extension's published API.
915
922
 
916
923
  ## `contract-types` exports types only
917
924
 
@@ -1037,7 +1044,7 @@ Commit your work first. Then run the script that sits beside this guide in the `
1037
1044
  node .agents/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 .
1038
1045
  ```
1039
1046
 
1040
- It is the same script as the application guide's. In a code file that imports a renamed name from an `@prisma/orm-*` package, it renames that import and the file's uses of it; a name the file re-exports keeps the name the file exports (`export { ContractSignatureRow as ContractMarkerRow }`), so your own users are not broken. An object that holds the import in shorthand keeps its key: `{ errorMarkerMissing }` becomes `{ errorMarkerMissing: errorSignatureMissing }`. In a file that imports from such a package, it renames each renamed member where the file reads it (`.readMarker`), writes it as a key (`markerLocation: …`), or declares it in a class, interface or object (`async readMarker(…) {`, `markerLocation = …`, `readMarker = async (…) => …`), and in a type that names it as a string (`Pick<SqlControlAdapter<'postgres'>, 'readMarker'>`, `SqlControlAdapter<'postgres'>['readMarker']`). A variable, parameter, function or export your code declares keeps its name. 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 also renames the path, the flag, the codes, the values and the `--json` fields, as the application guide says, prints each file it changed, and a second run changes nothing.
1047
+ It is the same script as the application guide's. In a code file that imports a renamed name from an `@prisma/orm-*` package, it renames that import and the file's uses of it; a name the file re-exports keeps the name the file exports (`export { ContractSignatureRow as ContractMarkerRow }`), so your own users are not broken. An object that holds the import in shorthand keeps its key: `{ errorMarkerMissing }` becomes `{ errorMarkerMissing: errorSignatureMissing }`. In a file that imports from such a package, it renames each renamed member where the file reads it (`.readMarker`), writes it as a key (`markerLocation: …`), or declares it in a class, interface or object (`async readMarker(…) {`, `markerLocation = …`, `readMarker = async (…) => …`), and in a type that names it as a string (`Pick<SqlControlAdapter<'postgres'>, 'readMarker'>`, `SqlControlAdapter<'postgres'>['readMarker']`). A variable, parameter, function or export your code declares keeps its name. 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, and when it needs TypeScript and finds only TypeScript 7, it changes no file and exits with code 1, as `platform-paths-an-extension-uses` does. It also renames the path, the flag, the codes, the values and the `--json` fields, as the application guide says, prints each file it changed, and a second run changes nothing. It skips the files and folders git ignores. 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 the sentence around it usually needs rewriting too, and a dated record, such as a changelog, 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 extension works now.
1041
1048
 
1042
1049
  ```ts
1043
1050
  // before
@@ -1075,6 +1082,7 @@ The script finds names by searching the text of your code. It uses TypeScript on
1075
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:]]*[=:)]' .
1076
1083
  ```
1077
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.
1078
1086
  - **Your target's own table and messages.** A target that stores signatures in a table of its own keeps its table name; rename only what the code calls it, if you want the code to match. Messages your target writes that say "marker" are yours to reword.
1079
1087
 
1080
1088
  The searches leave out the `upgrading` folder of the skill copy, whose guides name the old names.
@@ -1879,15 +1887,17 @@ Each file Prisma stores now says which version of its format it is in, so a late
1879
1887
  { "formatVersion": 1, "from": null, "to": "...", ... }
1880
1888
  ```
1881
1889
 
1882
- Commit your work first. Then run the script from the extension package's root:
1890
+ Commit your work first. Then run the script once for each extension package, from the folder that holds the skills copy, and give it the package's folder as its one argument, relative to where you run it; without one, it works on the working directory. For a package at the repository root, the argument is `.`; for one in `packages/extension-foo`:
1883
1891
 
1884
1892
  ```sh
1885
- node .agents/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
1893
+ node .agents/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 packages/extension-foo
1886
1894
  ```
1887
1895
 
1888
- 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/`.
1896
+ Do not give it a folder that holds more than the package, such as the root of a monorepo: it would also reach files that look like Prisma's but are not, such as test fixtures. 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.
1889
1897
 
1890
- Node 24 or later runs the TypeScript script directly. It reads and writes files only. It walks the package, skipping `node_modules`, `dist`, `build` and directories whose name starts with a dot. In every contract (any `*.json` file with `targetFamily`, `storage` and `schemaVersion` at the top level) it replaces `"schemaVersion": "1"` with `"formatVersion": 1`. In every `migration.json` that has an `ops.json` next to it, and every ref file under the package's `migrations/refs/` (or the migrations folder the package configures under another name; the script recognises a migrations folder by the contract snapshot store or the migrations in it, not by its name, and a ref in any other `refs` folder by its `hash` and `invariants`), it adds `"formatVersion": 1` as the first field. It keeps the rest of each file's bytes, prints each file it changed, and says so when nothing needed changing. A field a ref file does not have, which earlier releases ignored and dropped when they wrote the ref again, it drops and lists. It 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`, or a `contract.json` holding a contract with neither; a contract whose `schemaVersion` is not `"1"`. Outside a migrations folder it recognises, it leaves alone, without a report, any file in a `refs` folder without a ref's content (a `hash` that is `empty` or a 64-character storage hash, and an `invariants` list of strings). 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 correct it by hand, since no Prisma command writes the head ref in an extension's own package: its `hash` is the `storage.storageHash` of the contract the extension emits. It also reports a stored file whose `formatVersion` is not `1` and a snapshot's `contract.json` that is not a JSON object. It does not follow symbolic links. It ignores a link to the package folder or a folder above it, and a link to a folder inside the package that the walk enters or to a `.json` file in one, unless the walk would read the target as another kind of file than at the link, such as a ref in `migrations/refs/` that links to a file elsewhere; it reports such a link and exits 1. It reports a link to any other file or folder, outside the package or skipped by the walk, that holds a stored file it would change or report.
1898
+ 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-extension.md#step-0--read-the-newest-releases-skill) says.
1899
+
1900
+ Node 24 or later runs the TypeScript script directly. It reads and writes files only. 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. In every contract (any `*.json` file with `targetFamily`, `storage` and `schemaVersion` at the top level) it replaces `"schemaVersion": "1"` with `"formatVersion": 1`. In every `migration.json` that has an `ops.json` next to it, and every ref file under the package's `migrations/refs/` (or the migrations folder the package configures under another name; the script recognises a migrations folder by the contract snapshot store or the migrations in it, not by its name, and a ref in any other `refs` folder by its `hash` and `invariants`), it adds `"formatVersion": 1` as the first field. It keeps the rest of each file's bytes, prints each file it changed, and says so when nothing needed changing. A field a ref file does not have, which earlier releases ignored and dropped when they wrote the ref again, it drops and lists. It checks every file before it writes any. It changes no file, prints `Changed no file, because:` with what is wrong with each 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`, or a `contract.json` holding a contract with neither; a contract whose `schemaVersion` is not `"1"`. Outside a migrations folder it recognises, it leaves alone, without a report, any file in a `refs` folder without a ref's content (a `hash` that is `empty` or a 64-character storage hash, and an `invariants` list of strings). 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 correct it by hand, since no Prisma command writes the head ref in an extension's own package: its `hash` is the `storage.storageHash` of the contract the extension emits. It also reports a stored file whose `formatVersion` is not `1` and a snapshot's `contract.json` that is not a JSON object. It does not follow symbolic links. It ignores a link to the package folder or a folder above it, and a link to a folder inside the package that the walk enters or to a `.json` file in one, unless the walk would read the target as another kind of file than at the link, such as a ref in `migrations/refs/` that links to a file elsewhere; it reports such a link and exits 1. It reports a link to any other file or folder, outside the package or skipped by the walk, that holds a stored file it would change or report.
1891
1901
 
1892
1902
  No hash covers the format version: the storage hash, the head ref's hash, snapshot directory names and each `migrationHash` stay as they are. Then run the `contract-hash-inputs` script below, and only then `prisma contract emit`, which writes the new form of `contract.json`. Rebuild the package and publish it as those instructions say.
1893
1903
 
@@ -1982,17 +1992,21 @@ A contract has three hashes: the storage hash (`storage.storageHash`), the profi
1982
1992
 
1983
1993
  An extension's package carries these hashes: its emitted `src/contract.json` and `contract.d.ts`, `migrations/refs/head.json`, the `from`, `to` and `migrationHash` of each `migration.json` and any storage hash in its `ops.json`, the snapshots under `migrations/snapshots/<hash>/` and the `migration.ts` that import them. When an application loads the extension, this release recomputes the hash of the bundled contract and compares it with the head ref. An extension published for an earlier release therefore fails to load with `MIGRATION.DESCRIPTOR_HEAD_HASH_MISMATCH`, which names the extension.
1984
1994
 
1985
- 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, then run the script from the extension package's root:
1995
+ 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, then run the script from the folder that holds the skills copy:
1986
1996
 
1987
1997
  ```sh
1988
- node .agents/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
1998
+ node .agents/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 packages/extension-foo
1989
1999
  ```
1990
2000
 
1991
- 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/`.
2001
+ As with the format version script, run it once for each extension package and give it the package's folder, here `packages/extension-foo`, or `.` for a package at the repository root. The script checks every stored file below that 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, makes it change no file and exit with code 1; a lone contract file, such as a test fixture, is left alone, as the next paragraph says. It skips the files and folders git ignores, other than a migrations folder and what is in it.
2002
+
2003
+ 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-extension.md#step-0--read-the-newest-releases-skill) says.
2004
+
2005
+ Node 24 or later runs the TypeScript script directly. It reads and writes files only. It first checks that each stored storage hash, and each snapshot directory's name, is the hash the old rules or the new rules give the contract's content, and that each `migrationHash` matches its migration. If one does not, the file was edited by hand or comes from another release: the script 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 package, and exits 1. An intermediate contract, which a migration's `migration.ts` imports to type the queries of a data migration and which sits beside that `migration.ts`, `migration.json` and `ops.json`, is left alone the same way when its storage hash is one nothing names, but listed last under "Intermediate contracts, left as they are", and does not make the script exit 1; when it is all that is left, every run exits 0. Leave it as it is and do not set its hashes: only that `migration.ts` reads it, and it is not run again after this upgrade. A contract whose `execution.mutations.defaults` refs still have the keys `table` and `column`, which 8.0.0-rc.13 renamed to `entry` and `field`, is left alone like one with wrong hashes when it is not a snapshot and nothing names its storage hash: an intermediate contract is listed as one, and any other is listed under "Left unchanged:" and makes the script exit 1. A snapshot with such refs, or a contract something names, makes the script change no file and exit 1, listing the contract under "Changed no file, because:"; for one under `migrations/`, run the command the message gives from the package folder, which 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, `node <skill>/upgrading/extension/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/scripts/execution-ref-entry-field/rename-execution-ref-keys.ts`, or emit any other contract again, as that step says, and run this script again. Otherwise it rewrites every hash listed above, renames each snapshot directory to its new hash, and recomputes each `migrationHash`, keeping every other byte of each file. It also renames each contract's and snapshot's `capabilities` to `requiredCapabilities`, and the type of that list in each `contract.d.ts`: `sql.interactiveTransactions` becomes `conn.interactiveTransactions`, every other `sql.` and `postgres.` key becomes `db.`, and a PostgreSQL contract loses the nine keys the release candidates wrote that nothing reads, such as `postgres.jsonAgg`. A contract a development build wrote, with `requiredCapabilities` grouped by provider (`{ "db": { "returning": true } }`), gets the sorted list too, of the keys it sets to `true`; a contract already in the list form keeps it. This release refuses a contract that still has `capabilities`, and a snapshot cannot be emitted again, so the script is the only way to bring one to this release. It changes no file, names the contract and exits 1 when 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. Emit the contract again with `prisma contract emit` if Prisma writes it, or fix the file by hand, and run the script again. It does not follow symbolic links. It also changes no file at all, names the cause and exits 1 when a link leads to a file or folder that holds stored files and that the walk does not reach, inside the package where the walk skips or outside the package, or that the walk reaches but reads as another kind of file, such as a ref in `migrations/refs/` that links to a file elsewhere, or when a snapshot directory, or the `contract.json` in one, is itself a link, wherever it points, or a folder above it is a link to a place where the snapshot is not under a `snapshots` folder by the same hash, such as a `snapshots` folder linked to a folder with another name, since the script renames each snapshot directory to its new storage hash and through the link it would keep the old name, or when a link outside a snapshot directory points into one, such as a `contract.json` linked to a snapshot's, since after the rename the link would point at nothing, or when a snapshot whose storage hash changes cannot be rewritten without changing other content: migrations and refs would then name a snapshot directory that keeps its old name. Fix the file as the report says and run the script again. It prints what it changed; a second run changes nothing. If you ran `prisma contract emit` with this release before the script, and the contract source holds a value the earlier release left out, the emitted contract's storage hash differs from the new hash of the contract the earlier release wrote, which is the one your databases are at. The script gives every snapshot, migration and ref that named the old hash that new hash, whether or not a snapshot of the contract is left. It leaves the emitted contract as it is and lists it with both hashes, on every run; "When the emitted contract gets a different storage hash" below says what to do. 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.
1992
2006
 
1993
- Node 24 or later runs the TypeScript script directly. It reads and writes files only. It first checks that each stored storage hash, and each snapshot directory's name, is the hash the old rules or the new rules give the contract's content, and that each `migrationHash` matches its migration. If one does not, the file was edited by hand or comes from another release: the script 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 package, and exits 1. Otherwise it rewrites every hash listed above, renames each snapshot directory to its new hash, and recomputes each `migrationHash`, keeping every other byte of each file. It also renames each contract's and snapshot's `capabilities` to `requiredCapabilities`, and the type of that list in each `contract.d.ts`: `sql.interactiveTransactions` becomes `conn.interactiveTransactions`, every other `sql.` and `postgres.` key becomes `db.`, and a PostgreSQL contract loses the nine keys the release candidates wrote that nothing reads, such as `postgres.jsonAgg`. A contract a development build wrote, with `requiredCapabilities` grouped by provider (`{ "db": { "returning": true } }`), gets the sorted list too, of the keys it sets to `true`; a contract already in the list form keeps it. This release refuses a contract that still has `capabilities`, and a snapshot cannot be emitted again, so the script is the only way to bring one to this release. It changes no file, names the contract and exits 1 when 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. Emit the contract again with `prisma contract emit` if Prisma writes it, or fix the file by hand, and run the script again. It does not follow symbolic links. It also changes no file at all, names the cause and exits 1 when a link leads to a file or folder that holds stored files and that the walk does not reach, inside the package where the walk skips or outside the package, or that the walk reaches but reads as another kind of file, such as a ref in `migrations/refs/` that links to a file elsewhere, or when a snapshot directory, or the `contract.json` in one, is itself a link, wherever it points, or a folder above it is a link to a place where the snapshot is not under a `snapshots` folder by the same hash, such as a `snapshots` folder linked to a folder with another name, since the script renames each snapshot directory to its new storage hash and through the link it would keep the old name, or when a link outside a snapshot directory points into one, such as a `contract.json` linked to a snapshot's, since after the rename the link would point at nothing, or when a snapshot whose storage hash changes cannot be rewritten without changing other content: migrations and refs would then name a snapshot directory that keeps its old name. Fix the file as the report says and run the script again. It prints what it changed; a second run changes nothing. If you ran `prisma contract emit` with this release before the script, and the contract source holds a value the earlier release left out, the emitted contract's storage hash differs from the new hash of the contract the earlier release wrote, which is the one your databases are at. The script gives every snapshot, migration and ref that named the old hash that new hash, whether or not a snapshot of the contract is left. It leaves the emitted contract as it is and lists it with both hashes, on every run; "When the emitted contract gets a different storage hash" below says what to do. 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.
2007
+ Then run `prisma contract emit`, build the package and run its tests, and publish a new version. An application must upgrade the extension together with Prisma: an older version of the extension does not load in this release, and this version does not load in an earlier one.
1994
2008
 
1995
- Then build the package and run its tests, and publish a new version. An application must upgrade the extension together with Prisma: an older version of the extension does not load in this release, and this version does not load in an earlier one.
2009
+ Do not run again the `migration.ts` of a migration the extension already shipped. This release can write other checks into `ops.json` than the release that planned the migration, such as new prechecks and postchecks, so running one changes its `ops.json` and its `migrationHash`, and the migration is no longer the one applications have applied. The script changes those `migration.ts` files without running them, and the migration hash does not cover `migration.ts`. A CI check that runs each changed `migration.ts` and compares what it writes with the committed files fails on the upgrade's pull request for that reason; make an exception for that one pull request.
1996
2010
 
1997
2011
  Add no migration in this version: publish any new migration in a version for the release before, and leave this one with the migrations it already had. An application deploys every pending migration, its own and its extensions', before it upgrades, then upgrades Prisma and the extension in a release of its own, whose deploy runs `prisma db sign --no-advance-ref` (with `--force` where the database's change policy permits only migrations) and then `prisma db migrate` against each database that existed before it. The release assumes every database is at the newest contract of the application and of every extension: `db sign` signs the extension's space at the extension's head, whatever contract the application names, so a database must already be there. A migration first shipped in this version would not be in the database yet: signing would then fail, because the schema does not match, or, for a migration that only drops something or moves data, mark the space as up to date so the migration never runs. The application's guide gives these steps.
1998
2012
 
@@ -6,18 +6,21 @@
6
6
  *
7
7
  * Usage: node contract-hash-inputs.ts [project-root]
8
8
  *
9
- * The project root defaults to the working directory. The script reads and writes files only; it needs no database. It walks the root, skipping `node_modules`, `dist`, `build` and directories whose name starts with a dot, and finds stored files the way the `stored-files-format-version` script does: a contract by its content (`targetFamily` and `storage`) in any `*.json` file, a `migration.json` by the `ops.json` next to it, and a ref file by where Prisma writes refs or by its content.
9
+ * The project root defaults to the working directory. The script reads and writes files only; it needs no database. It walks the root, skipping `node_modules`, `dist`, `build`, directories whose name starts with a dot and, in a git repository, the files and folders git ignores, unless git ignores the root itself, except a migrations folder (one holding the contract snapshot store, a migration package or a ref file, directly or in a space folder) and what is in it, since nothing else writes those files again, and finds stored files the way the `stored-files-format-version` script does: a contract by its content (`targetFamily` and `storage`) in any `*.json` file, a `migration.json` by the `ops.json` next to it, and a ref file by where Prisma writes refs or by its content.
10
10
  *
11
11
  * First it checks every contract: each stored `storageHash`, `profileHash` and `executionHash`, and each snapshot directory's name, must be the hash the old rules or the new rules give the contract's content. Two exceptions: a snapshot's profile and execution hash may come from an earlier release's rules, and a MongoDB snapshot may keep the storage hash it had before an earlier upgrade step rewrote its content; both get the hashes their content gives. Then it checks each `migration.json` against its `migrationHash`, and that each `from`, `to` and ref `hash` names a contract of the project. If any check fails, it changes no file, prints one line per problem and exits 1. A hash that does not match the content means the file was edited by hand or comes from another release; fix that first.
12
12
  *
13
13
  * It reads a stored file whether or not it has a `formatVersion`, and leaves its format version as it is: a file a release candidate wrote keeps `"schemaVersion": "1"`, or no version field, and this release reads it as format version 0.
14
14
  *
15
- * A contract that is not a snapshot and whose storage hash no migration, ref or snapshot names, such as a hand-made test fixture, does not stop the upgrade when its hashes are wrong: it is reported, left unchanged, and makes the script exit 1.
15
+ * A contract that is not a snapshot and whose storage hash no migration, ref or snapshot names, such as a hand-made test fixture, does not stop the upgrade when its hashes are wrong: it is reported, left unchanged, and makes the script exit 1. An intermediate contract, one in a migration's directory beside its `migration.ts`, which reads it to type a data migration's queries, is the exception: when its hashes are wrong it is listed as an intermediate contract and left unchanged, and the script still exits 0, since that `migration.ts` is not run again after this upgrade.
16
+ *
17
+ * A contract whose `execution.mutations.defaults` refs still have the keys `table` and `column`, which 8.0.0-rc.13 renamed to `entry` and `field`, stops the run when it is a snapshot or something names its storage hash: the script changes no file and gives the command of the 8.0.0-rc.12 to 8.0.0-rc.13 step that renames them. Such a contract that nothing names is left alone like one with wrong hashes: an intermediate contract is listed as one, and any other is reported and makes the script exit 1.
16
18
  *
17
19
  * Otherwise it rewrites: the three hashes in every contract; the same hashes in the `contract.d.ts` beside it; each snapshot directory's name; `from`, `to` and `migrationHash` in every `migration.json`, and the storage hashes in the `ops.json` beside it; `hash` in every ref file; and every old storage hash in every `migration.ts` (snapshot import paths and hash literals). It edits each file's text, so every other byte stays, including a leading byte order mark, and replaces each file in one rename, so a run that stops partway can be run again to finish. It prints what it changed and each hash it replaced. A `contract.d.ts` whose hashes it cannot match with its contract, or a migration or ref naming a hash it cannot tell the new value of, is reported, left unchanged, and makes it exit 1. A second run changes nothing.
18
20
  *
19
21
  * The hash rules, old and new, the families' normal forms of storage and the migration hash rule are copied from Prisma's packages, because a project's strict `node_modules` does not expose them.
20
22
  */
23
+ import { spawnSync } from 'node:child_process';
21
24
  import { createHash } from 'node:crypto';
22
25
  import {
23
26
  chmodSync,
@@ -31,7 +34,8 @@ import {
31
34
  statSync,
32
35
  writeFileSync,
33
36
  } from 'node:fs';
34
- import { basename, dirname, join, relative, resolve, sep } from 'node:path';
37
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
38
+ import { fileURLToPath } from 'node:url';
35
39
 
36
40
  type Json = null | boolean | number | string | Json[] | JsonRecord;
37
41
  interface JsonRecord {
@@ -1145,6 +1149,79 @@ function isWalked(name: string): boolean {
1145
1149
  return !SKIPPED_DIRECTORIES.has(name) && !name.startsWith('.');
1146
1150
  }
1147
1151
 
1152
+ let ignoredByGit: (path: string) => boolean = () => false;
1153
+
1154
+ /** A test of whether git ignores a file or folder under `root`. Outside a git repository it ignores nothing, and so it does when git ignores `root` itself, which the user then named on purpose. */
1155
+ function gitIgnores(root: string): (path: string) => boolean {
1156
+ const listed = spawnSync(
1157
+ 'git',
1158
+ ['ls-files', '--others', '--ignored', '--exclude-standard', '--directory', '-z'],
1159
+ { cwd: root, encoding: 'utf8', maxBuffer: 2 ** 30 },
1160
+ );
1161
+ if (listed.status !== 0) return () => false;
1162
+ const ignored = new Set(
1163
+ listed.stdout
1164
+ .split('\0')
1165
+ .filter((path) => path !== '')
1166
+ .map((path) => path.replace(/\/$/, '')),
1167
+ );
1168
+ if (ignored.has('.')) return () => false;
1169
+ const bases = [root, realpathSync(root)];
1170
+ return (path) =>
1171
+ bases.some((base) => ignored.has(relative(base, path).split(sep).join('/'))) &&
1172
+ !isInMigrationsFolder(bases, path);
1173
+ }
1174
+
1175
+ function readsAsRef(path: string): boolean {
1176
+ try {
1177
+ const value: unknown = JSON.parse(readFileSync(path, 'utf8').replace(/^\uFEFF/, ''));
1178
+ return isRecord(value) && hasRefContent(value);
1179
+ } catch {
1180
+ return false;
1181
+ }
1182
+ }
1183
+
1184
+ /** Whether `dir` holds what Prisma writes to a migrations directory or to one of its spaces: the contract snapshot store, a migration package or a ref file. */
1185
+ function holdsMigrationFiles(dir: string): boolean {
1186
+ return isMigrationsDirectory(dir) || holdsRef(dir);
1187
+ }
1188
+
1189
+ function holdsRef(dir: string): boolean {
1190
+ const refs = join(dir, 'refs');
1191
+ const entries = listDirectory(refs);
1192
+ return (
1193
+ typeof entries !== 'string' &&
1194
+ entries.some((entry) => entry.isFile() && readsAsRef(join(refs, entry.name)))
1195
+ );
1196
+ }
1197
+
1198
+ /** Whether `dir` holds what Prisma writes to a space of a migrations directory: a migration package or a ref file. The snapshot store sits beside the spaces, never in one. */
1199
+ function holdsSpaceFiles(dir: string): boolean {
1200
+ return hasSubdirectory(dir, isMigrationPackage) || holdsRef(dir);
1201
+ }
1202
+
1203
+ function isMigrationsFolder(dir: string): boolean {
1204
+ return (
1205
+ holdsMigrationFiles(dir) ||
1206
+ hasSubdirectory(dir, (path, name) => SPACE_ID.test(name) && holdsSpaceFiles(path))
1207
+ );
1208
+ }
1209
+
1210
+ /** Whether `path`, or a folder it is in below the project root, is a migrations folder, whose files the script upgrades even when git ignores them: nothing else writes them again. */
1211
+ function isInMigrationsFolder(bases: readonly string[], path: string): boolean {
1212
+ for (let dir = path; !bases.includes(dir) && dir !== dirname(dir); dir = dirname(dir))
1213
+ if (isDirectory(dir) && isMigrationsFolder(dir)) return true;
1214
+ return false;
1215
+ }
1216
+
1217
+ /** Whether the walk from `realRoot` reaches `target`. */
1218
+ function isReached(realRoot: string, target: string): boolean {
1219
+ const names = relative(realRoot, target).split(sep);
1220
+ return names.every(
1221
+ (name, index) => isWalked(name) && !ignoredByGit(join(realRoot, ...names.slice(0, index + 1))),
1222
+ );
1223
+ }
1224
+
1148
1225
  function isInside(dir: string, path: string): boolean {
1149
1226
  return path === dir || path.startsWith(`${dir}${sep}`);
1150
1227
  }
@@ -1164,12 +1241,16 @@ function visit(
1164
1241
  for (const entry of entries) {
1165
1242
  const path = join(dir, entry.name);
1166
1243
  const shown = relative(root, path);
1167
- if (entry.isDirectory()) {
1168
- if (entry.name.startsWith('.') && entry.name.endsWith(REMOVED_SUFFIX))
1169
- files.leftovers.push(path);
1170
- else if (isWalked(entry.name)) visit(root, path, files, stops, checkLinks);
1171
- } else if (entry.isFile() && entry.name.endsWith(TEMPORARY_SUFFIX)) {
1244
+ const isLeftover = entry.isDirectory()
1245
+ ? entry.name.startsWith('.') && entry.name.endsWith(REMOVED_SUFFIX)
1246
+ : entry.isFile() && entry.name.endsWith(TEMPORARY_SUFFIX);
1247
+ if (isLeftover) {
1172
1248
  files.leftovers.push(path);
1249
+ continue;
1250
+ }
1251
+ if (ignoredByGit(path)) continue;
1252
+ if (entry.isDirectory()) {
1253
+ if (isWalked(entry.name)) visit(root, path, files, stops, checkLinks);
1173
1254
  } else if (entry.isFile() && entry.name.endsWith('.json')) {
1174
1255
  classify(root, path, files, stops, shown);
1175
1256
  } else if (entry.isFile() && entry.name === 'migration.ts' && isMigrationPackage(dir)) {
@@ -1196,9 +1277,7 @@ function checkLink(root: string, path: string, name: string, stops: string[]): v
1196
1277
  }
1197
1278
  if (isInside(target, realRoot)) return;
1198
1279
  const inside = isInside(realRoot, target);
1199
- const reached =
1200
- relative(realRoot, target).split(sep).every(isWalked) &&
1201
- (isDirectory(target) || target.endsWith('.json'));
1280
+ const reached = isReached(realRoot, target) && (isDirectory(target) || target.endsWith('.json'));
1202
1281
  const intoSnapshot = inside && isInSnapshotDirectory(realRoot, target);
1203
1282
  const reading = inside && reached ? linkReading(root, path, realRoot, target, name) : undefined;
1204
1283
  if (reading === 'snapshot') {
@@ -1405,20 +1484,81 @@ function hashList(hashes: HashSet): string {
1405
1484
  }
1406
1485
 
1407
1486
  interface ContractChecks {
1487
+ /** The project root the script upgrades. */
1488
+ readonly root: string;
1408
1489
  readonly stops: string[];
1409
1490
  /** Contracts the script leaves unchanged and reports, without refusing the project. */
1410
1491
  readonly left: string[];
1411
1492
  /** Snapshots whose profile or execution hash an earlier release wrote by other rules. */
1412
1493
  readonly notes: string[];
1494
+ /** Stale intermediate contracts the script leaves unchanged without counting them as problems. */
1495
+ readonly intermediate: string[];
1413
1496
  /** Every storage hash a migration, ref or snapshot names. */
1414
1497
  readonly named: ReadonlySet<string>;
1415
1498
  }
1416
1499
 
1500
+ function oldExecutionRefs(value: JsonRecord): readonly string[] {
1501
+ const execution = value['execution'];
1502
+ const mutations = isRecord(execution) ? execution['mutations'] : undefined;
1503
+ const defaults = isRecord(mutations) ? mutations['defaults'] : undefined;
1504
+ if (!Array.isArray(defaults)) return [];
1505
+ return defaults.flatMap((entry) => {
1506
+ const ref = isRecord(entry) ? entry['ref'] : undefined;
1507
+ if (!isRecord(ref) || !('table' in ref || 'column' in ref)) return [];
1508
+ return [`${String(ref['table'])}.${String(ref['column'])}`];
1509
+ });
1510
+ }
1511
+
1512
+ function isIntermediateContract(path: string): boolean {
1513
+ const dir = dirname(path);
1514
+ return isMigrationPackage(dir) && existsSync(join(dir, 'migration.ts'));
1515
+ }
1516
+
1517
+ /** The `node` command that runs the 8.0.0-rc.12 to 8.0.0-rc.13 script of this skill copy from `root`: relative to `root` when the copy is inside it. */
1518
+ function renameExecutionRefKeysCommand(root: string): string {
1519
+ const upgrades = resolve(dirname(fileURLToPath(import.meta.url)), '../../..');
1520
+ const script = join(
1521
+ upgrades,
1522
+ '8.0.0-rc.12-to-8.0.0-rc.13/scripts/execution-ref-entry-field/rename-execution-ref-keys.ts',
1523
+ );
1524
+ const fromRoot = relative(realpathSync(root), script);
1525
+ const path = fromRoot.startsWith('..') || isAbsolute(fromRoot) ? script : fromRoot;
1526
+ return `node ${path.split(sep).join('/')}`;
1527
+ }
1528
+
1529
+ function planOldExecutionRefs(
1530
+ file: StoredText,
1531
+ shown: string,
1532
+ oldRefs: readonly string[],
1533
+ checks: ContractChecks,
1534
+ ): void {
1535
+ const refs = `its execution.mutations.defaults refs name "table" and "column" (${oldRefs.join(', ')}), the keys from before 8.0.0-rc.13, which "entry" and "field" replaced`;
1536
+ const storage = storedHashes(file.value).storage;
1537
+ const isNamed = typeof storage === 'string' && checks.named.has(storage);
1538
+ if (snapshotDirectoryHash(file.path) === undefined && !isNamed) {
1539
+ if (isIntermediateContract(file.path)) checks.intermediate.push(shown);
1540
+ else
1541
+ checks.left.push(
1542
+ `${shown}: ${refs}. It is not a snapshot, and no migration, ref or snapshot names its hashes, so the script leaves it alone. If Prisma emits it, emit it again with \`prisma contract emit\`; otherwise rename those keys to "entry" and "field"`,
1543
+ );
1544
+ return;
1545
+ }
1546
+ const remedy = shown.split('/').includes('migrations')
1547
+ ? `Run the script of the 8.0.0-rc.12 to 8.0.0-rc.13 step \`execution-ref-entry-field\`, which renames the keys in every contract under a \`migrations\` folder, from the project root: \`${renameExecutionRefKeysCommand(checks.root)}\`. Then run this script again`
1548
+ : 'Emit it again with `prisma contract emit`, as the 8.0.0-rc.12 to 8.0.0-rc.13 step `execution-ref-entry-field` says, then run this script again';
1549
+ checks.stops.push(`${shown}: ${refs}. ${remedy}`);
1550
+ }
1551
+
1417
1552
  function planContract(
1418
1553
  file: StoredText,
1419
1554
  shown: string,
1420
1555
  checks: ContractChecks,
1421
1556
  ): ContractPlan | undefined {
1557
+ const oldRefs = oldExecutionRefs(file.value);
1558
+ if (oldRefs.length > 0) {
1559
+ planOldExecutionRefs(file, shown, oldRefs, checks);
1560
+ return undefined;
1561
+ }
1422
1562
  const sections = sectionsOf(file.value);
1423
1563
  if (typeof sections === 'string') {
1424
1564
  checks.stops.push(`${shown}: ${sections}`);
@@ -1463,7 +1603,9 @@ function planContract(
1463
1603
  );
1464
1604
  if (problems.length > 0) {
1465
1605
  const isNamed = typeof stored.storage === 'string' && checks.named.has(stored.storage);
1466
- if (snapshotHash === undefined && !isNamed)
1606
+ if (snapshotHash === undefined && !isNamed && isIntermediateContract(file.path))
1607
+ checks.intermediate.push(shown);
1608
+ else if (snapshotHash === undefined && !isNamed)
1467
1609
  checks.left.push(
1468
1610
  `${shown}: ${problems.join('; ')}. It is not a snapshot, and no migration, ref or snapshot names its hashes, so the script leaves it alone. If Prisma emits it, emit it again with \`prisma contract emit\`; otherwise set its ${hashList(newHashes)}, the hashes its content gives`,
1469
1611
  );
@@ -1653,6 +1795,7 @@ interface Plan {
1653
1795
  readonly superseded: string[];
1654
1796
  /** Contracts whose capabilities the script writes as the list of keys `requiredCapabilities`. */
1655
1797
  readonly renamedCapabilities: string[];
1798
+ readonly intermediate: readonly string[];
1656
1799
  readonly problems: string[];
1657
1800
  }
1658
1801
 
@@ -1666,6 +1809,7 @@ function main(args: readonly string[]): number {
1666
1809
  process.stderr.write(`${root}: not a directory\n`);
1667
1810
  return 1;
1668
1811
  }
1812
+ ignoredByGit = gitIgnores(root);
1669
1813
  const shown = (path: string) => relative(root, path).split(sep).join('/');
1670
1814
  const files = emptyFiles();
1671
1815
  const stops: string[] = [];
@@ -1674,9 +1818,11 @@ function main(args: readonly string[]): number {
1674
1818
 
1675
1819
  const contracts: ContractPlan[] = [];
1676
1820
  const checks: ContractChecks = {
1821
+ root,
1677
1822
  stops,
1678
1823
  left: [...files.unversioned],
1679
1824
  notes: [],
1825
+ intermediate: [],
1680
1826
  named: namedHashes(files),
1681
1827
  };
1682
1828
  for (const file of files.contracts) {
@@ -1720,6 +1866,7 @@ function main(args: readonly string[]): number {
1720
1866
  merged: [],
1721
1867
  superseded: [],
1722
1868
  renamedCapabilities: [],
1869
+ intermediate: checks.intermediate,
1723
1870
  problems: checks.left,
1724
1871
  };
1725
1872
  const alreadyNew = unknownHashesAlreadyNew(files.migrations, hashes);
@@ -2042,6 +2189,11 @@ function report(
2042
2189
  'Snapshot directories whose new name already held a snapshot with the same storage hash, which `prisma contract emit` wrote with this release. The script kept that snapshot unchanged and removed the old directory:',
2043
2190
  ...plan.superseded.map((note) => ` ${note}`),
2044
2191
  );
2192
+ if (plan.intermediate.length > 0)
2193
+ lines.push(
2194
+ 'Intermediate contracts, left as they are. Each sits beside the `migration.ts` of a data migration, which reads it to type its queries. Their hashes are not the ones their content gives, or their execution default refs have the keys from before 8.0.0-rc.13, but only that `migration.ts` reads them, and it is not run again after this upgrade, so the script does not change them:',
2195
+ ...[...plan.intermediate].sort(compareCodeUnits).map((path) => ` ${path}`),
2196
+ );
2045
2197
  process.stdout.write(`${lines.join('\n')}\n`);
2046
2198
  }
2047
2199