@prisma/orm-mongo 8.0.1-dev.41 → 8.0.1-dev.43
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.
- package/dist/{mongo-static-D3ow-Rl0-BeXA3Gno.mjs → mongo-static-D0gxIAFR-D4Ugp6Ri.mjs} +3 -3
- package/dist/{mongo-static-D3ow-Rl0-BeXA3Gno.mjs.map → mongo-static-D0gxIAFR-D4Ugp6Ri.mjs.map} +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/runtime.mjs.map +1 -1
- package/dist/static.mjs +1 -1
- package/package.json +12 -12
- package/skills/prisma-8/SKILL.md +1 -1
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/instructions.md +2385 -0
- 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 +2048 -0
- 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 +667 -0
- 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 +667 -0
- 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 +1996 -0
- 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 +586 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/instructions.md +2043 -0
- 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 +2048 -0
- 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 +667 -0
- 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 +667 -0
- 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 +1996 -0
- 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 +586 -0
|
@@ -0,0 +1,2385 @@
|
|
|
1
|
+
---
|
|
2
|
+
from: "8.0.0-rc.25"
|
|
3
|
+
to: "8.0.0-rc.26"
|
|
4
|
+
changes:
|
|
5
|
+
- id: list-the-platform-packages
|
|
6
|
+
summary: |
|
|
7
|
+
The database package (`@prisma/orm-postgres`, `@prisma/orm-sqlite`, `@prisma/orm-mysql`, `@prisma/orm-mariadb` or `@prisma/orm-mongo`) and every extension now name the Prisma packages they are built on, the platform packages, as peer dependencies instead of bringing them along. List each of them in the application's `package.json`, at the same version as the database package. Nothing in application code changes.
|
|
8
|
+
detection:
|
|
9
|
+
glob: "**/package.json"
|
|
10
|
+
matches:
|
|
11
|
+
- '"@prisma/orm-(?:postgres|sqlite|mysql|mariadb|mongo)"\s*:'
|
|
12
|
+
- id: config-imports-prisma-config
|
|
13
|
+
summary: |
|
|
14
|
+
`prisma.config.ts` imports `definePrismaConfig` from `prisma/config`, and the application no longer lists `@prisma/cli-engine`, so the config is made by the engine the `prisma` command runs and no line of the application's own can name another version.
|
|
15
|
+
detection:
|
|
16
|
+
glob: "**/{prisma.config.ts,prisma.config.mts,prisma.config.cts,prisma.config.js,prisma.config.mjs,prisma.config.cjs,package.json}"
|
|
17
|
+
matches:
|
|
18
|
+
- "(['\"])@prisma/cli-engine\\1"
|
|
19
|
+
- id: facade-paths-an-application-uses
|
|
20
|
+
summary: |
|
|
21
|
+
The database packages (`@prisma/orm-postgres`, `@prisma/orm-sqlite`, `@prisma/orm-mysql`, `@prisma/orm-mariadb` and `@prisma/orm-mongo`) now publish only the paths an application, a generated file or the documentation imports. The paths they forwarded from the platform packages and no application needs are removed: every `utils` and `driver` path, every `relational-core` path but `relational-core/ast`, the `control` path of the adapter, driver and target, and most of the `adapter`, `target`, `components`, `contract`, `family-contract` and `family` paths. Each removed module is still published by a platform package, under that package's own name. Run this guide's colocated script: it changes each such import to the platform package's path; on PostgreSQL and MongoDB, an import of the default alone from `target/pack` or `family/pack` to the database package's own `target` or `family`; and an import of `param` alone or `isStructuredError` alone to the database package's `runtime`.
|
|
22
|
+
detection:
|
|
23
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx}"
|
|
24
|
+
matches:
|
|
25
|
+
- "['\"`]@prisma/orm-(postgres|sqlite|mysql|mariadb|mongo)/(utils|driver)(/[A-Za-z0-9_./-]*)?['\"`]"
|
|
26
|
+
- "['\"`]@prisma/orm-(postgres|sqlite|mysql|mariadb|mongo)/(adapter|builder|components|contract|relational-core|query-ast)['\"`]"
|
|
27
|
+
- "['\"`]@prisma/orm-(postgres|sqlite|mysql|mariadb)/family-contract['\"`]"
|
|
28
|
+
- "['\"`]@prisma/orm-(postgres|sqlite|mysql|mariadb|mongo)/(builder/(?!runtime['\"`]|types['\"`])|components/(?!runtime['\"`])|contract/(?!types['\"`])|family-contract/(?!types['\"`])|family/(?!control['\"`])|relational-core/(?!ast['\"`])|migration-tools/(?!aggregate['\"`]|hash['\"`]|io['\"`]|spaces['\"`])|query-ast/(?!execution['\"`])|query-builder/|schema-ir/|value/)"
|
|
29
|
+
- "['\"`]@prisma/orm-postgres/adapter/(?!column-types['\"`])"
|
|
30
|
+
- "['\"`]@prisma/orm-sqlite/adapter/(?!codec-types['\"`]|column-types['\"`])"
|
|
31
|
+
- "['\"`]@prisma/orm-(mysql|mariadb)/adapter/(?!codec-types['\"`])"
|
|
32
|
+
- "['\"`]@prisma/orm-mongo/adapter/"
|
|
33
|
+
- "['\"`]@prisma/orm-postgres/target/(?!codec-ids['\"`]|codec-types['\"`]|full-text['\"`]|migration['\"`]|operation-types['\"`]|planner-target-details['\"`]|runtime['\"`])"
|
|
34
|
+
- "['\"`]@prisma/orm-sqlite/target/(?!codec-ids['\"`]|codec-types['\"`]|migration['\"`]|planner-target-details['\"`]|runtime['\"`])"
|
|
35
|
+
- "['\"`]@prisma/orm-(mysql|mongo)/target/(?!codec-ids['\"`]|codec-types['\"`]|migration['\"`]|runtime['\"`])"
|
|
36
|
+
- "['\"`]@prisma/orm-mariadb/target/(?!migration['\"`]|runtime['\"`])"
|
|
37
|
+
script: ./scripts/facade-paths-an-application-uses/facade-paths-an-application-uses.ts
|
|
38
|
+
- id: platform-paths-an-extension-uses
|
|
39
|
+
summary: |
|
|
40
|
+
The platform packages (`@prisma/orm-framework`, `@prisma/orm-family-sql`, `@prisma/orm-target-postgres` and `@prisma/orm-toolchain`) no longer publish 57 of the paths release 8.0.0-rc.25 published, the ones nothing outside their own package imported, among them the package-level paths `@prisma/orm-target-postgres/target` and `/adapter`, `@prisma/orm-framework/utils` and `@prisma/orm-family-sql/family`. `@prisma/orm-family-sql/contract` and `@prisma/orm-toolchain/migration-tools` stay, with fewer names. `@prisma/orm-framework/utils/internal-error` is now `utils/invariant-error`, and the exported names that contained "internal" have new names: `InternalError` is `InvariantError`, `isInternalError` is `isInvariantError`, `PreparedStatementInternals` is `LoweredPreparedStatement`, `SqlParamRefMutatorInternal` is `SqlRuntimeParamRefMutator`, `MongoParamRefMutatorInternal` is `MongoRuntimeParamRefMutator`, `SupabaseInternalDb` is `SupabaseSchemasDb`, and `SupabaseExtensionContract` is `SupabaseSchemasContract`. Most names of the removed paths are no longer published anywhere. Run the `facade-paths-an-application-uses` script first, then this guide's colocated script, which sends each import whose names a kept path still exports to that path, renames the old names where they came from a Prisma import, and lists what it could not change. Then rewrite what it lists, as the guide says.
|
|
41
|
+
detection:
|
|
42
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx}"
|
|
43
|
+
matches:
|
|
44
|
+
- "['\"`]@prisma/orm-framework/(?:contract/resolve-domain-model|psl-parser/tokenizer|target-package-config|type-implementations|utils|utils/internal-error)['\"`]"
|
|
45
|
+
- "['\"`]@prisma/orm-family-sql/(?:builder|contract-emitter|contract-psl|contract-psl/attribute-specs|contract-psl/default-table-name|contract-psl/diagnostics|contract-ts|contract/authored-check-naming|contract/factories|contract/index-type-validation|contract/validators|family|relational-core/functions|relational-core/middleware|schema-ir)['\"`]"
|
|
46
|
+
- "['\"`]@prisma/orm-target-postgres/(?:adapter|adapter/sql-renderer|adapter/types|target|target/aggregates|target/contract-free|target/data-transform|target/ddl|target/default-normalizer|target/diff-database-schema|target/errors|target/issue-planner|target/marker-lock|target/native-type-normalizer|target/op-factory-call|target/planner|target/planner-ddl-builders|target/planner-identity-values|target/planner-produced-postgres-migration|target/planner-schema-lookup|target/planner-sql-checks|target/render-ops|target/render-typescript|target/schema-ir-annotations)['\"`]"
|
|
47
|
+
- "['\"`]@prisma/orm-toolchain/(?:cli-telemetry|cli-telemetry/sender|cli/control-api/testing|cli/init-output|emitter|emitter/type-expression-safety|migration-tools/constants|migration-tools/contract-snapshot-store|migration-tools/errors|migration-tools/graph|migration-tools/metadata|migration-tools/migration-graph|migration-tools/ref-resolution)['\"`]"
|
|
48
|
+
- "(?<![\\w$])(?:InternalError|isInternalError|PreparedStatementInternals|SqlParamRefMutatorInternal|MongoParamRefMutatorInternal|SupabaseInternalDb|SupabaseExtensionContract|isPrismaInternalError)(?![\\w$])"
|
|
49
|
+
- "\\.name\\s*[!=]==?\\s*['\"`]InternalError['\"`]"
|
|
50
|
+
- "case\\s*['\"`]InternalError['\"`]"
|
|
51
|
+
- "['\"`]@prisma/orm-(?:family-sql/contract|toolchain/migration-tools)['\"`]"
|
|
52
|
+
script: ./scripts/platform-paths-an-extension-uses/platform-paths-an-extension-uses.ts
|
|
53
|
+
- id: contract-types-exports-types-only
|
|
54
|
+
summary: |
|
|
55
|
+
The `contract-types` entry of `@prisma/orm-postgres`, `@prisma/orm-sqlite`, `@prisma/orm-mysql`, `@prisma/orm-mariadb` and `@prisma/orm-mongo` now declares types only, as it always exported at run time. Its declarations used to list runtime values, such as `coreHash`, that it never exported, so importing one compiled and then failed when the module loaded. Such an import now fails to compile with TS1362 or TS1361. Import the type with `import type`, or import the value from the path of the same package that exports it: `contract/types` or `family-contract/types` (`family-contract` on MongoDB). Imports of types do not change, and neither do generated `contract.d.ts` files.
|
|
56
|
+
detection:
|
|
57
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs}"
|
|
58
|
+
matches:
|
|
59
|
+
- '@prisma/orm-(?:postgres|sqlite|mysql|mariadb|mongo)/contract-types[''"]'
|
|
60
|
+
- id: contract-signature-flag
|
|
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.
|
|
63
|
+
detection:
|
|
64
|
+
glob: "**/*"
|
|
65
|
+
matches:
|
|
66
|
+
- '(?<![\w-])--marker-only(?![\w-])'
|
|
67
|
+
script: ./scripts/contract-signature-names/contract-signature-names.ts
|
|
68
|
+
- id: contract-signature-error-codes
|
|
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.
|
|
71
|
+
detection:
|
|
72
|
+
glob: "**/*"
|
|
73
|
+
matches:
|
|
74
|
+
- '(?<![\w.])(?:CONTRACT|MIGRATION)\.MARKER_[A-Z_]+'
|
|
75
|
+
- 'CONFIG\.FAMILY_READ_MARKER_REQUIRED'
|
|
76
|
+
script: ./scripts/contract-signature-names/contract-signature-names.ts
|
|
77
|
+
- id: contract-signature-json-fields
|
|
78
|
+
summary: |
|
|
79
|
+
In `--json` output the field `marker` is now `signature` (in `db verify`, `db init`, `db update` and each `perSpace` entry of `db init`, `db update` and `db migrate`), `markerHash` of `db migrate` is `signatureHash`, and the `db verify` mode `marker-only` is `signature-only`. The error values `orphanMarker` and `markerChanged` are `orphanSignature` and `signatureChanged`, and the scope of the client's warnings about the contract signature, `marker-verification`, is `contract-signature-verification`. The script renames them where it can tell they are Prisma's; the guide says how to find the rest.
|
|
80
|
+
detection:
|
|
81
|
+
glob: "**/*"
|
|
82
|
+
matches:
|
|
83
|
+
- '--json[\s\S]*\.marker(?:Hash)?(?![\w$])'
|
|
84
|
+
- '--json[\s\S]*\{[^{}]*(?<![\w$.])marker(?:Hash)?(?![\w$])[^{}]*\}\s*=(?![=>])'
|
|
85
|
+
- '\bdb\s+(?:verify|init|update|migrate)\b[^\n]*--json[^\n]*\.marker'
|
|
86
|
+
- "['\"`](?:orphanMarker|markerChanged|marker-only|marker-verification)['\"`]"
|
|
87
|
+
script: ./scripts/contract-signature-names/contract-signature-names.ts
|
|
88
|
+
- id: contract-signature-published-names
|
|
89
|
+
summary: |
|
|
90
|
+
The names Prisma's packages published with Marker in them say Signature, such as `readMarker`, now `readSignature`, and the client option `verifyMarker`, now `verifyContractSignature`; a type that stands alone in an import says `ContractSignature`, such as `MarkerReadResult`, now `ContractSignatureReadResult`; the outcome of signing a space, `SpaceSignature`, is `SpaceSignOutcome`. The path `@prisma/orm-target-mysql/target/marker-lock` is `@prisma/orm-target-mysql/target/signature-lock`. The script renames a name where a file imports it from an `@prisma/orm-*` package, and a renamed option or method where such a file passes, calls or declares it.
|
|
91
|
+
detection:
|
|
92
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx}"
|
|
93
|
+
matches:
|
|
94
|
+
- '(?<![\w$])(?:buildSignMarkerBootstrapQueries|MARKER_LOCK_TIMEOUT_SECONDS|withMarkerReadErrorHandling|VERIFY_CODE_MARKER_MISSING|VERIFY_CODE_HASH_MISMATCH|ContractMarkerRecordLike|SpaceMarkerHashConflict|parseContractMarkerRow|rethrowMarkerReadError|errorMarkerReadFailed|errorMarkerRowCorrupt|ContractMarkerRecord|contractHashAtMarker|parseMarkerRowSafely|SpaceMarkerConflict|MarkerCheckSection|VerifyMarkerOption|errorMarkerMissing|ContractMarkerRow|MarkerCheckResult|MarkerDestination|MarkerSwapFailure|SpaceMarkerRecord|acquireMarkerLock|errorHashMismatch|markerSwapFailure|releaseMarkerLock|MarkerOperations|MarkerReadResult|sameMarkerHashes|SpaceSignature|withMarkerLock|MarkerHashes|MarkerInsert|MarkerReader)(?![\w$])[^;]*?\bfrom\s*[''"]@prisma/orm-'
|
|
95
|
+
- '@prisma/orm-[\s\S]*(?:\.\s*(?:bootstrapSignMarkerQueries|databaseMarkerHashBySpace|currentMarkerStorageHash|currentMarkerInvariants|readMarkerDiscriminated|currentMarkerHash|markerRowsBySpace|markerInvariants|markersBySpaceId|holdMarkerLock|markerLocation|readAllMarkers|currentMarker|orphanMarkers|insertMarker|markerReader|updateMarker|verifyMarker|markerCheck|markerDrift|initMarker|lockMarker|markerHash|readMarker|skipMarker|markerOps)(?![\w$])|(?:(?<!\$)\{|[,;])\s*(?:(?:readonly|async|public|private|protected|static|override)\s+)*(?:bootstrapSignMarkerQueries|databaseMarkerHashBySpace|currentMarkerStorageHash|currentMarkerInvariants|readMarkerDiscriminated|currentMarkerHash|markerRowsBySpace|markerInvariants|markersBySpaceId|holdMarkerLock|markerLocation|readAllMarkers|currentMarker|orphanMarkers|insertMarker|markerReader|updateMarker|verifyMarker|markerCheck|markerDrift|initMarker|lockMarker|markerHash|readMarker|skipMarker|markerOps)\s*\??\s*[:(]|\breadonly\s+(?:bootstrapSignMarkerQueries|databaseMarkerHashBySpace|currentMarkerStorageHash|currentMarkerInvariants|readMarkerDiscriminated|currentMarkerHash|markerRowsBySpace|markerInvariants|markersBySpaceId|holdMarkerLock|markerLocation|readAllMarkers|currentMarker|orphanMarkers|insertMarker|markerReader|updateMarker|verifyMarker|markerCheck|markerDrift|initMarker|lockMarker|markerHash|readMarker|skipMarker|markerOps)\s*=)'
|
|
96
|
+
- '@prisma/orm-target-mysql/target/marker-lock'
|
|
97
|
+
script: ./scripts/contract-signature-names/contract-signature-names.ts
|
|
98
|
+
- id: code-reads-required-capabilities
|
|
99
|
+
summary: |
|
|
100
|
+
A contract of every database, MongoDB included, stores what it requires as `requiredCapabilities` in place of `capabilities`, with each key prefixed by who provides it: `conn.interactiveTransactions` for the connection, and `db.` for every other key. Code that reads `contract.capabilities` reads `contract.requiredCapabilities`: the list is sorted capability keys, so `contract.capabilities.sql.returning` becomes `contract.requiredCapabilities.includes('db.returning')`, and `contract.capabilities.postgres.distinctOn` becomes `contract.requiredCapabilities.includes('db.distinctOn')`. A contract built by hand, such as one in a test, renames its field and keys the same way. `mysqlAdapterCapabilities`, `mariadbAdapterCapabilities` and `sqliteAdapterCapabilities` are lists of keys too, such as `['conn.interactiveTransactions', 'db.enums', …]`.
|
|
101
|
+
detection:
|
|
102
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx}"
|
|
103
|
+
matches:
|
|
104
|
+
- '\bcontract\s*(?:\?\.|\.)\s*capabilities\b'
|
|
105
|
+
- '\.capabilities\s*(?:\?\.|\.)\s*(?:sql|postgres)\b|\.capabilities\s*(?:\?\.)?\[\s*[''"](?:sql|postgres)\b'
|
|
106
|
+
- '\bcapabilities[''"]?\s*:\s*\{\s*[''"]?(?:sql|postgres)[''"]?\s*:'
|
|
107
|
+
- '\b(?:mysql|mariadb|sqlite)AdapterCapabilities\s*(?:\?\.|\.)\s*sql\b'
|
|
108
|
+
- 'Object\.(?:entries|keys|values)\(\s*[\w.?]*\.(?:required)?[cC]apabilities\b'
|
|
109
|
+
- id: stored-contract-needs-the-upgrade-script
|
|
110
|
+
summary: |
|
|
111
|
+
This release refuses to read a `contract.json` that a release candidate wrote, for every database, with `CONTRACT.VALIDATION_FAILED`, because it stores `capabilities`. A migration snapshot a release candidate wrote is refused before that, with `MIGRATION.CONTRACT_SNAPSHOT_CONTENT_MISMATCH`, because its storage hash was computed by the old hash rules. Run the `contract-hash-inputs` script of this release, which rewrites both, and then `prisma contract emit`, as the `contract-hash-inputs` instructions say. For PostgreSQL, see also `postgres-emitted-contract-is-emitted-again`.
|
|
112
|
+
detection:
|
|
113
|
+
glob: "**/contract.json"
|
|
114
|
+
matches:
|
|
115
|
+
- '(?<![\s\S])(?![\s\S]*"requiredCapabilities")(?![\s\S]*"target"\s*:\s*"postgres")(?=[\s\S]*"targetFamily")[\s\S]*"capabilities"\s*:'
|
|
116
|
+
- id: required-capabilities-as-list
|
|
117
|
+
summary: |
|
|
118
|
+
A contract stores its required capabilities as a sorted list of keys, such as `["conn.interactiveTransactions", "db.returning"]`, not as maps grouped by prefix. Code that read `requiredCapabilities.db.returning` checks `requiredCapabilities.includes('db.returning')`. `postgresRequiredCapabilities` and its type `PostgresRequiredCapabilities` are removed: the source options take the list the author writes.
|
|
119
|
+
detection:
|
|
120
|
+
glob: "**/*.{ts,tsx,mts,cts,js,mjs,cjs}"
|
|
121
|
+
matches:
|
|
122
|
+
- 'requiredCapabilities\??\.(db|conn)\b'
|
|
123
|
+
- 'requiredCapabilities(\?\.)?\[\s*[''"](db|conn)[''"]'
|
|
124
|
+
- '\b[Pp]ostgresRequiredCapabilities\b'
|
|
125
|
+
- 'Object\.(?:entries|keys|values)\(\s*[\w.?]*\.(?:required)?[cC]apabilities\b'
|
|
126
|
+
- id: stored-required-capabilities-as-list
|
|
127
|
+
summary: |
|
|
128
|
+
This release refuses a `contract.json` or migration snapshot whose `requiredCapabilities` is grouped by prefix, as a development build wrote it, with `CONTRACT.VALIDATION_FAILED`. The `contract-hash-inputs` script of this release, which every project runs, rewrites it to the sorted list of keys and computes its profile hash again; then each database is signed as the `contract-hash-inputs` instructions say. A contract already in the list form keeps its profile hash.
|
|
129
|
+
- id: postgres-contract-lists-required-capabilities
|
|
130
|
+
summary: |
|
|
131
|
+
A PostgreSQL contract now lists every capability it requires, where the contract is written: `defineContract({ requiredCapabilities: [...postgres18, ...postgresDriver], ... })`, the config's contract entry `{ path: './prisma/contract.prisma', requiredCapabilities: [...postgres18, ...postgresDriver] }`, or `prisma7Schema(path, { requiredCapabilities: [...postgres18, ...postgresDriver] })`. Each key names who provides it: `db.` for the database, such as `db.returning`, and `conn.` for the connection, such as `conn.interactiveTransactions`. `postgres15` to `postgres18` list what each PostgreSQL version provides, and `postgresDriver` what the driver's connection provides; import them beside `defineContract` or `defineConfig`. A contract without the list still works: it requires the newest version's list and the driver's, and `prisma contract emit` warns with `CONTRACT.REQUIRED_CAPABILITIES_NOT_LISTED` until the list is added. Prisma 8.0 requires the list. Add the list, run `prisma contract emit` after the `contract-hash-inputs` script, then sign each database as the `contract-hash-inputs` instructions say.
|
|
132
|
+
detection:
|
|
133
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs}"
|
|
134
|
+
matches:
|
|
135
|
+
- '@prisma/orm-postgres/(?:config|contract-builder)[''"]'
|
|
136
|
+
- id: postgres-config-without-define-config-passes-capabilities
|
|
137
|
+
summary: |
|
|
138
|
+
A config that builds a PostgreSQL contract source itself, with `prismaContract` or `prisma7Contract`, passes the source `requiredCapabilities: [...postgres18, ...postgresDriver]` from `@prisma/orm-postgres/config`. Without it, a source passed to the PostgreSQL `defineConfig` requires the newest version's list and the driver's and `prisma contract emit` warns, until Prisma 8.0. A config built with the core `defineConfig`, which names the target, adapter and driver itself, gets no default: its next `prisma contract emit` writes a contract that lists no capabilities, so the features that need a capability, such as `transaction()`, are refused, includes still work with one query per relation, and a schema with a scalar list or `@@check` does not emit. Add the `requiredCapabilities` line before emitting.
|
|
139
|
+
detection:
|
|
140
|
+
glob: "**/*.{ts,mts,cts,js,mjs,cjs}"
|
|
141
|
+
matches:
|
|
142
|
+
- '\bprisma(?:7)?Contract\s*\('
|
|
143
|
+
- id: postgres-emitted-contract-is-emitted-again
|
|
144
|
+
summary: |
|
|
145
|
+
A PostgreSQL `contract.json` and the migration snapshots a release candidate wrote store what the contract requires as `capabilities`, with `sql.` and `postgres.` keys. This release refuses to read such a `contract.json`, with `CONTRACT.VALIDATION_FAILED`. A migration snapshot a release candidate wrote is refused before that, with `MIGRATION.CONTRACT_SNAPSHOT_CONTENT_MISMATCH`, because its storage hash was computed by the old hash rules. The `contract-hash-inputs` script of this release rewrites both, and `prisma contract emit` then writes the contract's own list.
|
|
146
|
+
detection:
|
|
147
|
+
glob: "**/contract.json"
|
|
148
|
+
matches:
|
|
149
|
+
- '(?<![\s\S])(?=[\s\S]*"target"\s*:\s*"postgres")(?![\s\S]*"requiredCapabilities")'
|
|
150
|
+
- id: postgres-transaction-needs-interactive-transactions
|
|
151
|
+
summary: |
|
|
152
|
+
`transaction()` on a PostgreSQL client, a serverless connection or a Supabase role-bound client needs the contract to require `conn.interactiveTransactions`. `postgresDriver` lists it; a list that leaves it out makes the callback passed to `transaction()` a type error, and makes `transaction()` throw `ORM.CAPABILITY_MISSING` at run time.
|
|
153
|
+
- id: postgres-hand-built-contract-lists-capabilities
|
|
154
|
+
summary: |
|
|
155
|
+
A contract stores what it requires as `requiredCapabilities`, a sorted list of keys prefixed `db.` or `conn.`, such as `db.returning`. The client no longer adds its target's, adapter's and driver's capabilities to the contract's. A contract built by hand, not emitted, must list every capability it uses there, and code that reads a contract's capabilities reads `requiredCapabilities`.
|
|
156
|
+
detection:
|
|
157
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs}"
|
|
158
|
+
matches:
|
|
159
|
+
- '\.capabilities\s*(?:\?\.|\.)\s*(?:sql|postgres)\b|\.capabilities\s*(?:\?\.)?\[\s*[''"](?:sql|postgres)\b'
|
|
160
|
+
- '\bcapabilities[''"]?\s*:\s*\{\s*[''"]?(?:sql|postgres)[''"]?\s*:'
|
|
161
|
+
- id: postgres-signing-refuses-servers-older-than-15
|
|
162
|
+
summary: |
|
|
163
|
+
`prisma db verify`, `prisma db sign`, `prisma db migrate`, `prisma db update` and `prisma db init` now refuse a PostgreSQL database that does not provide what the contract requires of it, and every server older than PostgreSQL 15.
|
|
164
|
+
- id: postgres-capability-flags-removed
|
|
165
|
+
summary: |
|
|
166
|
+
PostgreSQL contracts no longer list `postgres.orderBy`, `postgres.limit`, `postgres.lateral`, `postgres.jsonAgg`, `postgres.returning`, `sql.enums`, `postgres.pgvector.cosine`, `postgres.postgis.geometry` or `postgres.paradedb/bm25`. Nothing read them, and no `db.` key replaces them. Remove any reference to them.
|
|
167
|
+
detection:
|
|
168
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs}"
|
|
169
|
+
matches:
|
|
170
|
+
- '\bpostgres\.(?:orderBy|limit|lateral|jsonAgg|returning)\b'
|
|
171
|
+
- 'pgvector\.cosine|postgis\.geometry|paradedb/bm25'
|
|
172
|
+
- id: postgres-capability-exports-moved
|
|
173
|
+
summary: |
|
|
174
|
+
`postgresAdapterCapabilities`, from `@prisma/orm-target-postgres/adapter/adapter`, is now empty, and Prisma 8.0 removes it. Nothing needs to read it. The database's capabilities are in `postgresCapabilitiesByVersion` from `@prisma/orm-target-postgres/target/server-version`. `PostgresDatabaseSchemaNode.pgVersion` is replaced by `serverVersionNumber`.
|
|
175
|
+
detection:
|
|
176
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs}"
|
|
177
|
+
matches:
|
|
178
|
+
- '\bpostgresAdapterCapabilities\b'
|
|
179
|
+
- '\bpgVersion\b'
|
|
180
|
+
- id: stored-files-format-version
|
|
181
|
+
summary: |
|
|
182
|
+
Every file Prisma stores in a project now names its format version. A `contract.json`, and each contract snapshot under `migrations/snapshots/<hash>/`, has `"formatVersion": 1` where it had `"schemaVersion": "1"`. Every `migration.json` and every ref file under `migrations/<space>/refs/` starts with `"formatVersion": 1`. Until `8.0.0`, a release still reads a `migration.json` or a ref file without it, as the format a release candidate wrote, and changes nothing on disk. A contract or a snapshot a release candidate wrote stores what it requires as `capabilities`, which this release refuses until the `contract-hash-inputs` step of this release rewrites it. `8.0.0` refuses such a file, with `CONTRACT.FORMAT_VERSION_MISSING` or `MIGRATION.FORMAT_VERSION_MISSING`. Run the colocated script on the project before you upgrade to `8.0.0`: it adds the version to each file and changes nothing else. No hash changes.
|
|
183
|
+
detection:
|
|
184
|
+
glob: "**/*.json"
|
|
185
|
+
matches:
|
|
186
|
+
- '"schemaVersion"\s*:\s*"1"[\s\S]*"targetFamily"\s*:|"targetFamily"\s*:[\s\S]*"schemaVersion"\s*:\s*"1"'
|
|
187
|
+
- '(?<![\s\S])(?![\s\S]*"formatVersion")[\s\S]*"migrationHash"\s*:'
|
|
188
|
+
- '(?<![\s\S])(?![\s\S]*"formatVersion")(?=[\s\S]*"hash"\s*:)[\s\S]*"invariants"\s*:'
|
|
189
|
+
script: ./scripts/stored-files-format-version/stored-files-format-version.ts
|
|
190
|
+
- id: contract-hash-inputs
|
|
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.
|
|
193
|
+
script: ./scripts/contract-hash-inputs/contract-hash-inputs.ts
|
|
194
|
+
- id: migration-ts-proto-key-computed
|
|
195
|
+
summary: |
|
|
196
|
+
A generated `migration.ts` now writes an object key `__proto__` as a computed key, `['__proto__']:`, which JavaScript keeps as a key. A `migration.ts` generated by the previous release wrote `__proto__:`, and running that file loses the key or fails. Rewrite the key in such a file before you run it again.
|
|
197
|
+
detection:
|
|
198
|
+
glob: "**/migration.ts"
|
|
199
|
+
matches:
|
|
200
|
+
- '["'']?__proto__["'']?\s*:'
|
|
201
|
+
- id: prisma-tables-move-to-prisma-schema
|
|
202
|
+
summary: |
|
|
203
|
+
On PostgreSQL, Prisma's own tables move from the schema `prisma_contract` to the schema `prisma`, and the `marker` table is replaced by two tables: `prisma.signatures`, which records which contract each contract space was signed with, and `prisma.config`, which holds the database's change policy and data protection policy. The first command that changes the database (`prisma db init`, `db update`, `db migrate` or `db sign`) renames the schema, moves the rows of `marker` into the two new tables, drops `marker`, and keeps everything Prisma recorded. Run one of them against each database once, with the new release, before the application on the new release reads it. After that, only the new release may change the database: a release candidate's command applies every migration again. The command stops without changing anything when the role that runs it does not own the schema and its tables or may not create in the database, when a schema named `prisma` already exists and holds anything but Prisma's own tables, such as a schema of the project's own named `prisma`, when `prisma_contract` holds anything but the release candidates' tables, when the role may not create tables in an empty `prisma`, when `prisma` holds Prisma's tables while `prisma_contract` exists too, when one of Prisma's tables is in a form this release does not bring up to date, or when another object, such as a view, depends on `marker`.
|
|
204
|
+
detection:
|
|
205
|
+
glob: "**/package.json"
|
|
206
|
+
matches:
|
|
207
|
+
- '"@prisma/orm-postgres"\s*:'
|
|
208
|
+
- id: name-the-prisma-schema
|
|
209
|
+
summary: |
|
|
210
|
+
Anything in the project that names the schema `prisma_contract` in its own SQL or scripts must name `prisma` instead: grants in infrastructure code, scripts that drop or reset the database, monitoring queries, row-level-security setup, and tests that reset the database. Anything that names the `marker` table must name `prisma.signatures`, or `prisma.config` for the policies. A grant on `marker` is dropped with the table. Once the database is brought up to date, a role that runs a command that reads the database's policies (`prisma db migrate`, `db migrate --show`, `db update` and `db sign`) needs `SELECT` on both `prisma.signatures` and `prisma.config`; `prisma db verify` and the application's client need `SELECT` on `prisma.signatures` alone, and `prisma migration status` without access to `prisma.config` reports that it cannot read the policies and still gives its report. Migrations that have been planned are not edited.
|
|
211
|
+
detection:
|
|
212
|
+
glob: "**/*"
|
|
213
|
+
contains:
|
|
214
|
+
- "prisma_contract"
|
|
215
|
+
- id: rename-a-namespace-named-prisma
|
|
216
|
+
summary: |
|
|
217
|
+
On PostgreSQL, the schemas `prisma` and `prisma_contract` are reserved for Prisma's own tables, so a project's contract may no longer declare a namespace with either name. `prisma migration plan`, `prisma db init` and `prisma db update` refuse such a contract with `MIGRATION.PLANNING_FAILED`, and `prisma db migrate` with `MIGRATION.CONTRACT_SPACE_VIOLATION`. The namespace, and the schema in every database, need another name.
|
|
218
|
+
detection:
|
|
219
|
+
glob: "**/*.prisma"
|
|
220
|
+
matches:
|
|
221
|
+
- 'namespace\s+prisma(_contract)?\s*\{'
|
|
222
|
+
- id: marker-table-is-signatures
|
|
223
|
+
summary: |
|
|
224
|
+
On PostgreSQL, Prisma's `marker` table is replaced by `prisma.signatures`, one row per contract space with the columns `space`, `core_hash`, `profile_hash`, `invariants` and `signed_at`, and `prisma.config`, which holds the database's policies. Queries, scripts and project docs that name the marker table, as `prisma.marker` or `prisma_contract.marker`, name `prisma.signatures` instead, or `prisma.config` for the policies.
|
|
225
|
+
detection:
|
|
226
|
+
glob: "**/*"
|
|
227
|
+
matches:
|
|
228
|
+
- 'prisma(?:_contract)?"?\."?marker\b'
|
|
229
|
+
- '[Mm]arker table'
|
|
230
|
+
- id: sqlite-prisma-tables-renamed
|
|
231
|
+
summary: |
|
|
232
|
+
On SQLite, Prisma's own tables `_prisma_marker` and `_prisma_ledger` are replaced by `prisma_signatures` (one row per contract space: `space`, `core_hash`, `profile_hash`, `invariants`, `signed_at`), `prisma_config` (at most one row, the database's policies in `policies`) and `prisma_ledger`. The first `db migrate`, `db update`, `db init` or `db sign` of this release moves the rows and drops the old tables, unless a project added a column to one of them, which stops it first. Queries, scripts and project docs that name `_prisma_marker` or `_prisma_ledger` name the new tables instead.
|
|
233
|
+
detection:
|
|
234
|
+
glob: "**/*"
|
|
235
|
+
matches:
|
|
236
|
+
- '\b_prisma_(?:marker|ledger)\b'
|
|
237
|
+
- id: db-init-db-update-ref-rule
|
|
238
|
+
summary: |
|
|
239
|
+
`prisma db init` and `prisma db update` now advance refs by the rule `prisma db migrate` follows. Without `--advance-ref`, they no longer advance the `db` ref when the CLI detects CI, and say so with `MIGRATION.REF_NOT_ADVANCED_IN_CI`; they still advance nothing with `--db`. Both take the new `--no-advance-ref`, which a pipeline passes to write no ref and silence the notice. A ref they cannot write is now a warning and the command exits 0, which matters to a script that checks their exit code. A pipeline or script that runs `db init` or `db update` from the config in CI and needs `migrations/app/refs/db.json` written passes `--advance-ref db`. Without a ref they also store no snapshot of the contract they applied, so a pipeline that later runs `db update` with statements such as `--rename` passes `--advance-ref <name>` on the earlier run. The detection finds `db init` and `db update` commands that pass `--advance-ref`, and those that pass neither `--db` nor `--no-advance-ref`, including a Dockerfile's exec form, a YAML list and a command split with a backslash between `db` and the command; it reads the flags only up to the end of that command on its line (a `;`, `&`, `|` or an unescaped quote, so a command in a JSON string is read alone, and an exec form such as `["prisma","db","update","--db","$URL"]` matches even with `--db`); check each against the cases below, and look for others in files it does not search.
|
|
240
|
+
detection:
|
|
241
|
+
glob: "**/{*.json,*.sh,*.bash,*.zsh,*.yml,*.yaml,*.toml,*.md,*.mdx,*.ts,*.mts,*.js,*.mjs,*.cjs,Dockerfile*,*.dockerfile,Procfile*,Makefile,justfile}"
|
|
242
|
+
matches:
|
|
243
|
+
- '(?<![\w-])db(?:[ \t]+|[ \t]*\\\n\s*|["'']\s*,\s*["'']|\s*\n\s*-\s+["'']?)(?:init|update)\b(?:(?=(?:[^\n;&|"\\]|\\.)*--advance-ref\b)|(?!(?:[^\n;&|"\\]|\\.)*--(?:db|no-advance-ref)\b))'
|
|
244
|
+
- id: contract-argument-one-parser
|
|
245
|
+
summary: |
|
|
246
|
+
Every command that takes a contract argument now reads it with one parser. A path to a migration directory works wherever its name does, and `migration new --from` takes what `migration plan --from` takes. Some error codes change for scripts that match on them. On `migration new --from`, a hash prefix needs six characters or more, an empty string is `MIGRATION.REF_INVALID_FORMAT`, an unknown name, prefix or path is `MIGRATION.REF_NOT_FOUND` where it was `MIGRATION.HASH_NOT_IN_GRAPH`, a prefix that matches several contracts is `MIGRATION.REF_AMBIGUOUS`, and `@empty` is accepted. `@db` and `@contract` given to `migration ref set`, `migration plan --from` or `--to`, or `migration new --from` are refused first with `MIGRATION.REF_WRONG_GRAMMAR`. `migration plan --from empty` or `--from <first migration>^` now plans from an empty database. A `--from <ref>` whose contract no migration records and whose snapshot is missing is `MIGRATION.HASH_NOT_IN_GRAPH` where it was `MIGRATION.SNAPSHOT_MISSING`.
|
|
247
|
+
detection:
|
|
248
|
+
glob: "**/{*.json,*.sh,*.bash,*.zsh,*.yml,*.yaml,*.toml,*.md,*.mdx,*.ts,*.mts,*.cts,*.js,*.mjs,*.cjs,Dockerfile*,Makefile,justfile}"
|
|
249
|
+
matches:
|
|
250
|
+
- '\bmigration[ \t]+new\b[^\n]*--from\b'
|
|
251
|
+
- '\bmigration[ \t]+(?:ref[ \t]+set|plan)\b[^\n]*@(?:db|contract)\b'
|
|
252
|
+
- 'MIGRATION\.(?:HASH_NOT_IN_GRAPH|SNAPSHOT_MISSING|REF_SET_EMPTY_SENTINEL)\b'
|
|
253
|
+
- id: control-api-ref-resolution-takes-migration-dir
|
|
254
|
+
summary: |
|
|
255
|
+
`resolveContractRef`, `resolveContractRefToSnapshot`, `resolveFromForPlan` and `resolveToForPlan`, from `@prisma/orm-toolchain/cli/control-api`, take one more required field in their options or context, `migrationDirResolution: { cwd, spaceMigrationsDir }`: the folder a path argument is resolved against, and the migrations folder of the space, such as `<project>/migrations/app`. A call without it no longer compiles.
|
|
256
|
+
detection:
|
|
257
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs}"
|
|
258
|
+
matches:
|
|
259
|
+
- '\b(?:resolveContractRef|resolveContractRefToSnapshot|resolveFromForPlan|resolveToForPlan)\s*\('
|
|
260
|
+
- id: mongo-proto-field-and-relation-names-refused
|
|
261
|
+
summary: |
|
|
262
|
+
A MongoDB contract now refuses a field, a relation, or a member of a composite type or value object named `__proto__`, an embed relation stored under that name, and, in a Mongo PSL contract, an enum named `__proto__` and a wildcard index path `__proto__`. Choose another name, and move the values that documents hold under the old key.
|
|
263
|
+
detection:
|
|
264
|
+
glob: "**/*.{prisma,ts,mts,cts,tsx}"
|
|
265
|
+
matches:
|
|
266
|
+
- '__proto__'
|
|
267
|
+
- id: mongo-stored-name-change-is-a-rename
|
|
268
|
+
summary: |
|
|
269
|
+
On MongoDB, a model, field or enum member that keeps its name while its `@@map`, `@map` or stored value changes is now renamed, or has its stored value replaced, by `migration plan` and `db update`, with no question. A field of an embedded model has its key renamed in every place the model is stored. The by-hand rename these changes needed before is no longer needed.
|
|
270
|
+
- id: mongo-stored-name-delete-is-unused
|
|
271
|
+
summary: |
|
|
272
|
+
A `--delete` statement that a script passed to allow the drop of a collection, or the removal of a field, key or enum value, whose stored name changed now answers no question, and the run fails with `CLI.CONSENT_UNUSED`.
|
|
273
|
+
- id: mongo-stored-name-empty-collection
|
|
274
|
+
summary: |
|
|
275
|
+
To get an empty collection, or a field with no values, under a new stored name instead of renaming the old one, remove the model or field in one change and add it back in a second.
|
|
276
|
+
- id: mongo-stored-name-swaps-refused
|
|
277
|
+
summary: |
|
|
278
|
+
Swaps, chains and takeovers of collection names and of field stored names are refused with `MIGRATION.PLANNING_FAILED`. Enum members that swap stored values, shift them along a chain, or take the stored value of another member, which were asked about before with advice to use two migrations, are now refused with a route through two plans.
|
|
279
|
+
- id: mongo-shared-collection-rename-refused
|
|
280
|
+
summary: |
|
|
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
|
+
- id: mongo-create-collection-postcheck
|
|
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.
|
|
285
|
+
- id: runtime-signature-check-only-warns
|
|
286
|
+
summary: |
|
|
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.
|
|
288
|
+
detection:
|
|
289
|
+
glob: "**/*.{ts,tsx,mts,cts,js,mjs,cjs}"
|
|
290
|
+
matches:
|
|
291
|
+
- 'CONTRACT\.(?:MARKER_READ_FAILED|SIGNATURE_READ_FAILED)'
|
|
292
|
+
- 'CONTRACT\.(?:MARKER_ROW_CORRUPT|SIGNATURE_ROW_CORRUPT)'
|
|
293
|
+
- id: default-logger-console
|
|
294
|
+
summary: |
|
|
295
|
+
A client created without `log` (`postgres()`, `postgresServerless()`, `sqlite()`, `supabase()`, the MySQL and MariaDB clients, and `mongo()`) now writes the runtime's warnings to `console.warn` and its errors to `console.error`, which in Node go to standard error, and its info events to `console.info`. Debug events are still dropped. Before, the client dropped every event. An application that needs a silent console passes `log: { info() {}, warn() {}, error() {} }`. `mongo()` now takes `log`, with the same type and default as the SQL clients.
|
|
296
|
+
detection:
|
|
297
|
+
glob: "**/*.{ts,tsx,mts,cts,js,mjs,cjs}"
|
|
298
|
+
matches:
|
|
299
|
+
- '@prisma/orm-(?:postgres|sqlite|mysql|mariadb|mongo|extension-supabase)/(?:runtime|serverless)[''"]'
|
|
300
|
+
- id: fragment-on-the-client
|
|
301
|
+
summary: |
|
|
302
|
+
A fragment for any model is made with `db.fragment(fields, body)` instead of `db.orm.fragment(fields, body)`, and inside a transaction with `tx.fragment(...)` instead of `tx.orm.fragment(...)`. `db.orm` now holds only the contract's namespaces (PostgreSQL) or models (SQLite, MySQL, MariaDB), so a namespace or model may be named `fragment`. Code that builds its own ORM client with `orm()` from `@prisma/orm-postgres/orm-client` gets the member from `fragmentMember<Contract>()`. The per-model form `db.orm.public.Post.fragment(body)` is unchanged.
|
|
303
|
+
detection:
|
|
304
|
+
glob: "**/*.{ts,tsx,mts,cts,js,mjs,cjs}"
|
|
305
|
+
matches:
|
|
306
|
+
- '\.fragment\(\s*[^\s()]'
|
|
307
|
+
- '(?<![\w$])orm\.fragment\('
|
|
308
|
+
- id: orm-fns-comparison-takes-field-input-type
|
|
309
|
+
summary: |
|
|
310
|
+
In an ORM callback, `fns.eq`, `fns.ne`, `fns.gt`, `fns.gte`, `fns.lt`, `fns.lte`, `fns.in` and `fns.notIn` now type a plain value compared with a model field as that field's input type, such as an enum's member union, as `p.status.eq(...)` and the `where` shorthand object already did. A value that is not of that type, such as `fns.eq(p.status, 'NOT_A_MEMBER')`, no longer compiles. Do not edit such a call: report it to the user with the value or narrowing you would propose, note that the condition would then match different rows than before, and ask.
|
|
311
|
+
detection:
|
|
312
|
+
glob: "**/*.{ts,tsx,mts,cts}"
|
|
313
|
+
matches:
|
|
314
|
+
- '(?<![\w$])fns\.(?:eq|ne|gte?|lte?|in|notIn)\('
|
|
315
|
+
- id: update-all-explicit-type-argument
|
|
316
|
+
summary: |
|
|
317
|
+
`updateAll` and `updateAndCount` on an ORM collection now have two type parameters, because they also take a callback. A call that passes one explicit type argument, such as `drafts.updateAll<typeof drafts>({ ... })`, no longer compiles (TS2558). Remove the type argument: TypeScript infers both. Calls without a type argument do not change.
|
|
318
|
+
detection:
|
|
319
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
320
|
+
matches:
|
|
321
|
+
- '\.(?:updateAll|updateAndCount)\s*<'
|
|
322
|
+
- id: sql-builder-shared-join-column-name-needs-table
|
|
323
|
+
summary: |
|
|
324
|
+
In the SQL builder, a column name that two or more joined tables have is now reached only through its table, such as `f.users.id`, however many tables the query joins. Before, with three or more joined tables, a name that the first two shared but a later one also had, such as `id`, became a top-level field again. In 8.0.0-rc.25, reading that field in a callback, such as `f.id`, type-checked, ran without an error and silently returned the column of the last joined table that has the name; in earlier releases the database refused it as ambiguous. Passing the name as a string, as in `select('id')`, `orderBy('id')`, `groupBy('id')` or `distinctOn('id')`, was refused by the database as ambiguous in every release. Both forms are now a type error, and the string forms throw `ORM.COLUMN_AMBIGUOUS` when `select` (or `orderBy`, `groupBy` or `distinctOn`) is called. Decide which table's column the code means, which may not be the last joined table that has the name, and name that table. Results that the callback form produced in 8.0.0-rc.25 may hold the wrong table's values; so may either form inside a lateral subquery.
|
|
325
|
+
detection:
|
|
326
|
+
glob: "**/*.{ts,tsx,mts,cts}"
|
|
327
|
+
matches:
|
|
328
|
+
- '\.(?:innerJoin|outerLeftJoin|outerRightJoin|outerFullJoin|lateralJoin|outerLateralJoin)\('
|
|
329
|
+
- id: sql-builder-list-column-in-a-one-value-position
|
|
330
|
+
summary: In the PostgreSQL SQL builder a list column is typed as a list, so an ordered comparison of it, it on the left of `in` / `notIn`, or a raw expression declared as one value in its place no longer compiles.
|
|
331
|
+
- id: postgres-char-bit-list-values-check
|
|
332
|
+
summary: |
|
|
333
|
+
On PostgreSQL, 8.0.0-rc.25 cut each element of a `char(n)[]` value it wrote to its first character, because its parameter cast named the type without its length. For the same reason, a write of a `bit(n)[]` value failed with an error and stored nothing. This release casts to `bpchar` and `varbit`, which keep the length. `char(n)[]` values written with 8.0.0-rc.25 stay cut. Find each `char(n)[]` column, report it to the user, and give them a query to find the rows written with values cut to one character.
|
|
334
|
+
- id: prepared-declaration-param-spec-can-be-a-list
|
|
335
|
+
summary: |
|
|
336
|
+
`ParamSpec`, the type of each parameter in a prepared declaration (`@prisma/orm-family-sql/runtime`, and the `family-runtime` entry of each SQL database package, such as `@prisma/orm-postgres/family-runtime`), gains `many?: { elementNullable: boolean }`, for a parameter that holds a list. Code that is generic over a declaration, such as a function that wraps `prepare`, `prepareQuery` or `delegatingRuntime`, implements `PrepareMember` or `DelegatingRuntime`, or maps each parameter of a declaration to a value type, may no longer type-check where it treats every parameter as one value. Treat a spec with `many` as a list of its codec's values, or pass the declaration type on unchanged. The `ParamSpec` of `@prisma/orm-framework/operations`, for operation signatures, is a different type and does not change: leave code that uses only that one as it is.
|
|
337
|
+
detection:
|
|
338
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
339
|
+
matches:
|
|
340
|
+
- '\b(?:PrepareMember|prepareQuery|DelegatingRuntime|delegatingRuntime|ParamSpec)\b'
|
|
341
|
+
- id: app-middleware-handles-later-activities
|
|
342
|
+
summary: |
|
|
343
|
+
A middleware's hooks can now receive an activity, an ended result or a value of a kind a later 8.x release adds. `Activity` and `ActivityEndedResult` gain a member whose `kind` is a `FutureCase`, and `ActivityContext.mode` and `.scope`, `TransactionEnded.outcome`, `StatementEnded.outcome` and `.source`, `ClientActivityEnded.outcome` and `.source` and `ActivityFinalizedResult.outcome` accept any string beside their named values. Where a middleware checks every kind or value, with a `switch` or a `never` assignment, give it a branch for the rest, and act there as for a value it does not know: for example, cache nothing or pass the activity on. A middleware that narrows away `'statement'` and `'transaction'` and then reads a client activity's `contentHash` must instead check that the kind is a client kind, whose name always contains a hyphen (such as `orm-call`). `FutureCase` (a type every entry of your database package and of the extensions exports, such as `@prisma/orm-postgres/runtime`) only stands for a later kind in the type, and no code can write it; at run time a later kind arrives under its own name, so check for the kinds the middleware knows. Likewise `StatementActivity.returns` accepts any string beside `'rows'` and `'stats'`, and `StatementEnded` gains a member whose `returns` is a `FutureCase`: read `rowCount` after `returns === 'rows'` and `stats` after `returns === 'stats'`, not in an `else` branch.
|
|
344
|
+
detection:
|
|
345
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs}"
|
|
346
|
+
matches:
|
|
347
|
+
- '\b(?:activity(?:Started|Ended|Finalized)|onQuery|onExecute|onActivity|onRow|beforeEncode)\s*[(:]'
|
|
348
|
+
- id: app-switches-over-later-values
|
|
349
|
+
summary: |
|
|
350
|
+
Sets of values that a later 8.x release may grow now say so in their types. Each is written `NonExhaustive<…>`. `NonExhaustive` and `FutureCase` are types every entry of your database package and of the extensions exports, so import them as types from the entry you import the union from, such as `import type { ColumnDefault, FutureCase } from '@prisma/orm-postgres/contract-builder'`. A union of strings gains `(string & {})`; a union of objects gains a member whose `kind` (or, for a migration statement, `entity`; for the other unions below, the property named) is a `FutureCase`, a value no release has and no code can write, which stands for one a later release adds. The sets:
|
|
351
|
+
|
|
352
|
+
- a column default (`ColumnDefault`, kinds `'literal'` and `'function'`) and a field's type (`ContractFieldType`, kinds `'scalar'`, `'valueObject'` and `'union'`);
|
|
353
|
+
- the database policies a ref declares (`ChangeStrategy`, `DataLossLevel`, `AccessWideningLevel`);
|
|
354
|
+
- a migration statement (`ResolvedMigrationStatement` and `MigrationStatementJson`, told apart by `kind` and `entity`) and a migration subject (`MigrationSubject` and `MigrationSubjectJson`);
|
|
355
|
+
- the PSL parser's symbols, scope resolutions, token kinds, syntax kinds and diagnostic codes (`PslSymbol`, `ScopeResolution`, `TokenKind`, `SyntaxKind`, `PslDiagnosticCode`);
|
|
356
|
+
- the `mode` of the result of the control API's `dbInit()` and `dbUpdate()`;
|
|
357
|
+
- more of what the control API hands back: the `outcome` of a `spanEnd` progress event an `onProgress` callback receives, the `kind` of each entry of a result's `perSpace`, the `kind` of a migration plan's `migrationsToTarget`, what a plan question's `namespaceAnswer()` returns, the `reason` of the `unreachable` position `classifyInstalledSpaceRow()` returns, and the `verb` an `answerQuestions` callback receives for each subject answered without asking;
|
|
358
|
+
- the `appliedStatements` of a `dbUpdate()` or migration plan result: a consent statement's `statement.kind` accepts any string beside `'delete'` and `'allow'`, and `AppliedStatementReport` gains a member whose `verb` is a `FutureCase` and which has no `statement`;
|
|
359
|
+
- what the control API's `dbSign()` returns for each space (`DbSignSpaceOutcome`): its `status` gains a member whose `status` is a `FutureCase`, and a signature conflict gains a member whose `reason` is a `FutureCase` and which has no `expected` or `found`;
|
|
360
|
+
- the `setting` of each policy difference a result's `databasePoliciesUpdated` lists (`DatabasePolicyDifference`), whose new member's `declared` and `inForce` are a string or a list of strings;
|
|
361
|
+
- the `by` of a migration runner failure's `failedTypeChange` (`FailedTypeChange`), and the `provenance` of what `contractAt()` returns (`ContractAtResult`);
|
|
362
|
+
- the `format` of a contract source (`ContractSourceProvider`, as `loadConfig()`, `loadConfigForFile()` and `loadConfigForSections()` return it in `contract.source`), which gains a member whose `format` is a `FutureCase`;
|
|
363
|
+
- the `setting` and `subject` of the MongoDB contract builder's refusals (`BuildRefusal`, in a `BuildFailure`);
|
|
364
|
+
- what the SQL contract DSL hands back: the state `RelationBuilder.build()` returns (its `kind`, and the `kind` and `source` of its `toModel` and `through`) and the `source` of a `TargetFieldRef` from `constraints.ref()`.
|
|
365
|
+
|
|
366
|
+
What to do:
|
|
367
|
+
|
|
368
|
+
- Where code checks every value, with a `switch` or a `const unreachable: never = value` assignment, add a `default` branch that acts as for a value the code does not know: report it, skip it, or throw.
|
|
369
|
+
- To keep the compiler's check that every kind you know is handled, assign the value in the `default` branch to `FutureCase` in place of `never`: `const later: FutureCase = columnDefault.kind`. A kind the code forgets is still a compile error, and only a kind a later release adds reaches the branch.
|
|
370
|
+
- Where code reads a member's own property in an `else` branch, such as `columnDefault.expression` after ruling out `'literal'`, check for the kind it means instead: `columnDefault.kind === 'function'`.
|
|
371
|
+
- For `AppliedStatementReport`, read `statement` only after narrowing on a `verb` you handle.
|
|
372
|
+
- For `DbSignSpaceOutcome`, `status === 'conflict'` no longer narrows to the conflict over the signature's hashes: read `expected` and `found` after `reason === 'storageHash'`.
|
|
373
|
+
- For `ContractSourceProvider`'s `format`, branch on `'psl'` and `'typescript'` by name, and treat any other format as one the code does not read, never as TypeScript.
|
|
374
|
+
- For the `mode` of a `dbInit()` or `dbUpdate()` result, use the `mode` the call was given.
|
|
375
|
+
- A table keyed by one of these sets, such as a `Record` from each value to a message, accepts any key once the set is open, so a lookup with a value a later release adds returns `undefined` although its type says otherwise: check that the key is present, for example with `Object.hasOwn(table, key)`, before using what it returns.
|
|
376
|
+
detection:
|
|
377
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs}"
|
|
378
|
+
matches:
|
|
379
|
+
- '\b(?:ColumnDefault|ContractFieldType|ChangeStrategy|DataLossLevel|AccessWideningLevel|ResolvedMigrationStatement|ResolvedRenameStatement|MigrationStatementJson|MigrationSubject|MigrationSubjectJson|PslSymbol|ScopeResolution|TokenKind|SyntaxKind|PslDiagnosticCode)\b'
|
|
380
|
+
- '\b(?:dbInit|dbUpdate)\s*\('
|
|
381
|
+
- '\.build\(\)\.(?:kind|toModel|through)\b'
|
|
382
|
+
- '\b(?:onProgress|perSpace|migrationsToTarget|namespaceAnswer|classifyInstalledSpaceRow|appliedStatements|AppliedStatementReport|answerQuestions|AnsweredWithoutAsking|BuildRefusal|BuildFailure|TargetFieldRef)\b'
|
|
383
|
+
- '\b(?:dbSign|DbSignSpaceOutcome|databasePoliciesUpdated|DatabasePolicyDifference|failedTypeChange|FailedTypeChange|contractAt|ContractAtResult|ContractSourceProvider|loadConfig|loadConfigForFile|loadConfigForSections)\b'
|
|
384
|
+
- id: app-geometry-may-gain-types
|
|
385
|
+
summary: |
|
|
386
|
+
A PostGIS geometry (`Geometry`, also published as `GeometryValue`) may be of a type a later 8.x release adds, such as a geometry collection, which has no `coordinates`. The union gains a member whose `type` is a `FutureCase` and which carries only `type` and `srid`, so code that reads `coordinates` before checking `type` no longer compiles: check `type` first, for example `if (geometry.type === 'Point') use(geometry.coordinates)`. A `switch` over `type` that handles every type needs a `default` branch; to keep the compiler's check that every type you know is handled, assign the value there to `FutureCase` in place of `never`, as in `const later: FutureCase = geometry.type`. `FutureCase` is a type every entry of `@prisma/orm-extension-postgis` exports, so import it from the entry you import `Geometry` from, such as `import type { FutureCase, Geometry } from '@prisma/orm-extension-postgis/geojson'`. It only stands for a later type in the type, and no code can write it; at run time a later type arrives under its own name.
|
|
387
|
+
detection:
|
|
388
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs}"
|
|
389
|
+
matches:
|
|
390
|
+
- '\b(?:Geometry|GeometryValue)\b'
|
|
391
|
+
- '\.coordinates\b'
|
|
392
|
+
---
|
|
393
|
+
|
|
394
|
+
# 8.0.0-rc.25 → 8.0.0-rc.26 — User upgrade instructions
|
|
395
|
+
|
|
396
|
+
This release changes every hash Prisma stores, moves Prisma's own tables, and renames the contract marker to the contract signature. Read the whole order below before you start: some of it must happen with the release you are on now, and some of it in the deploy.
|
|
397
|
+
|
|
398
|
+
## Order of the steps
|
|
399
|
+
|
|
400
|
+
Do the steps in this order, and skip a step that does not apply to the project:
|
|
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.
|
|
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`).
|
|
410
|
+
|
|
411
|
+
## The application lists the platform packages
|
|
412
|
+
|
|
413
|
+
### `list-the-platform-packages`
|
|
414
|
+
|
|
415
|
+
The database package, such as `@prisma/orm-postgres`, no longer brings `@prisma/orm-framework`, its family, its target and `@prisma/orm-toolchain` along as its own dependencies. It names them as peer dependencies, and so does every extension. A package manager never gives a package its own copy of a peer dependency: it uses the copy the application lists. So the application now lists them, and holds one copy of each. A monorepo whose applications are on different Prisma versions can still get two copies under npm workspaces and Bun's hoisted linker; keep such applications on one version, or use pnpm, Yarn or Bun's isolated linker. Yarn installs no peer dependencies at all, so an application under Yarn that does not list them cannot load the database package. npm and pnpm install a missing peer by themselves, which hides the gap until the project moves to another package manager.
|
|
416
|
+
|
|
417
|
+
For each `package.json` that lists a database package, add every `@prisma/orm-*` package that the database package and each installed `@prisma/orm-*` extension name as peer dependencies. Put them in the same field as the database package (usually `dependencies`), each naming the same version as the database package, written the same way as the database package's line (an exact version, or a caret if that line has one), so an update moves them together. Leave entries the file already has.
|
|
418
|
+
|
|
419
|
+
These are the packages each database package names:
|
|
420
|
+
|
|
421
|
+
| The database package | Add |
|
|
422
|
+
| --- | --- |
|
|
423
|
+
| `@prisma/orm-postgres` | `@prisma/orm-framework`, `@prisma/orm-family-sql`, `@prisma/orm-target-postgres`, `@prisma/orm-toolchain` |
|
|
424
|
+
| `@prisma/orm-sqlite` | `@prisma/orm-framework`, `@prisma/orm-family-sql`, `@prisma/orm-target-sqlite`, `@prisma/orm-toolchain` |
|
|
425
|
+
| `@prisma/orm-mysql` | `@prisma/orm-framework`, `@prisma/orm-family-sql`, `@prisma/orm-target-mysql`, `@prisma/orm-toolchain` |
|
|
426
|
+
| `@prisma/orm-mariadb` | `@prisma/orm-framework`, `@prisma/orm-family-sql`, `@prisma/orm-target-mariadb`, `@prisma/orm-target-mysql`, `@prisma/orm-mysql`, `@prisma/orm-toolchain` |
|
|
427
|
+
| `@prisma/orm-mongo` | `@prisma/orm-framework`, `@prisma/orm-family-mongo`, `@prisma/orm-target-mongo`, `@prisma/orm-toolchain` |
|
|
428
|
+
|
|
429
|
+
The extensions name a subset of the PostgreSQL list, except `@prisma/orm-extension-supabase`, which also names `@prisma/orm-postgres`. For a PostgreSQL application on version `8.0.0-rc.26` with pgvector, `package.json` reads:
|
|
430
|
+
|
|
431
|
+
```json
|
|
432
|
+
"dependencies": {
|
|
433
|
+
"@prisma/orm-postgres": "8.0.0-rc.26",
|
|
434
|
+
"@prisma/orm-framework": "8.0.0-rc.26",
|
|
435
|
+
"@prisma/orm-family-sql": "8.0.0-rc.26",
|
|
436
|
+
"@prisma/orm-target-postgres": "8.0.0-rc.26",
|
|
437
|
+
"@prisma/orm-toolchain": "8.0.0-rc.26",
|
|
438
|
+
"@prisma/orm-extension-pgvector": "8.0.0-rc.26"
|
|
439
|
+
}
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
Besides the `@prisma/orm-*` packages, check the other required peer dependencies the database package and those packages name, the ones `peerDependenciesMeta` does not mark optional: `temporal-polyfill` for every database package, `pg` and `@types/pg` for `@prisma/orm-postgres`, and `mongodb` for `@prisma/orm-mongo`. A package manager that installs no peer dependencies, such as Yarn, leaves out any the application does not list, and the application then cannot load. Add each one the application does not list yet, at the range its manifest gives, in the same field as the database package, usually `dependencies`. `@types/pg` is only needed to compile, so `devDependencies` will do for it. An entry already under `devDependencies` satisfies a peer while you develop, but an install that leaves out development dependencies, such as `npm ci --omit=dev` in a deploy, leaves it out too, and the application then cannot load; move such an entry for `temporal-polyfill`, `pg` or `mongodb` to `dependencies`.
|
|
443
|
+
|
|
444
|
+
`@prisma/orm-toolchain` also names `@prisma/cli-engine`, the engine of the `prisma` command, as a peer. It is the exception:
|
|
445
|
+
|
|
446
|
+
- Do not add it. The `prisma` package depends on it at the exact version it runs, and the toolchain uses that copy, or a copy at its own version that the package manager installs for it.
|
|
447
|
+
- Add it, at the version `@prisma/orm-toolchain` names, only if the project's own code imports `@prisma/cli-engine`, or in a Yarn project whose `.yarnrc.yml` sets `nmHoistingLimits: dependencies`.
|
|
448
|
+
- Under Yarn, install reports the engine as a peer the project does not provide. That is expected.
|
|
449
|
+
|
|
450
|
+
To read the names from the installed packages instead of the table, run this from the project folder after the install, naming the database package and each `@prisma/orm-*` extension the project lists. It prints every package they need as a required peer: the `@prisma/orm-*` ones followed through the peers of those, and the others with the range their manifest gives. It leaves out the names the command was given and `@prisma/cli-engine`, and exits with an error when it cannot find one of them:
|
|
451
|
+
|
|
452
|
+
```sh
|
|
453
|
+
node -e 'const given=process.argv.slice(1);const read=(n)=>{try{return require(require.resolve(n+"/package.json",{paths:[process.cwd()]}))}catch{return undefined}};for(const n of given)if(!read(n)){console.error("cannot find "+n+" from this folder; install it first, or under Yarn Plug\x27n\x27Play run this with yarn node -e");process.exit(1)}const seen=new Set(given);const todo=[...given];const found=[];while(todo.length){const m=read(todo.shift())??{};const meta=m.peerDependenciesMeta??{};for(const [p,r] of Object.entries(m.peerDependencies??{})){if(seen.has(p)||meta[p]?.optional||p==="@prisma/cli-engine")continue;seen.add(p);if(p.startsWith("@prisma/orm-")){found.push(p);todo.push(p)}else found.push(p+"@"+r)}}console.log(found.join(" "))' @prisma/orm-postgres @prisma/orm-extension-pgvector
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
Under Yarn Plug'n'Play, run it as `yarn node -e '…'` with the same arguments, so it finds the installed packages. Under a package manager that installs no peer dependencies, a package the project does not list yet is not on disk, so its own peers are not read: add the names it printed, install, and run it again until it prints no name the project does not list.
|
|
457
|
+
|
|
458
|
+
This change alone changes no application code and no generated file. The application lists the platform packages because it may import them: the `facade-paths-an-application-uses` script below sends some imports, those of paths the database package no longer publishes, to `@prisma/orm-framework`, `@prisma/orm-family-sql` and the other platform packages.
|
|
459
|
+
|
|
460
|
+
## The config imports `prisma/config`, and the application does not list the engine
|
|
461
|
+
|
|
462
|
+
### `config-imports-prisma-config`
|
|
463
|
+
|
|
464
|
+
`prisma orm init` used to write `import { definePrismaConfig } from '@prisma/cli-engine';` into `prisma.config.ts` and add `@prisma/cli-engine` to `devDependencies`. The `prisma` command runs on one exact version of that engine and depends on it at that version. The `prisma` package also exports `definePrismaConfig` from `prisma/config`, re-exported from that same engine. Importing it from there means the config is made by the engine the command runs. A line of the application's own for the engine stays where it was written while each release of `prisma` and the ORM toolchain names a new exact engine version. Once they move on, npm refuses to install the project (`ERESOLVE`), and pnpm installs it with the toolchain running on the old engine. So `init` now writes the `prisma/config` import and lists no engine.
|
|
465
|
+
|
|
466
|
+
Do this in each project whose `package.json` lists the `prisma` package, the one that provides the `prisma` command. `prisma` exports `prisma/config` from `8.0.0-rc.9` on; update `prisma` first if the project has an earlier version.
|
|
467
|
+
|
|
468
|
+
1. In each `prisma.config.*` file of that project that imports `definePrismaConfig` from `@prisma/cli-engine`, change that module name to `prisma/config`. If the file imports anything else from `@prisma/cli-engine`, leave the file as it is.
|
|
469
|
+
2. Decide about the `@prisma/cli-engine` line in that `package.json`. Do this step also in a project whose config already imports `prisma/config` but whose `package.json` still lists the engine.
|
|
470
|
+
- Keep the line if the project's own source files, outside `node_modules`, import from `@prisma/cli-engine` or one of its subpaths, such as `import type { CliStructuredError } from '@prisma/cli-engine/protocol'`.
|
|
471
|
+
- Keep the line in a Yarn project whose `.yarnrc.yml` sets `nmHoistingLimits: dependencies`. Yarn then keeps the engine inside `node_modules/prisma`, where the toolchain cannot find it.
|
|
472
|
+
- Otherwise remove the line from `devDependencies` (or `dependencies`), then install.
|
|
473
|
+
|
|
474
|
+
A line you keep names the exact version `@prisma/orm-toolchain` gives for `@prisma/cli-engine` in its `peerDependencies`. Any other version makes npm refuse to install (`ERESOLVE`). If you change the version, install afterwards.
|
|
475
|
+
|
|
476
|
+
```ts
|
|
477
|
+
// prisma.config.ts, before
|
|
478
|
+
import { definePrismaConfig } from '@prisma/cli-engine';
|
|
479
|
+
// after
|
|
480
|
+
import { definePrismaConfig } from 'prisma/config';
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
```diff
|
|
484
|
+
// package.json, when no source file imports the engine and Yarn does not limit hoisting
|
|
485
|
+
"devDependencies": {
|
|
486
|
+
- "@prisma/cli-engine": "^0.10.4",
|
|
487
|
+
"prisma": "^8.0.0-rc.37"
|
|
488
|
+
}
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
Nothing else in the config changes, and `prisma contract emit` produces the same files.
|
|
492
|
+
|
|
493
|
+
Under Yarn, install now reports that the project does not provide `@prisma/cli-engine` to `@prisma/orm-toolchain`. That is expected: the toolchain uses the copy `prisma` brings. Under Yarn Plug'n'Play no `prisma.config.ts` loads today, with either import, so this step changes nothing there.
|
|
494
|
+
|
|
495
|
+
## The database packages publish only what an application uses
|
|
496
|
+
|
|
497
|
+
### `facade-paths-an-application-uses`
|
|
498
|
+
|
|
499
|
+
#### What changed
|
|
500
|
+
|
|
501
|
+
From release 8.0 every path a Generally Available Prisma package publishes is kept until 9.0 (see [the versioning policy](https://github.com/prisma/orm/blob/v8.0.0-rc.26/docs/oss/versioning.md) for each package's level). So each database package (`@prisma/orm-postgres`, `@prisma/orm-sqlite`, `@prisma/orm-mysql`, `@prisma/orm-mariadb`, `@prisma/orm-mongo`) now publishes only what applications and generated files import, where it used to forward the platform packages whole. The platform packages are the packages a database package is built from, and each removed path is still published by one of them, under its own name:
|
|
502
|
+
|
|
503
|
+
- `@prisma/orm-framework`: the contract types, the components and the general helpers.
|
|
504
|
+
- `@prisma/orm-family-sql`, or `@prisma/orm-family-mongo` for MongoDB: the database family's contract, query and migration code.
|
|
505
|
+
- `@prisma/orm-target-<database>`, such as `@prisma/orm-target-postgres`: the target, adapter and driver of one database.
|
|
506
|
+
- `@prisma/orm-toolchain`: the command-line tooling, such as the migration tools.
|
|
507
|
+
|
|
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.
|
|
509
|
+
|
|
510
|
+
#### Where the guide and its script are
|
|
511
|
+
|
|
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:
|
|
513
|
+
|
|
514
|
+
```text
|
|
515
|
+
.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
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
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
|
+
|
|
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.
|
|
521
|
+
|
|
522
|
+
#### Run the script
|
|
523
|
+
|
|
524
|
+
Commit your work first, so the script's changes can be reviewed and undone with git. Then run the script from the folder that holds the skills copy, usually the project root, and give it the folder to work on; `.` is the working directory, which is also the default. With the copy in `.agents/`:
|
|
525
|
+
|
|
526
|
+
```sh
|
|
527
|
+
node .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 .
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
With another copy, replace `.agents` with `.claude`, `.cursor` or `.windsurf`. The script prints each file it changed. For example:
|
|
531
|
+
|
|
532
|
+
```ts
|
|
533
|
+
// before
|
|
534
|
+
import { blindCast } from '@prisma/orm-postgres/utils/casts';
|
|
535
|
+
import { param } from '@prisma/orm-postgres/relational-core/expression';
|
|
536
|
+
import postgresPack from '@prisma/orm-postgres/target/pack';
|
|
537
|
+
|
|
538
|
+
// after the script
|
|
539
|
+
import { blindCast } from '@prisma/orm-framework/utils/casts';
|
|
540
|
+
import { param } from '@prisma/orm-postgres/runtime';
|
|
541
|
+
import postgresPack from '@prisma/orm-postgres/target';
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
#### Change by hand what the script cannot
|
|
545
|
+
|
|
546
|
+
##### A mock of a path the script sent to the database package
|
|
547
|
+
|
|
548
|
+
The script sends three kinds of `import` to the database package's own module:
|
|
549
|
+
|
|
550
|
+
- one that takes only the default of `target/pack` or `family/pack` (PostgreSQL and MongoDB);
|
|
551
|
+
- one that takes only `param` from `relational-core/expression` (PostgreSQL, SQLite, MySQL and MariaDB);
|
|
552
|
+
- one that takes only `isStructuredError` from `utils/structured-error`.
|
|
553
|
+
|
|
554
|
+
A `vi.mock(…)` or `require.resolve(…)` of the same path is not an `import`, so the script sends it to the platform package. `vi.mock` replaces the module its path names, and the code now imports a different module, the database package's, which only re-exports the mocked one; whether the test then sees the mock depends on how the test runner treats that re-export. Change the mock by hand to name the same path as its import, so the mock and the import name one module:
|
|
555
|
+
|
|
556
|
+
```ts
|
|
557
|
+
// after the script
|
|
558
|
+
import postgresPack from '@prisma/orm-postgres/target';
|
|
559
|
+
vi.mock('@prisma/orm-target-postgres/target/pack');
|
|
560
|
+
|
|
561
|
+
// after your change
|
|
562
|
+
import postgresPack from '@prisma/orm-postgres/target';
|
|
563
|
+
vi.mock('@prisma/orm-postgres/target');
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
This command lists each mock or resolve call of those four platform paths. Change the ones whose `import` in the same code now names the database package:
|
|
567
|
+
|
|
568
|
+
```sh
|
|
569
|
+
grep -rnE --include='*.ts' --include='*.mts' --include='*.cts' --include='*.tsx' --include='*.js' --include='*.mjs' --include='*.cjs' --include='*.jsx' --exclude-dir=node_modules --exclude-dir=dist --exclude-dir=build --exclude-dir='.?*' \
|
|
570
|
+
"(mock|doMock|resolve)\\(['\"\`]@prisma/orm-(target-(postgres|mongo)/target/pack|family-(sql|mongo)/family/pack|family-sql/relational-core/expression|framework/utils/structured-error)['\"\`]" *
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
##### Recommended: replace three kinds of platform import
|
|
574
|
+
|
|
575
|
+
Three kinds of import now name a Prisma platform module an application does not need: two helpers that become plain code, and a control stack that becomes `create<Database>ControlClient`. The code builds and runs as it is; replacing them removes a dependency on a Prisma platform helper.
|
|
576
|
+
|
|
577
|
+
A helper from `@prisma/orm-framework/utils/*`. Replace `blindCast` on an ORM input with the plain value: an ORM input takes the same type a query returns for that field, such as a string for a `Uuid` id. Replace `ifDefined` with a spread, and `SimplifyDeep` with the type itself. Nothing changes at run time. A `blindCast` that is not on an ORM input stays, and keeps importing from `@prisma/orm-framework/utils/casts`.
|
|
578
|
+
|
|
579
|
+
```ts
|
|
580
|
+
// before
|
|
581
|
+
orm.User.where({ id: blindCast<UserId, 'the CLI passes a string'>(userId) });
|
|
582
|
+
mongo({ contract, url, ...ifDefined('dbName', options.dbName) });
|
|
583
|
+
type PostsResponse = SimplifyDeep<Awaited<ReturnType<typeof getPosts>>>;
|
|
584
|
+
|
|
585
|
+
// after
|
|
586
|
+
orm.User.where({ id: userId });
|
|
587
|
+
mongo({ contract, url, ...(options.dbName === undefined ? {} : { dbName: options.dbName }) });
|
|
588
|
+
type PostsResponse = Awaited<ReturnType<typeof getPosts>>;
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
An enum helper from `@prisma/orm-framework/contract/enum-accessor`. Use the enum accessor: `db.enums` on the client, with the namespace on PostgreSQL, such as `db.enums.public.Priority`, or the `enums` of the static context, such as `mongoStatic({ contract }).enums`.
|
|
592
|
+
|
|
593
|
+
```ts
|
|
594
|
+
// before
|
|
595
|
+
type Priority = EnumValues<typeof db.enums.public.Priority>;
|
|
596
|
+
setOrderType(blindCast<EnumValues<typeof db.enums.public.OrderType>, 'the form emits members'>(value));
|
|
597
|
+
|
|
598
|
+
// after
|
|
599
|
+
type Priority = (typeof db.enums.public.Priority.values)[number];
|
|
600
|
+
if (db.enums.public.OrderType.has(value)) setOrderType(value);
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
The `has` guard changes behaviour: a value that is not a member is now skipped, where the cast passed it on.
|
|
604
|
+
|
|
605
|
+
A control stack built by hand from `adapter/control`, `driver/control` and `target/control`. The database package's `control` path assembles the same client:
|
|
606
|
+
|
|
607
|
+
```ts
|
|
608
|
+
// after the script
|
|
609
|
+
import { createControlClient } from '@prisma/orm-toolchain/cli/control-api';
|
|
610
|
+
import sql from '@prisma/orm-postgres/family/control';
|
|
611
|
+
import postgres from '@prisma/orm-target-postgres/target/control';
|
|
612
|
+
import postgresAdapter from '@prisma/orm-target-postgres/adapter/control';
|
|
613
|
+
import postgresDriver from '@prisma/orm-target-postgres/driver/control';
|
|
614
|
+
const url = process.env['DATABASE_URL'];
|
|
615
|
+
const client = createControlClient({
|
|
616
|
+
family: sql,
|
|
617
|
+
target: postgres,
|
|
618
|
+
adapter: postgresAdapter,
|
|
619
|
+
driver: postgresDriver,
|
|
620
|
+
...(url === undefined ? {} : { connection: url }),
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
// after your change
|
|
624
|
+
import { createPostgresControlClient } from '@prisma/orm-postgres/control';
|
|
625
|
+
const url = process.env['DATABASE_URL'];
|
|
626
|
+
const client = createPostgresControlClient(url === undefined ? {} : { connection: url });
|
|
627
|
+
```
|
|
628
|
+
|
|
629
|
+
The other databases have `createSqliteControlClient`, `createMysqlControlClient`, `createMariadbControlClient` and `createMongoControlClient`, each from its database package's `control`.
|
|
630
|
+
|
|
631
|
+
##### Keep: the two imports of a PSL default control policy
|
|
632
|
+
|
|
633
|
+
A PostgreSQL config that sets a PSL contract's default control policy builds the contract source itself, because the database package's `defineConfig` has no option for the policy. It imports `prismaContract` from `@prisma/orm-family-sql/contract-psl/provider` and, after the script, `postgresCreateNamespace` from `@prisma/orm-target-postgres/target/types`. Keep both: they are the two platform imports you should not replace by hand.
|
|
634
|
+
|
|
635
|
+
#### List the platform packages in `package.json`
|
|
636
|
+
|
|
637
|
+
A project created before `8.0.0-rc.26` lists none of the platform packages. Apply the `list-the-platform-packages` change in this guide first: it adds every platform package the database package names, so after it the search below finds nothing to add. A project that already lists them still needs the search, since an import may now name a platform package it does not list.
|
|
638
|
+
|
|
639
|
+
The script's imports name platform packages, so the project must list each one it now imports. This command prints the packages the code names; in a monorepo, run it in each project:
|
|
640
|
+
|
|
641
|
+
```sh
|
|
642
|
+
grep -rnoE --include='*.ts' --include='*.mts' --include='*.cts' --include='*.tsx' --include='*.js' --include='*.mjs' --include='*.cjs' --include='*.jsx' --exclude-dir=node_modules --exclude-dir=dist --exclude-dir=build --exclude-dir='.?*' \
|
|
643
|
+
'@prisma/orm-(framework|family-sql|family-mongo|target-[a-z]+|toolchain)' * \
|
|
644
|
+
| sed 's/.*://' | sort -u
|
|
645
|
+
```
|
|
646
|
+
|
|
647
|
+
Add each one that `package.json` does not list yet to the same field as the database package, usually `dependencies`, then reinstall. On the release candidates every package has the database package's version, as the `list-the-platform-packages` change in this guide says:
|
|
648
|
+
|
|
649
|
+
```json
|
|
650
|
+
"dependencies": {
|
|
651
|
+
"@prisma/orm-family-sql": "<version of @prisma/orm-family-sql>",
|
|
652
|
+
"@prisma/orm-framework": "<version of @prisma/orm-framework>"
|
|
653
|
+
}
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
Without them, the type check below reports `TS2307 Cannot find module` for paths that are published.
|
|
657
|
+
|
|
658
|
+
#### Check the result
|
|
659
|
+
|
|
660
|
+
Run this in the folder you ran the script in. It searches the files the script reads, outside folders whose name starts with a dot, for a path the database packages no longer publish. This command lists every `@prisma/orm-<database>/…` path in them, then drops the paths each database package still publishes:
|
|
661
|
+
|
|
662
|
+
```sh
|
|
663
|
+
grep -rnoE --include='*.ts' --include='*.mts' --include='*.cts' --include='*.tsx' --include='*.js' --include='*.mjs' --include='*.cjs' --include='*.jsx' --exclude-dir=node_modules --exclude-dir=dist --exclude-dir=build --exclude-dir='.?*' \
|
|
664
|
+
'@prisma/orm-(postgres|sqlite|mysql|mariadb|mongo)/[A-Za-z0-9_./$-]*' * \
|
|
665
|
+
| grep -vE ':@prisma/orm-postgres/(adapter/column-types|builder/runtime|builder/types|components/runtime|config|contract-builder|contract-types|contract/types|control|family|family-contract/types|family-runtime|family/control|init|migration|migration-tools/aggregate|migration-tools/hash|migration-tools/io|migration-tools/spaces|orm-client|package.json|relational-core/ast|runtime|serverless|static|target|target/codec-ids|target/codec-types|target/full-text|target/migration|target/operation-types|target/planner-target-details|target/runtime|vite-plugin-contract-emit)$|:@prisma/orm-sqlite/(adapter/codec-types|adapter/column-types|builder/runtime|builder/types|components/runtime|config|contract-builder|contract-types|contract/types|control|family-contract/types|family-runtime|family/control|init|migration|migration-tools/aggregate|migration-tools/hash|migration-tools/io|migration-tools/spaces|orm-client|package.json|relational-core/ast|runtime|static|target/codec-ids|target/codec-types|target/migration|target/planner-target-details|target/runtime|vite-plugin-contract-emit)$|:@prisma/orm-mysql/(adapter/codec-types|builder/runtime|builder/types|components/runtime|config|contract-builder|contract-types|contract/types|control|define-contract|family-contract/types|family-runtime|family/control|init|migration|migration-tools/aggregate|migration-tools/hash|migration-tools/io|migration-tools/spaces|orm-client|package.json|relational-core/ast|runtime|static|target/codec-ids|target/codec-types|target/migration|target/runtime|vite-plugin-contract-emit)$|:@prisma/orm-mariadb/(adapter/codec-types|builder/runtime|builder/types|components/runtime|config|contract-builder|contract-types|contract/types|control|family-contract/types|family-runtime|family/control|migration|migration-tools/aggregate|migration-tools/hash|migration-tools/io|migration-tools/spaces|orm-client|package.json|relational-core/ast|runtime|static|target/migration|target/runtime|vite-plugin-contract-emit)$|:@prisma/orm-mongo/(bson|components/runtime|config|contract-builder|contract-types|contract/types|control|family|family-contract|family-runtime|family/control|init|migration|migration-tools/aggregate|migration-tools/hash|migration-tools/io|migration-tools/spaces|orm|package.json|query-ast/execution|query-builder|runtime|static|target|target/codec-ids|target/codec-types|target/migration|target/runtime|value|vite-plugin-contract-emit)$'
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
Each line it prints is a file, a line and a path that is no longer published. A template literal with `${…}` in it shows as a path that ends at `$`, and a path built from parts shows as its first part. Change each one by the reference below. Two kinds of line the reference does not cover:
|
|
669
|
+
|
|
670
|
+
- `@prisma/orm-postgres/adapter/operation-types` in a stored migration snapshot comes from a release before `8.0.0-rc.12`, which removed that path. The script leaves it. Leave it too, or point it at `@prisma/orm-postgres/target/operation-types`.
|
|
671
|
+
- An `@prisma/orm-postgres/internal/…` path, or a `family-runtime/internal/prepared-query` path, named internals that were there only for the Supabase extension, and another change removes them. An application has no replacement for them; the extension guide's `postgres-client-parts-early-access-names` change lists the Early Access names that replace them for an extension.
|
|
672
|
+
|
|
673
|
+
Then run the type check, such as `tsc --noEmit`: an import of a path that is no longer published fails with `TS2307 Cannot find module`.
|
|
674
|
+
|
|
675
|
+
#### Reference
|
|
676
|
+
|
|
677
|
+
##### The paths that stay
|
|
678
|
+
|
|
679
|
+
Each database package still publishes these paths, and the script leaves them. The bare `target` and `family` exist only on PostgreSQL and MongoDB: each default-exports a pack, the object that describes the target or the family to the contract builder, `target` the database's and `family` its family's. `package.json` always stays. MariaDB has no `init`, the module `prisma orm init` loads for a database: its package does not publish one, so the missing `yes` is not a mistake.
|
|
680
|
+
|
|
681
|
+
| Path | PostgreSQL | SQLite | MySQL | MariaDB | MongoDB |
|
|
682
|
+
| --- | --- | --- | --- | --- | --- |
|
|
683
|
+
| `adapter/codec-types` | | yes | yes | yes | |
|
|
684
|
+
| `adapter/column-types` | yes | yes | | | |
|
|
685
|
+
| `bson` | | | | | yes |
|
|
686
|
+
| `builder/runtime` | yes | yes | yes | yes | |
|
|
687
|
+
| `builder/types` | yes | yes | yes | yes | |
|
|
688
|
+
| `components/runtime` | yes | yes | yes | yes | yes |
|
|
689
|
+
| `config` | yes | yes | yes | yes | yes |
|
|
690
|
+
| `contract-builder` | yes | yes | yes | yes | yes |
|
|
691
|
+
| `contract-types` | yes | yes | yes | yes | yes |
|
|
692
|
+
| `contract/types` | yes | yes | yes | yes | yes |
|
|
693
|
+
| `control` | yes | yes | yes | yes | yes |
|
|
694
|
+
| `define-contract` | | | yes | | |
|
|
695
|
+
| `family` | yes | | | | yes |
|
|
696
|
+
| `family-contract` | | | | | yes |
|
|
697
|
+
| `family-contract/types` | yes | yes | yes | yes | |
|
|
698
|
+
| `family-runtime` | yes | yes | yes | yes | yes |
|
|
699
|
+
| `family/control` | yes | yes | yes | yes | yes |
|
|
700
|
+
| `init` | yes | yes | yes | | yes |
|
|
701
|
+
| `migration` | yes | yes | yes | yes | yes |
|
|
702
|
+
| `migration-tools/aggregate` | yes | yes | yes | yes | yes |
|
|
703
|
+
| `migration-tools/hash` | yes | yes | yes | yes | yes |
|
|
704
|
+
| `migration-tools/io` | yes | yes | yes | yes | yes |
|
|
705
|
+
| `migration-tools/spaces` | yes | yes | yes | yes | yes |
|
|
706
|
+
| `orm` | | | | | yes |
|
|
707
|
+
| `orm-client` | yes | yes | yes | yes | |
|
|
708
|
+
| `query-ast/execution` | | | | | yes |
|
|
709
|
+
| `query-builder` | | | | | yes |
|
|
710
|
+
| `relational-core/ast` | yes | yes | yes | yes | |
|
|
711
|
+
| `runtime` | yes | yes | yes | yes | yes |
|
|
712
|
+
| `serverless` | yes | | | | |
|
|
713
|
+
| `static` | yes | yes | yes | yes | yes |
|
|
714
|
+
| `target` | yes | | | | yes |
|
|
715
|
+
| `target/codec-ids` | yes | yes | yes | | yes |
|
|
716
|
+
| `target/codec-types` | yes | yes | yes | | yes |
|
|
717
|
+
| `target/full-text` | yes | | | | |
|
|
718
|
+
| `target/migration` | yes | yes | yes | yes | yes |
|
|
719
|
+
| `target/operation-types` | yes | | | | |
|
|
720
|
+
| `target/planner-target-details` | yes | yes | | | |
|
|
721
|
+
| `target/runtime` | yes | yes | yes | yes | yes |
|
|
722
|
+
| `value` | | | | | yes |
|
|
723
|
+
| `vite-plugin-contract-emit` | yes | yes | yes | yes | yes |
|
|
724
|
+
|
|
725
|
+
##### What the script writes
|
|
726
|
+
|
|
727
|
+
The script:
|
|
728
|
+
|
|
729
|
+
- rewrites only a path that release `8.0.0-rc.25` published and this change removes. It leaves every other path: one an older release removed, and the `internal/…` paths that the `postgres-client-parts-early-access-names` change in the extension authors' guide for this release removes.
|
|
730
|
+
- changes every string that is exactly such a path, in single quotes, double quotes, or backticks with nothing interpolated, wherever it is in the file, and edits nothing else.
|
|
731
|
+
- cannot rewrite a path built from parts.
|
|
732
|
+
|
|
733
|
+
The paths below are under `@prisma/orm-<database>/`, and each row skips the paths that stay.
|
|
734
|
+
|
|
735
|
+
The first three rows apply to an `import` statement that takes exactly that one name. An import that takes more names, and a `vi.mock` or `require.resolve` of the path, follow the later rows.
|
|
736
|
+
|
|
737
|
+
| Removed path | Its replacement | Example |
|
|
738
|
+
| --- | --- | --- |
|
|
739
|
+
| `relational-core/expression`, imported for `param` alone (PostgreSQL, SQLite, MySQL and MariaDB) | `@prisma/orm-<database>/runtime`, which re-exports `param` | `import { param } from '@prisma/orm-mysql/relational-core/expression'` becomes `import { param } from '@prisma/orm-mysql/runtime'` |
|
|
740
|
+
| `utils/structured-error`, imported for `isStructuredError` alone | `@prisma/orm-<database>/runtime`, which re-exports `isStructuredError` | `import { isStructuredError } from '@prisma/orm-postgres/utils/structured-error'` becomes `import { isStructuredError } from '@prisma/orm-postgres/runtime'` |
|
|
741
|
+
| `target/pack` or `family/pack`, imported for its default alone (PostgreSQL and MongoDB) | the bare `@prisma/orm-<database>/target` or `@prisma/orm-<database>/family`, whose default export is the same pack | `import pack from '@prisma/orm-postgres/target/pack'` becomes `import pack from '@prisma/orm-postgres/target'` |
|
|
742
|
+
| under `adapter/`, `driver/` and `target/` | the same path in `@prisma/orm-target-<database>` | `@prisma/orm-postgres/target/types` becomes `@prisma/orm-target-postgres/target/types`; `@prisma/orm-mariadb/adapter/control` becomes `@prisma/orm-target-mariadb/adapter/control` |
|
|
743
|
+
| under `components/`, `contract/` and `utils/` | the same path in `@prisma/orm-framework` | `@prisma/orm-postgres/utils/casts` becomes `@prisma/orm-framework/utils/casts` |
|
|
744
|
+
| under `family-contract/` | the family package, with `family-contract` renamed to `contract`; `canonicalization-hooks` goes to `contract/normal-form`, its name in this release, where `normalizeSqlStorage` or `normalizeMongoStorage` replaces the old hooks object (see the `contract-hash-inputs` change) | `@prisma/orm-postgres/family-contract/index-types` becomes `@prisma/orm-family-sql/contract/index-types`; `@prisma/orm-mongo/family-contract/data-type` becomes `@prisma/orm-family-mongo/contract/data-type` |
|
|
745
|
+
| under `family/` | the same path in `@prisma/orm-family-sql`, or `@prisma/orm-family-mongo` for MongoDB | `@prisma/orm-postgres/family/pack` becomes `@prisma/orm-family-sql/family/pack`; `@prisma/orm-mongo/family/ir` becomes `@prisma/orm-family-mongo/family/ir` |
|
|
746
|
+
| under `builder/`, `relational-core/` and `schema-ir/` (PostgreSQL, SQLite, MySQL and MariaDB) | the same path in `@prisma/orm-family-sql` | `@prisma/orm-sqlite/relational-core/plan` becomes `@prisma/orm-family-sql/relational-core/plan` |
|
|
747
|
+
| under `query-ast/`, `query-builder/` and `value/` (MongoDB) | the same path in `@prisma/orm-family-mongo` | `@prisma/orm-mongo/query-ast/control` becomes `@prisma/orm-family-mongo/query-ast/control` |
|
|
748
|
+
| `migration-tools/contract-snapshot-store` | the same path in `@prisma/orm-toolchain` | `@prisma/orm-postgres/migration-tools/contract-snapshot-store` becomes `@prisma/orm-toolchain/migration-tools/contract-snapshot-store`. The `platform-paths-an-extension-uses` change, in the same release, then stops publishing that path; its guide says what to do |
|
|
749
|
+
|
|
750
|
+
A row also covers its folder's own path, with no subpath, where the database package published one:
|
|
751
|
+
|
|
752
|
+
- On PostgreSQL, SQLite, MySQL and MariaDB: `adapter`, `builder`, `components`, `contract`, `driver`, `family-contract`, `relational-core` and `utils`.
|
|
753
|
+
- On MongoDB: `adapter`, `components`, `contract`, `driver`, `query-ast` and `utils`.
|
|
754
|
+
|
|
755
|
+
## The platform packages publish only the paths extensions use
|
|
756
|
+
|
|
757
|
+
### `platform-paths-an-extension-uses`
|
|
758
|
+
|
|
759
|
+
#### What changed
|
|
760
|
+
|
|
761
|
+
From release 8.0 every path and name a Generally Available Prisma package publishes is kept until 9.0, except a name that starts with a maturity level (`ea_`, `preview_` or `rc_`, or `Ea_`, `Preview_` or `Rc_` for a type or a class), which may still change in a later release. An Early Access package, such as `@prisma/orm-sqlite`, makes no such promise (see [the versioning policy](https://github.com/prisma/orm/blob/v8.0.0-rc.26/docs/oss/versioning.md)). An application imports from its database package, such as `@prisma/orm-postgres`, but the `facade-paths-an-application-uses` change in the same release sends some of its imports to the platform packages, the packages a database package is built from. Those packages now stop publishing the paths that nothing outside their own package imported:
|
|
762
|
+
|
|
763
|
+
- `@prisma/orm-framework`: `contract/resolve-domain-model`, `psl-parser/tokenizer`, and the package-level paths `utils`, `type-implementations` and `target-package-config`. Each module under them, such as `utils/casts`, is still published.
|
|
764
|
+
- `@prisma/orm-family-sql`: `contract/authored-check-naming`, `contract/factories`, `contract/index-type-validation`, `contract/validators`, `contract-emitter`, `contract-psl`, `contract-psl/attribute-specs`, `contract-psl/default-table-name`, `contract-psl/diagnostics`, `relational-core/functions`, `relational-core/middleware`, and the package-level paths `builder`, `contract-ts`, `family` and `schema-ir`.
|
|
765
|
+
- `@prisma/orm-target-postgres`: `adapter/sql-renderer`, `adapter/types`, twenty `target/…` paths, such as `target/planner`, `target/ddl` and `target/op-factory-call`, and the package-level paths `target` and `adapter`.
|
|
766
|
+
- `@prisma/orm-toolchain`: `cli/control-api/testing`, `cli/init-output`, `cli-telemetry`, `cli-telemetry/sender`, `emitter`, `emitter/type-expression-safety`, and seven `migration-tools/…` paths, such as `migration-tools/contract-snapshot-store` and `migration-tools/errors`.
|
|
767
|
+
|
|
768
|
+
Two package-level paths stay but export fewer names: `@prisma/orm-family-sql/contract` and `@prisma/orm-toolchain/migration-tools` now export only the names of the paths their package still publishes.
|
|
769
|
+
|
|
770
|
+
Since release 8.0.0-rc.25, `@prisma/orm-family-sql/contract` no longer exports 41 names. `checkSqlDefaultText` is published at `@prisma/orm-family-sql/family/control`. `sqlContractCanonicalizationHooks` went in the `contract-hash-inputs` change, in the same release, which says what replaces it. These 39 are not published anywhere: `AuthoredCheckInput`, `CheckConstraintSchema`, `CodecTraitsLookup`, `col`, `ColumnDefaultFunctionSchema`, `ColumnDefaultLiteralSchema`, `ColumnDefaultSchema`, `ContractEnumSchema`, `createNamespaceEntrySchema`, `createSqlContractSchema`, `createSqlStorageSchema`, `fk`, `ForeignKeyReferenceSchema`, `ForeignKeySchema`, `ForeignKeySourceSchema`, `index`, `IndexSchema`, `lowerAuthoredCheck`, `model`, `pk`, `ReferentialActionSchema`, `reservedSqlDefaultText`, `resolveSqlToOneRelationStorage`, `SqlToOneRelationStorage`, `StorageTableSchema`, `StorageValueSetSchema`, `table`, `unique`, `validateExecutionDefaultsTargetMappedColumns`, `validateIndexTypes`, `validateModel`, `validateModelStorageReferences`, `validateRelationJoinFields`, `validateSqlContractFully`, `ValidateSqlContractFullyOptions`, `validateSqlStorageConsistency`, `validateStorage`, `validateStorageSemantics`, `valueObjectStorageTypeMissingMessage`.
|
|
771
|
+
|
|
772
|
+
Where a kept path exports the same declaration, the script sends the import there: `Migration` from `@prisma/orm-target-postgres/target` goes to `target/migration`, `RlsPolicyOperation` from `target/ddl` to `target/rls-canonicalize`, `checkSqlDefaultText` from `@prisma/orm-family-sql/contract` to `family/control`, and `createFunctions` from `relational-core/functions` to `@prisma/orm-family-sql/builder/runtime`. About 570 names, such as the PostgreSQL planner, its DDL nodes and the migration graph tools, are no longer published.
|
|
773
|
+
|
|
774
|
+
Some names were also renamed, because "internal" says "not for you" while every published name is promised like any other:
|
|
775
|
+
|
|
776
|
+
| Before | After |
|
|
777
|
+
| --- | --- |
|
|
778
|
+
| `InternalError`, `isInternalError` and `assertNever` from `@prisma/orm-framework/utils/internal-error` | `InvariantError`, `isInvariantError` and `assertNever` from `@prisma/orm-framework/utils/invariant-error` |
|
|
779
|
+
| The `isPrismaInternalError` field of an `InternalError` | The `isPrismaInvariantError` field of an `InvariantError` |
|
|
780
|
+
| `PreparedStatementInternals` from `@prisma/orm-family-sql/runtime` | `LoweredPreparedStatement` |
|
|
781
|
+
| `SqlParamRefMutatorInternal` from `@prisma/orm-family-sql/relational-core` | `SqlRuntimeParamRefMutator` |
|
|
782
|
+
| `MongoParamRefMutatorInternal` from `@prisma/orm-family-mongo/runtime` | `MongoRuntimeParamRefMutator` |
|
|
783
|
+
| `SupabaseInternalDb` from `@prisma/orm-extension-supabase/runtime` | `SupabaseSchemasDb` |
|
|
784
|
+
| `SupabaseExtensionContract` from `@prisma/orm-extension-supabase/runtime` | `SupabaseSchemasContract` |
|
|
785
|
+
|
|
786
|
+
An `InvariantError` from this release has only the new field, and its `name` is `'InvariantError'`, so a check for `isPrismaInternalError` or for `error.name === 'InternalError'` no longer recognises it. To recognise it, call `isInvariantError(error)`.
|
|
787
|
+
|
|
788
|
+
#### Run the scripts
|
|
789
|
+
|
|
790
|
+
Run the `facade-paths-an-application-uses` script first, then this one, which takes in what it wrote. This guide's script sits beside it in the agent skills copy of the `prisma-8` skill, for example:
|
|
791
|
+
|
|
792
|
+
```text
|
|
793
|
+
.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
|
|
794
|
+
```
|
|
795
|
+
|
|
796
|
+
Commit your work first, so the script's changes can be reviewed and undone with git. Then run it from the folder that holds the skills copy, and give it the folder to work on; `.` is the working directory, which is also the default:
|
|
797
|
+
|
|
798
|
+
```sh
|
|
799
|
+
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
|
+
```
|
|
801
|
+
|
|
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.
|
|
803
|
+
|
|
804
|
+
The script:
|
|
805
|
+
|
|
806
|
+
- sends each named import, type-only import and `export { … } from` to the kept path that exports the same declaration, splitting an import whose names now live on different paths:
|
|
807
|
+
|
|
808
|
+
```ts
|
|
809
|
+
// Before:
|
|
810
|
+
import { createFunctions, type Functions } from '@prisma/orm-family-sql/relational-core/functions';
|
|
811
|
+
// After:
|
|
812
|
+
import { createFunctions } from '@prisma/orm-family-sql/builder/runtime';
|
|
813
|
+
import { type Functions } from '@prisma/orm-family-sql/builder/types';
|
|
814
|
+
```
|
|
815
|
+
- moves a namespace import, an `export *`, a side-effect import, a dynamic `import()`, a `require` or an `import()` type only when one path publishes everything the old one did. It moves a dynamic `import()` or a `require` and lists it, so you check the names it uses.
|
|
816
|
+
- renames each name in the table above where it came from a Prisma import: the import itself, every use of that binding in the file, and `ns.InternalError` on a namespace binding. A file that does not import it is left alone, even if it has its own name of that spelling.
|
|
817
|
+
- in a file that re-exports a renamed name, keeps the name the file exports (`export { InvariantError as InternalError } from '…/utils/invariant-error'`), so the files that import from it still compile, and lists the file.
|
|
818
|
+
- renames the `isPrismaInternalError` field in a file that imports from a Prisma package, and a check of an error's `name` against `'InternalError'`, in a comparison or a `case`, in a file that imports `InternalError` or `isInternalError` from Prisma. Elsewhere it lists them, because `InternalError` may be the project's own error.
|
|
819
|
+
- prints each file it changed, then, under `Not changed:`, each import it left and each place it wants checked.
|
|
820
|
+
|
|
821
|
+
The script reads only source files. Rename the old names in your Markdown and other docs by hand.
|
|
822
|
+
|
|
823
|
+
#### What the script lists
|
|
824
|
+
|
|
825
|
+
- 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
|
+
- 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
|
+
- 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.
|
|
829
|
+
- 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
|
+
- 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
|
+
|
|
832
|
+
Code that called the emitter or the PSL interpreter directly, usually an extension's test of its own contributions, goes through the control client instead, and the script prints this advice beside each of those names. Give the database package's `defineConfig` the contract: the path of a `.prisma` or `.ts` file, or a contract built in memory, passed through `typescriptContract(contract)` from `@prisma/orm-family-sql/contract-ts/config-types`. Then pass the `source`, `output` and `typesModule` of the config's contract to the control client's `emit`. In a test, the database package is a development dependency:
|
|
833
|
+
|
|
834
|
+
```ts
|
|
835
|
+
import assert from 'node:assert/strict';
|
|
836
|
+
import { typescriptContract } from '@prisma/orm-family-sql/contract-ts/config-types';
|
|
837
|
+
import { defineConfig } from '@prisma/orm-postgres/config';
|
|
838
|
+
import { createPostgresControlClient } from '@prisma/orm-postgres/control';
|
|
839
|
+
import { contract } from './contract';
|
|
840
|
+
|
|
841
|
+
const config = defineConfig({ contract: typescriptContract(contract) });
|
|
842
|
+
const contractConfig = config.contract;
|
|
843
|
+
assert(contractConfig?.typesModule !== undefined, 'the config has no contract');
|
|
844
|
+
|
|
845
|
+
const client = createPostgresControlClient();
|
|
846
|
+
try {
|
|
847
|
+
const emitted = await client.emit({
|
|
848
|
+
contractConfig: {
|
|
849
|
+
source: contractConfig.source,
|
|
850
|
+
output: contractConfig.output ?? 'contract.json',
|
|
851
|
+
typesModule: contractConfig.typesModule,
|
|
852
|
+
},
|
|
853
|
+
});
|
|
854
|
+
if (!emitted.ok) assert.fail(emitted.failure.summary);
|
|
855
|
+
const { contractJson } = emitted.value;
|
|
856
|
+
|
|
857
|
+
const rendered = await client.renderContractDts({
|
|
858
|
+
contract: JSON.parse(contractJson),
|
|
859
|
+
typesModule: contractConfig.typesModule,
|
|
860
|
+
});
|
|
861
|
+
if (!rendered.ok) assert.fail(rendered.failure.summary);
|
|
862
|
+
} finally {
|
|
863
|
+
await client.close();
|
|
864
|
+
}
|
|
865
|
+
```
|
|
866
|
+
|
|
867
|
+
The example is for PostgreSQL. Each database package has its own `defineConfig` in `config` and its own control client in `control`; MongoDB takes its `typescriptContract` from its own family package:
|
|
868
|
+
|
|
869
|
+
| Database | Control client | `typescriptContract` from |
|
|
870
|
+
| --- | --- | --- |
|
|
871
|
+
| PostgreSQL | `createPostgresControlClient` from `@prisma/orm-postgres/control` | `@prisma/orm-family-sql/contract-ts/config-types` |
|
|
872
|
+
| SQLite | `createSqliteControlClient` from `@prisma/orm-sqlite/control` | `@prisma/orm-family-sql/contract-ts/config-types` |
|
|
873
|
+
| MySQL | `createMysqlControlClient` from `@prisma/orm-mysql/control` | `@prisma/orm-family-sql/contract-ts/config-types` |
|
|
874
|
+
| MariaDB | `createMariadbControlClient` from `@prisma/orm-mariadb/control` | `@prisma/orm-family-sql/contract-ts/config-types` |
|
|
875
|
+
| MongoDB | `createMongoControlClient` from `@prisma/orm-mongo/control` | `@prisma/orm-family-mongo/contract-ts/config-types` |
|
|
876
|
+
|
|
877
|
+
The script names the project's own database package when its `package.json` lists exactly one. A test of an extension's contributions passes the extension's descriptors as `extensions` to both `defineConfig` and `createPostgresControlClient`. Each removed name maps to a part of this example:
|
|
878
|
+
|
|
879
|
+
| Before | After |
|
|
880
|
+
| --- | --- |
|
|
881
|
+
| `emit(…)` from `@prisma/orm-toolchain/emitter` | the client's `emit`, whose result carries `contractJson` and `contractDts`, the declarations `emit` wrote |
|
|
882
|
+
| `interpretPslDocumentToSqlContract(…)` from `@prisma/orm-family-sql/contract-psl` | the client's `emit`, with the path of the `.prisma` file as the `contract` of `defineConfig` |
|
|
883
|
+
| `generateContractDts(…)` from `@prisma/orm-toolchain/emitter` | the client's `renderContractDts`, given the parsed `contract.json` and the config's `typesModule` |
|
|
884
|
+
| `getEmittedArtifactPaths(…)` from `@prisma/orm-toolchain/emitter` | no call: the `.d.ts` is written beside the `.json`, and its path is the `.json` path with the `.json` extension replaced by `.d.ts` |
|
|
885
|
+
|
|
886
|
+
Every other name that is no longer published was a part of how Prisma builds itself. For a type, write the type your code needs in your own code; for `BuiltinFunctions`, the published `Functions` type from `@prisma/orm-family-sql/builder/types` covers the built-in functions and the extensions' functions together. For a function, copy what your application uses into it, or open an issue on the Prisma repository that says what you need it for, so we can decide whether to publish it.
|
|
887
|
+
|
|
888
|
+
#### Check the result
|
|
889
|
+
|
|
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.
|
|
891
|
+
|
|
892
|
+
## `contract-types` exports types only
|
|
893
|
+
|
|
894
|
+
### `contract-types-exports-types-only`
|
|
895
|
+
|
|
896
|
+
`contract-types` is the entry a generated `contract.d.ts` imports its types from. At run time it exports nothing. Its type declarations used to say it also exported runtime values, such as `coreHash` or `CODEC_INSTANCE_KIND`, so this compiled and then failed when the module loaded, with `SyntaxError: The requested module '@prisma/orm-postgres/contract-types' does not provide an export named 'coreHash'`:
|
|
897
|
+
|
|
898
|
+
```ts
|
|
899
|
+
import { coreHash } from '@prisma/orm-postgres/contract-types';
|
|
900
|
+
```
|
|
901
|
+
|
|
902
|
+
It now fails to compile: `error TS1362: 'coreHash' cannot be used as a value because it was exported using 'export type'`. Code that worked before still compiles: importing a type, and `typeof coreHash`, are unchanged.
|
|
903
|
+
|
|
904
|
+
In each file the detection matches, look at each import from `contract-types`:
|
|
905
|
+
|
|
906
|
+
- If it imports only types, nothing changes. You may write it as `import type`.
|
|
907
|
+
- If the compiler reports a name in it as a value, import that name from the path of the same database package that exports it. Look for the name in `contract/types`, then in `family-contract/types` (on MongoDB, `family-contract`). No value comes from the codec types entry. Keep the type names in the `contract-types` import.
|
|
908
|
+
|
|
909
|
+
```ts
|
|
910
|
+
// before
|
|
911
|
+
import { coreHash, type Contract } from '@prisma/orm-postgres/contract-types';
|
|
912
|
+
// after
|
|
913
|
+
import type { Contract } from '@prisma/orm-postgres/contract-types';
|
|
914
|
+
import { coreHash } from '@prisma/orm-postgres/contract/types';
|
|
915
|
+
```
|
|
916
|
+
|
|
917
|
+
Run the type checker after the `facade-paths-an-application-uses` script, so the paths you write are ones the database package still publishes.
|
|
918
|
+
|
|
919
|
+
## The contract marker is now the contract signature
|
|
920
|
+
|
|
921
|
+
Each database records, per contract space, which contract it was last signed with: the contract's hashes, when it was signed, and the invariants it holds. Prisma called this record the contract marker; it is now the contract signature, after `db sign`, the command that writes it. Every name that carried the old word now says signature.
|
|
922
|
+
|
|
923
|
+
If you do nothing:
|
|
924
|
+
|
|
925
|
+
- A CI step or script that runs `prisma db verify --marker-only` fails, because the command no longer knows that flag.
|
|
926
|
+
- Code that matches an error code such as `CONTRACT.MARKER_MISSING` or `MIGRATION.MARKER_MISMATCH` stops matching, because Prisma raises `CONTRACT.SIGNATURE_MISSING` and `MIGRATION.SIGNATURE_NOT_IN_GRAPH`. A runtime warning filter on those codes stops filtering.
|
|
927
|
+
- A `log` that filters or routes the client's warnings by their scope, `marker-verification`, stops matching them: the scope is now `contract-signature-verification`.
|
|
928
|
+
- Code or a `jq` filter that reads `marker` or `markerHash` from a command's `--json` output reads `undefined` or `null`.
|
|
929
|
+
- Code that uses the control API's `readMarker`, `readAllMarkers` or the `skipMarker` option no longer type-checks.
|
|
930
|
+
- In TypeScript, `verifyMarker: false` on a client no longer type-checks. In JavaScript, or a project that does not type-check, it is ignored without an error, and the check the client makes on its first use of the database comes back on.
|
|
931
|
+
|
|
932
|
+
The new word renames no table, column, row, lock or grant by itself. Other changes of this release do move Prisma's own tables: on PostgreSQL to `prisma.signatures` and `prisma.config`, which a role other than their owner needs a new grant to read (`prisma-tables-move-to-prisma-schema`, `name-the-prisma-schema`), and on SQLite to `prisma_signatures`, `prisma_config` and `prisma_ledger` (`sqlite-prisma-tables-renamed`). On MySQL and MariaDB the table is still named `_prisma_marker`.
|
|
933
|
+
|
|
934
|
+
### `contract-signature-flag`, `contract-signature-error-codes`, `contract-signature-json-fields`, `contract-signature-published-names`
|
|
935
|
+
|
|
936
|
+
#### What changed
|
|
937
|
+
|
|
938
|
+
| Before | Now |
|
|
939
|
+
| --- | --- |
|
|
940
|
+
| `db verify --marker-only` | `db verify --signature-only` |
|
|
941
|
+
| `CONTRACT.MARKER_MISSING`, `CONTRACT.MARKER_MISMATCH`, `CONTRACT.MARKER_READ_FAILED`, `CONTRACT.MARKER_ROW_CORRUPT` | `CONTRACT.SIGNATURE_MISSING`, `CONTRACT.SIGNATURE_MISMATCH`, `CONTRACT.SIGNATURE_READ_FAILED`, `CONTRACT.SIGNATURE_ROW_CORRUPT` |
|
|
942
|
+
| `MIGRATION.MARKER_LOCK_TIMEOUT`, `MIGRATION.MARKER_ORIGIN_MISMATCH` | `MIGRATION.SIGNATURE_LOCK_TIMEOUT`, `MIGRATION.SIGNATURE_ORIGIN_MISMATCH` |
|
|
943
|
+
| `MIGRATION.MARKER_MISMATCH` (`db migrate`) and `MIGRATION.MARKER_NOT_IN_HISTORY` (`migration status`) | one code for the one condition, `MIGRATION.SIGNATURE_NOT_IN_GRAPH`: an error from `db migrate`, a warning from `migration status` |
|
|
944
|
+
| the `meta` of `migration status`'s warning for a signature outside the migration graph: `space` | `spaceId`, as in `db migrate`'s error with the same code |
|
|
945
|
+
| `MIGRATION.MARKER_CAS_FAILURE` | `MIGRATION.CONCURRENT_CHANGE`: another process changed the contract signature or the database's policies during the run |
|
|
946
|
+
| `CONTRACT.MARKER_REQUIRED`, `CONFIG.FAMILY_READ_MARKER_REQUIRED` | gone: no command raised them |
|
|
947
|
+
| `--json` field `marker` (`db verify`, `db init`, `db update`, and each `perSpace` entry of `db init`, `db update` and `db migrate`) | `signature` |
|
|
948
|
+
| `--json` field `markerHash` (`db migrate`) | `signatureHash` |
|
|
949
|
+
| `--json` mode `marker-only` (`db verify`) | `signature-only` |
|
|
950
|
+
| error value `orphanMarker` (a contract space violation's `kind`), `markerChanged` (the `reason` of `MIGRATION.CONCURRENT_CHANGE`) | `orphanSignature`, `signatureChanged` |
|
|
951
|
+
| `scope` of the client's warnings about the contract signature, `marker-verification` | `contract-signature-verification` |
|
|
952
|
+
| control API: `readMarker`, `readAllMarkers`, the `db verify` option `skipMarker` | `readSignature`, `readAllSignatures`, `skipSignature` |
|
|
953
|
+
| client option `verifyMarker`, its type `VerifyMarkerOption` | `verifyContractSignature`, `VerifyContractSignatureOption` |
|
|
954
|
+
|
|
955
|
+
The client option turns on or off the check the client makes, on its first use of the database, of the database's contract signature against the contract the application carries; `false` turns it off, as `verifyMarker: false` did. It is not named `verifySignature`, because beside options such as `jwtSecret` on `supabase()` that would read as checking a cryptographic signature.
|
|
956
|
+
|
|
957
|
+
Each renamed name the script renames, in a file that imports it or uses it as a member:
|
|
958
|
+
|
|
959
|
+
| Before | Now |
|
|
960
|
+
| --- | --- |
|
|
961
|
+
| `acquireMarkerLock` | `acquireSignatureLock` |
|
|
962
|
+
| `bootstrapSignMarkerQueries` | `bootstrapSignQueries` |
|
|
963
|
+
| `buildSignMarkerBootstrapQueries` | `buildSignBootstrapQueries` |
|
|
964
|
+
| `contractHashAtMarker` | `contractHashAtSignature` |
|
|
965
|
+
| `ContractMarkerRecord` | `ContractSignatureRecord` |
|
|
966
|
+
| `ContractMarkerRecordLike` | `ContractSignatureRecordLike` |
|
|
967
|
+
| `ContractMarkerRow` | `ContractSignatureRow` |
|
|
968
|
+
| `currentMarker` | `currentSignature` |
|
|
969
|
+
| `currentMarkerHash` | `currentSignatureHash` |
|
|
970
|
+
| `currentMarkerInvariants` | `currentSignatureInvariants` |
|
|
971
|
+
| `currentMarkerStorageHash` | `currentSignatureStorageHash` |
|
|
972
|
+
| `databaseMarkerHashBySpace` | `databaseSignatureHashBySpace` |
|
|
973
|
+
| `errorHashMismatch` | `errorSignatureMismatch` |
|
|
974
|
+
| `errorMarkerMissing` | `errorSignatureMissing` |
|
|
975
|
+
| `errorMarkerReadFailed` | `errorSignatureReadFailed` |
|
|
976
|
+
| `errorMarkerRowCorrupt` | `errorSignatureRowCorrupt` |
|
|
977
|
+
| `holdMarkerLock` | `holdSignatureLock` |
|
|
978
|
+
| `initMarker` | `initSignature` |
|
|
979
|
+
| `insertMarker` | `insertSignature` |
|
|
980
|
+
| `lockMarker` | `lockSignature` |
|
|
981
|
+
| `MARKER_LOCK_TIMEOUT_SECONDS` | `SIGNATURE_LOCK_TIMEOUT_SECONDS` |
|
|
982
|
+
| `markerCheck` | `signatureCheck` |
|
|
983
|
+
| `MarkerCheckResult` | `ContractSignatureCheckResult` |
|
|
984
|
+
| `MarkerCheckSection` | `ContractSignatureCheckSection` |
|
|
985
|
+
| `MarkerDestination` | `ContractSignatureDestination` |
|
|
986
|
+
| `markerDrift` | `signatureDrift` |
|
|
987
|
+
| `markerHash` | `signatureHash` |
|
|
988
|
+
| `MarkerHashes` | `ContractSignatureHashes` |
|
|
989
|
+
| `MarkerInsert` | `ContractSignatureInsert` |
|
|
990
|
+
| `markerInvariants` | `signatureInvariants` |
|
|
991
|
+
| `markerLocation` | `signatureLocation` |
|
|
992
|
+
| `MarkerOperations` | `ContractSignatureOperations` |
|
|
993
|
+
| `markerOps` | `signatureOps` |
|
|
994
|
+
| `MarkerReader` | `ContractSignatureReader` |
|
|
995
|
+
| `markerReader` | `signatureReader` |
|
|
996
|
+
| `MarkerReadResult` | `ContractSignatureReadResult` |
|
|
997
|
+
| `markerRowsBySpace` | `signatureRowsBySpace` |
|
|
998
|
+
| `markersBySpaceId` | `signaturesBySpaceId` |
|
|
999
|
+
| `MarkerSwapFailure` | `ContractSignatureSwapFailure` |
|
|
1000
|
+
| `markerSwapFailure` | `signatureSwapFailure` |
|
|
1001
|
+
| `orphanMarkers` | `orphanSignatures` |
|
|
1002
|
+
| `parseContractMarkerRow` | `parseContractSignatureRow` |
|
|
1003
|
+
| `parseMarkerRowSafely` | `parseSignatureRowSafely` |
|
|
1004
|
+
| `readAllMarkers` | `readAllSignatures` |
|
|
1005
|
+
| `readMarker` | `readSignature` |
|
|
1006
|
+
| `readMarkerDiscriminated` | `readSignatureDiscriminated` |
|
|
1007
|
+
| `releaseMarkerLock` | `releaseSignatureLock` |
|
|
1008
|
+
| `rethrowMarkerReadError` | `rethrowSignatureReadError` |
|
|
1009
|
+
| `sameMarkerHashes` | `sameContractSignatureHashes` |
|
|
1010
|
+
| `skipMarker` | `skipSignature` |
|
|
1011
|
+
| `SpaceMarkerConflict` | `SpaceSignConflict` |
|
|
1012
|
+
| `SpaceMarkerHashConflict` | `SpaceSignatureHashConflict` |
|
|
1013
|
+
| `SpaceMarkerRecord` | `SpaceSignatureRecord` |
|
|
1014
|
+
| `SpaceSignature` | `SpaceSignOutcome` |
|
|
1015
|
+
| `updateMarker` | `updateSignature` |
|
|
1016
|
+
| `VERIFY_CODE_HASH_MISMATCH` | `VERIFY_CODE_SIGNATURE_MISMATCH` |
|
|
1017
|
+
| `VERIFY_CODE_MARKER_MISSING` | `VERIFY_CODE_SIGNATURE_MISSING` |
|
|
1018
|
+
| `verifyMarker` | `verifyContractSignature` |
|
|
1019
|
+
| `VerifyMarkerOption` | `VerifyContractSignatureOption` |
|
|
1020
|
+
| `withMarkerLock` | `withSignatureLock` |
|
|
1021
|
+
| `withMarkerReadErrorHandling` | `withSignatureReadErrorHandling` |
|
|
1022
|
+
|
|
1023
|
+
#### Run the script
|
|
1024
|
+
|
|
1025
|
+
Commit your work first, so the script's changes can be reviewed and undone with git. Then run the script that sits beside this guide in the `prisma-8` skill, from the folder that holds the skills copy, usually the project root, and give it the folder to work on; `.` is the working directory, which is also the default. With the copy in `.agents/`:
|
|
1026
|
+
|
|
1027
|
+
```sh
|
|
1028
|
+
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
|
+
```
|
|
1030
|
+
|
|
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:
|
|
1032
|
+
|
|
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;
|
|
1035
|
+
- in code, the values `'orphanMarker'`, `'markerChanged'` and `'marker-verification'`, written as strings;
|
|
1036
|
+
- 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
|
+
- 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
|
+
|
|
1039
|
+
|
|
1040
|
+
```ts
|
|
1041
|
+
// before
|
|
1042
|
+
const { stdout } = await execa('prisma', ['db', 'verify', '--marker-only', '--json']);
|
|
1043
|
+
if (error.code === 'CONTRACT.MARKER_MISSING') return signFirst();
|
|
1044
|
+
const { marker } = JSON.parse(stdout);
|
|
1045
|
+
return marker?.storageHash;
|
|
1046
|
+
|
|
1047
|
+
// after the script
|
|
1048
|
+
const { stdout } = await execa('prisma', ['db', 'verify', '--signature-only', '--json']);
|
|
1049
|
+
if (error.code === 'CONTRACT.SIGNATURE_MISSING') return signFirst();
|
|
1050
|
+
const { signature: marker } = JSON.parse(stdout);
|
|
1051
|
+
return marker?.storageHash;
|
|
1052
|
+
```
|
|
1053
|
+
|
|
1054
|
+
#### Read the script's changes before you commit them
|
|
1055
|
+
|
|
1056
|
+
The script finds names by searching the text of your code. It uses TypeScript only to tell a local binding of a renamed name from the import. So read its diff, and expect to fix a few lines by hand:
|
|
1057
|
+
|
|
1058
|
+
- **Names of your own that match Prisma's.** In a file that imports from an `@prisma/orm-*` package, a name of your own that is in the table of renamed names below is renamed whoever owns it, where it is a member, a key, a property read, or a quoted name after `[` or in `Pick<…>` and `Omit<…>`: your own `{ markerHash: … }`, `pin.currentMarker`, `updateMarker() {}`, `pin['currentMarker']`, `['markerHash', 'lat']` or `Pick<Mine, 'readMarker'>` becomes `signatureHash`, `currentSignature`, `updateSignature`, `pin['currentSignature']`, `['signatureHash', 'lat']` or `Pick<Mine, 'readSignature'>`. In a file that runs `db verify`, `db init`, `db update` or `db migrate` with `--json`, every `.marker`, `marker:` key (in an object, a type literal or an interface, `markerHash?:` included), `'marker'` string and destructured `marker` is renamed, yours included. A variable, parameter, function or export you declare keeps its name, and a destructured field keeps your local name (`const { signature: marker } = …`). Where one of your objects crosses into a file the script did not change, revert the rename, or rename the other file to match.
|
|
1059
|
+
- **Shapes it misses.** A member destructured under its own name, `const { readMarker, markerLocation } = adapter`, keeps the old names: the script cannot tell your object from Prisma's there, and renaming it would make your own destructuring read `undefined`. TypeScript reports each one; in a JavaScript project nothing does, and the old name reads `undefined` at run time, so read the results of the searches below.
|
|
1060
|
+
- **Files it can misread.** In `.tsx` and `.jsx`, an apostrophe in JSX text (`<p>Don't …</p>`) and a quote inside a regular expression (`/['"]/`) can make it misjudge where a string ends, and miss or wrongly make a rename after it. Read its changes to such files closely, and search them for what is left.
|
|
1061
|
+
|
|
1062
|
+
#### Change by hand what the script cannot
|
|
1063
|
+
|
|
1064
|
+
- **Two codes that are now one.** Code that handled `MIGRATION.MARKER_MISMATCH` and `MIGRATION.MARKER_NOT_IN_HISTORY` apart now has two branches for `MIGRATION.SIGNATURE_NOT_IN_GRAPH`, and only the first is reached: merge them, telling `db migrate`'s error from `migration status`'s warning by the command that raised it.
|
|
1065
|
+
- **The two removed codes.** Code that matches `CONTRACT.MARKER_REQUIRED` or `CONFIG.FAMILY_READ_MARKER_REQUIRED` handles something no command raises: remove that branch.
|
|
1066
|
+
- **`--json` output read away from the command.** The script renames `marker` and `markerHash` only in a file that also runs the command. Output saved to a file and read elsewhere, or passed between CI steps, is not renamed. Find the readers with this search, and change each one that reads Prisma's output:
|
|
1067
|
+
|
|
1068
|
+
```sh
|
|
1069
|
+
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
|
+
```
|
|
1071
|
+
|
|
1072
|
+
- **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
|
+
|
|
1074
|
+
```sh
|
|
1075
|
+
grep -rnwE --exclude-dir=node_modules --exclude-dir=dist --exclude-dir=build --exclude-dir=upgrading 'ContractMarkerRecord|ContractMarkerRecordLike|ContractMarkerRow|MARKER_LOCK_TIMEOUT_SECONDS|MarkerCheckResult|MarkerCheckSection|MarkerDestination|MarkerHashes|MarkerInsert|MarkerOperations|MarkerReadResult|MarkerReader|MarkerSwapFailure|SpaceMarkerConflict|SpaceMarkerHashConflict|SpaceMarkerRecord|SpaceSignature|VERIFY_CODE_HASH_MISMATCH|VERIFY_CODE_MARKER_MISSING|VerifyMarkerOption|acquireMarkerLock|bootstrapSignMarkerQueries|buildSignMarkerBootstrapQueries|contractHashAtMarker|currentMarker|currentMarkerHash|currentMarkerInvariants|currentMarkerStorageHash|databaseMarkerHashBySpace|errorHashMismatch|errorMarkerMissing|errorMarkerReadFailed|errorMarkerRowCorrupt|holdMarkerLock|initMarker|insertMarker|lockMarker|markerCheck|markerDrift|markerHash|markerInvariants|markerLocation|markerOps|markerReader|markerRowsBySpace|markerSwapFailure|markersBySpaceId|orphanMarkers|parseContractMarkerRow|parseMarkerRowSafely|readAllMarkers|readMarker|readMarkerDiscriminated|releaseMarkerLock|rethrowMarkerReadError|sameMarkerHashes|skipMarker|updateMarker|verifyMarker|withMarkerLock|withMarkerReadErrorHandling' .
|
|
1076
|
+
```
|
|
1077
|
+
|
|
1078
|
+
The searches leave out the `upgrading` folder of the skill copy, whose guides name the old names.
|
|
1079
|
+
|
|
1080
|
+
## A contract stores what it requires as `requiredCapabilities`
|
|
1081
|
+
|
|
1082
|
+
These changes apply to a project on any database. The PostgreSQL entries of this guide, from `postgres-contract-lists-required-capabilities` on, cover what else changes for PostgreSQL.
|
|
1083
|
+
|
|
1084
|
+
### `code-reads-required-capabilities`
|
|
1085
|
+
|
|
1086
|
+
A contract used to store the capabilities it requires as `capabilities`, each key in the namespace of its vocabulary: `sql.` for a key the SQL databases share and `postgres.` for PostgreSQL's own. It now stores them as `requiredCapabilities`, each key in the namespace of who provides it: `conn.` for the connection, whose only key is `conn.interactiveTransactions`, and `db.` for every other key, which the database provides. The field holds the keys as a list, sorted and without duplicates. A MongoDB contract's list stays empty, under its new name.
|
|
1087
|
+
|
|
1088
|
+
Change code that reads the list:
|
|
1089
|
+
|
|
1090
|
+
| Before | After |
|
|
1091
|
+
| --- | --- |
|
|
1092
|
+
| `contract.capabilities` | `contract.requiredCapabilities` |
|
|
1093
|
+
| `contract.capabilities.sql.returning` | `contract.requiredCapabilities.includes('db.returning')` |
|
|
1094
|
+
| `contract.capabilities.postgres.distinctOn` | `contract.requiredCapabilities.includes('db.distinctOn')` |
|
|
1095
|
+
| `contract.capabilities.sql.interactiveTransactions` | `contract.requiredCapabilities.includes('conn.interactiveTransactions')` |
|
|
1096
|
+
| Code that walks the groups and their flags, such as `Object.entries(contract.capabilities).flatMap(([namespace, flags]) => Object.entries(flags)…)` | Iterate `contract.requiredCapabilities` directly: each entry is a key such as `db.returning`. Renaming the field alone still compiles, because `Object.entries` accepts an array, but walks the characters of each key. |
|
|
1097
|
+
|
|
1098
|
+
A contract built by hand, not emitted, such as a JSON object in a test, renames its field and its keys the same way:
|
|
1099
|
+
|
|
1100
|
+
```json
|
|
1101
|
+
"requiredCapabilities": ["conn.interactiveTransactions", "db.jsonAgg", "db.returning"]
|
|
1102
|
+
```
|
|
1103
|
+
|
|
1104
|
+
A key whose prefix is neither `db.` nor `conn.` is read as written, and neither signing nor the client's connection check selects it.
|
|
1105
|
+
|
|
1106
|
+
`mysqlAdapterCapabilities` from `@prisma/orm-target-mysql/adapter`, `mariadbAdapterCapabilities` from `@prisma/orm-target-mariadb/adapter` and `sqliteAdapterCapabilities` from `@prisma/orm-target-sqlite/adapter` are lists of keys the same way: `mysqlAdapterCapabilities.sql.enums` becomes `mysqlAdapterCapabilities.includes('db.enums')`. Each now also lists `conn.interactiveTransactions`.
|
|
1107
|
+
|
|
1108
|
+
### `stored-contract-needs-the-upgrade-script`
|
|
1109
|
+
|
|
1110
|
+
The emitted `contract.json` and each migration snapshot under `migrations/snapshots/<hash>/` that a release candidate wrote store `capabilities`. This release refuses to read such a `contract.json`, for every database, with `CONTRACT.VALIDATION_FAILED`:
|
|
1111
|
+
|
|
1112
|
+
> 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
|
|
1113
|
+
|
|
1114
|
+
The client, `prisma db sign`, `prisma db verify` and the migration commands all read these files. Follow the `contract-hash-inputs` instructions in this guide: their script renames the field, writes the keys as a sorted list in every contract and snapshot, and in the type of the list in the `contract.d.ts` beside each, and they then have you run `prisma contract emit`.
|
|
1115
|
+
|
|
1116
|
+
## A contract stores its required capabilities as a list of keys
|
|
1117
|
+
|
|
1118
|
+
### `required-capabilities-as-list`
|
|
1119
|
+
|
|
1120
|
+
`contract.json` stores the capabilities a contract requires as the sorted list of keys its author writes:
|
|
1121
|
+
|
|
1122
|
+
| Before | After |
|
|
1123
|
+
| --- | --- |
|
|
1124
|
+
| `"requiredCapabilities": { "db": { "returning": true }, "conn": { "interactiveTransactions": true } }` | `"requiredCapabilities": ["conn.interactiveTransactions", "db.returning"]` |
|
|
1125
|
+
|
|
1126
|
+
In each file the detection matches:
|
|
1127
|
+
|
|
1128
|
+
- Replace a read of one capability, `X.requiredCapabilities.db.returning` or `X.requiredCapabilities.db?.returning`, with `X.requiredCapabilities.includes('db.returning')`. Do the same for `conn.` keys.
|
|
1129
|
+
- Code that walks the groups and their flags, such as `Object.entries(X.requiredCapabilities).flatMap(([namespace, flags]) => Object.entries(flags)…)`, iterates `X.requiredCapabilities` directly: each entry is a key such as `db.returning`.
|
|
1130
|
+
- Replace `prismaContract(path, { requiredCapabilities: postgresRequiredCapabilities([...]) })` with `prismaContract(path, { requiredCapabilities: [...] })`, passing the list directly, and remove the `postgresRequiredCapabilities` import. Do the same for `prisma7Contract`. A type annotation `PostgresRequiredCapabilities` becomes `RequiredCapabilities`, from the same entry.
|
|
1131
|
+
|
|
1132
|
+
### `stored-required-capabilities-as-list`
|
|
1133
|
+
|
|
1134
|
+
A development build wrote `requiredCapabilities` grouped by prefix, as in the "Before" column above. This release refuses such a `contract.json` or migration snapshot with `CONTRACT.VALIDATION_FAILED`.
|
|
1135
|
+
|
|
1136
|
+
There is no step of its own. The `contract-hash-inputs` script of this release rewrites a grouped `requiredCapabilities` to the sorted list, in `contract.json`, `contract.d.ts` and every migration snapshot, and computes the profile hash of the list. A contract already in the list form keeps its profile hash. Run the script, emit the contract and sign each database as the `contract-hash-inputs` instructions say: their last step, "Sign every database in that release's deploy", covers databases created later and databases that are behind.
|
|
1137
|
+
|
|
1138
|
+
## A PostgreSQL contract lists the capabilities it requires
|
|
1139
|
+
|
|
1140
|
+
These changes apply to a project on `@prisma/orm-postgres`. Do them in the order below.
|
|
1141
|
+
|
|
1142
|
+
### `postgres-contract-lists-required-capabilities`
|
|
1143
|
+
|
|
1144
|
+
A capability is a fact that a database version or a connection provides, and that a contract requires. Each capability's key names who provides it: `db.` for the database, such as `db.lateral`, and `conn.` for the connection, such as `conn.interactiveTransactions`. A contract's capabilities used to come from the adapter. Now you write, where the contract is written, the list of every capability the contract requires. Nothing is added to it.
|
|
1145
|
+
|
|
1146
|
+
The list is recommended now and required from Prisma 8.0. A contract that does not list them requires the newest PostgreSQL version's list and the driver's, the list `prisma orm init` writes, and the commands that load the contract source, `prisma contract emit` and `prisma contract print` among them, warn until you add it. The warning shows what to write, with its import, as `prisma orm init` writes it. For a Prisma schema given as `contract: './prisma/contract.prisma'` it reads:
|
|
1147
|
+
|
|
1148
|
+
```text
|
|
1149
|
+
Your contract does not list the capabilities it requires, so it requires those of the newest PostgreSQL version and of the driver. Prisma 8.0 removes this default and requires the list. Write this as the contract entry in the config, with its import:
|
|
1150
|
+
|
|
1151
|
+
contract: {
|
|
1152
|
+
path: "./prisma/contract.prisma",
|
|
1153
|
+
requiredCapabilities: [...postgres18, ...postgresDriver],
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
import { postgres18, postgresDriver } from '@prisma/orm-postgres/config';
|
|
1157
|
+
```
|
|
1158
|
+
|
|
1159
|
+
Its code is `CONTRACT.REQUIRED_CAPABILITIES_NOT_LISTED`. It does not change emit's exit code.
|
|
1160
|
+
|
|
1161
|
+
#### 1. Choose the lists
|
|
1162
|
+
|
|
1163
|
+
`@prisma/orm-postgres/contract-builder` and `@prisma/orm-postgres/config` export one list for each supported PostgreSQL version, `postgres15`, `postgres16`, `postgres17` and `postgres18`, and `postgresDriver`, what the connection of the PostgreSQL driver provides. Each is a list of capability keys as error messages print them, such as `db.returning`.
|
|
1164
|
+
|
|
1165
|
+
Spread the list of the oldest PostgreSQL version the contract must run on, and the driver's: `[...postgres18, ...postgresDriver]`. If production runs PostgreSQL 16 and development runs 17, use `postgres16`. A database newer than 18 provides what 18 provides. Today all four versions provide the same capabilities, so the version you choose does not change the emitted contract. It will matter when a later release adds a version with new features.
|
|
1166
|
+
|
|
1167
|
+
To leave a capability out, filter it out or write the keys yourself:
|
|
1168
|
+
|
|
1169
|
+
```ts
|
|
1170
|
+
requiredCapabilities: [
|
|
1171
|
+
...postgres18.filter((capability) => capability !== 'db.insertOnConflictTarget'),
|
|
1172
|
+
...postgresDriver,
|
|
1173
|
+
],
|
|
1174
|
+
```
|
|
1175
|
+
|
|
1176
|
+
A list that leaves out `postgresDriver` does not require `conn.interactiveTransactions`, so the callback passed to `transaction()` is a type error. See `postgres-transaction-needs-interactive-transactions`.
|
|
1177
|
+
|
|
1178
|
+
#### 2. Write the list where the contract is written
|
|
1179
|
+
|
|
1180
|
+
There are four forms. Change each one the project has.
|
|
1181
|
+
|
|
1182
|
+
A contract written in TypeScript lists them in `defineContract`, from `@prisma/orm-postgres/contract-builder`. Before:
|
|
1183
|
+
|
|
1184
|
+
```ts
|
|
1185
|
+
import { defineContract } from '@prisma/orm-postgres/contract-builder';
|
|
1186
|
+
|
|
1187
|
+
export const contract = defineContract({ extensions: { pgvector } }, ({ field, model }) => ({
|
|
1188
|
+
// ...
|
|
1189
|
+
}));
|
|
1190
|
+
```
|
|
1191
|
+
|
|
1192
|
+
After:
|
|
1193
|
+
|
|
1194
|
+
```ts
|
|
1195
|
+
import { defineContract, postgres18, postgresDriver } from '@prisma/orm-postgres/contract-builder';
|
|
1196
|
+
|
|
1197
|
+
export const contract = defineContract(
|
|
1198
|
+
{ requiredCapabilities: [...postgres18, ...postgresDriver], extensions: { pgvector } },
|
|
1199
|
+
({ field, model }) => ({
|
|
1200
|
+
// ...
|
|
1201
|
+
}),
|
|
1202
|
+
);
|
|
1203
|
+
```
|
|
1204
|
+
|
|
1205
|
+
Under the PostgreSQL `defineConfig`, `prisma contract emit` warns without the list, saying to add `requiredCapabilities: [...postgres18, ...postgresDriver]` in `defineContract` with the import from `@prisma/orm-postgres/contract-builder`. Building the contract elsewhere, such as in a test, prints nothing, and so does emit under the core `defineConfig`: the contract then gets the default list silently.
|
|
1206
|
+
|
|
1207
|
+
An empty list throws:
|
|
1208
|
+
|
|
1209
|
+
> State the capabilities your contract requires in requiredCapabilities in defineContract. The list is empty.
|
|
1210
|
+
|
|
1211
|
+
A capability set, such as `{ db: { returning: true } }`, is refused as not a list:
|
|
1212
|
+
|
|
1213
|
+
> requiredCapabilities in defineContract is not a list. State the capabilities your contract requires as a list of capability keys.
|
|
1214
|
+
|
|
1215
|
+
Any string is accepted as a key, but only a `db.` key is checked against the database and only a `conn.` key against the connection, so a key in the form a release candidate's `contract.json` used, such as `sql.returning`, is required by nothing that checks it. Write it with its provider's prefix, `db.returning`. An entry that is not a string is refused, for example:
|
|
1216
|
+
|
|
1217
|
+
> requiredCapabilities in defineContract lists 42, which is not a capability key. A capability key is a string, such as `db.returning`.
|
|
1218
|
+
|
|
1219
|
+
The config and `prisma7Schema` refuse the same three cases, naming where they take the list. These refusals have the code `CONTRACT.ARGUMENT_INVALID`.
|
|
1220
|
+
|
|
1221
|
+
A `db.` key that no PostgreSQL version provides, such as a mistyped one, is written to the contract as it is. `prisma db sign`, `prisma db verify` and the migration commands then refuse every database for it, with `CONTRACT.DATABASE_CAPABILITIES_NOT_PROVIDED` (`MIGRATION.DATABASE_CAPABILITIES_NOT_PROVIDED` from the migration commands):
|
|
1222
|
+
|
|
1223
|
+
> Your contract requires unrecognized database capabilities (db.notAThing). They are not provided by any known PostgreSQL version. Remove them from your contract's required capabilities.
|
|
1224
|
+
|
|
1225
|
+
A contract written in the Prisma schema language lists them in the config's contract entry, in the `defineConfig` from `@prisma/orm-postgres/config`. The contract path becomes an object. Before:
|
|
1226
|
+
|
|
1227
|
+
```ts
|
|
1228
|
+
import { defineConfig } from '@prisma/orm-postgres/config';
|
|
1229
|
+
|
|
1230
|
+
export default definePrismaConfig({
|
|
1231
|
+
orm: defineConfig({
|
|
1232
|
+
contract: './prisma/contract.prisma',
|
|
1233
|
+
}),
|
|
1234
|
+
});
|
|
1235
|
+
```
|
|
1236
|
+
|
|
1237
|
+
After:
|
|
1238
|
+
|
|
1239
|
+
```ts
|
|
1240
|
+
import { defineConfig, postgres18, postgresDriver } from '@prisma/orm-postgres/config';
|
|
1241
|
+
|
|
1242
|
+
export default definePrismaConfig({
|
|
1243
|
+
orm: defineConfig({
|
|
1244
|
+
contract: {
|
|
1245
|
+
path: "./prisma/contract.prisma",
|
|
1246
|
+
requiredCapabilities: [...postgres18, ...postgresDriver],
|
|
1247
|
+
},
|
|
1248
|
+
}),
|
|
1249
|
+
});
|
|
1250
|
+
```
|
|
1251
|
+
|
|
1252
|
+
A `.prisma` path without the list, or an entry `{ path }` without it, still works, and `prisma contract emit` prints the warning quoted at the start of this section.
|
|
1253
|
+
|
|
1254
|
+
A config whose contract is a TypeScript file (`contract: './prisma/contract.ts'`) does not change. The TypeScript contract lists its capabilities in `defineContract`, so the config refuses `requiredCapabilities` beside a `.ts` path.
|
|
1255
|
+
|
|
1256
|
+
A Prisma 7 schema read with `prisma7Schema` takes the list in a second argument. Before:
|
|
1257
|
+
|
|
1258
|
+
```ts
|
|
1259
|
+
contract: prisma7Schema('prisma/schema.prisma'),
|
|
1260
|
+
```
|
|
1261
|
+
|
|
1262
|
+
After:
|
|
1263
|
+
|
|
1264
|
+
```ts
|
|
1265
|
+
contract: prisma7Schema('prisma/schema.prisma', {
|
|
1266
|
+
requiredCapabilities: [...postgres18, ...postgresDriver],
|
|
1267
|
+
}),
|
|
1268
|
+
```
|
|
1269
|
+
|
|
1270
|
+
Without it, `prisma contract emit` warns and shows that call, with the import of the lists.
|
|
1271
|
+
|
|
1272
|
+
The fourth form, a contract source the config builds itself, is in `postgres-config-without-define-config-passes-capabilities` below.
|
|
1273
|
+
|
|
1274
|
+
#### 3. Emit the contract
|
|
1275
|
+
|
|
1276
|
+
The `contract-hash-inputs` instructions in this guide have you run their script on the project and then `prisma contract emit`. That emit is this step: run it after the script, once the list is written.
|
|
1277
|
+
|
|
1278
|
+
```sh
|
|
1279
|
+
prisma contract emit
|
|
1280
|
+
```
|
|
1281
|
+
|
|
1282
|
+
`contract.json` and `contract.d.ts` change. They store the list as `requiredCapabilities`, with exactly the keys the list names, so they lose the keys in `postgres-capability-flags-removed` and gain `conn.interactiveTransactions` when the list spreads `postgresDriver`. Commit them.
|
|
1283
|
+
|
|
1284
|
+
#### 4. Sign each database with the `contract-hash-inputs` steps
|
|
1285
|
+
|
|
1286
|
+
Signing now checks that the database provides every capability the contract requires of it, and refuses to sign when it does not. A database signed by an earlier release was signed without that check, so its signature does not yet promise that the database satisfies the contract. Signing again makes that check. `prisma db migrate`, `prisma db update` and `prisma db init` make the same check before they change the database.
|
|
1287
|
+
|
|
1288
|
+
Do not sign here. The `contract-hash-inputs` instructions in this guide, in their step on signing every database in the deploy, say which command each database gets: most get `prisma db sign --no-advance-ref`, a database that is behind is signed at a migration directory, and a database created later is not signed. That signing makes this check, so following them completes this step.
|
|
1289
|
+
|
|
1290
|
+
### `postgres-config-without-define-config-passes-capabilities`
|
|
1291
|
+
|
|
1292
|
+
A config that builds its contract source itself, with `prismaContract` from `@prisma/orm-family-sql/contract-psl/provider` or `prisma7Contract` from `@prisma/orm-family-sql/contract-prisma7/provider`, passes the source its required capabilities: the same list of keys as the other forms, from `@prisma/orm-postgres/config`. The target, adapter and driver no longer add capabilities to the contract.
|
|
1293
|
+
|
|
1294
|
+
Before:
|
|
1295
|
+
|
|
1296
|
+
```ts
|
|
1297
|
+
contract: prismaContract('./prisma/contract.prisma', {
|
|
1298
|
+
target: postgres,
|
|
1299
|
+
createNamespace: postgresCreateNamespace,
|
|
1300
|
+
}),
|
|
1301
|
+
```
|
|
1302
|
+
|
|
1303
|
+
After:
|
|
1304
|
+
|
|
1305
|
+
```ts
|
|
1306
|
+
import {
|
|
1307
|
+
postgres18,
|
|
1308
|
+
postgresDriver,
|
|
1309
|
+
} from '@prisma/orm-postgres/config';
|
|
1310
|
+
|
|
1311
|
+
contract: prismaContract('./prisma/contract.prisma', {
|
|
1312
|
+
requiredCapabilities: [...postgres18, ...postgresDriver],
|
|
1313
|
+
target: postgres,
|
|
1314
|
+
createNamespace: postgresCreateNamespace,
|
|
1315
|
+
}),
|
|
1316
|
+
```
|
|
1317
|
+
|
|
1318
|
+
A source given no `requiredCapabilities` and passed to the PostgreSQL `defineConfig`, as `contract: prismaContract(...)`, still works until Prisma 8.0, a schema with a scalar list or `@@check` included: it is read with the newest version's list and the driver's, its contract requires them, and `prisma contract emit` warns and shows the `requiredCapabilities` line above with its import.
|
|
1319
|
+
|
|
1320
|
+
A config built with the core `defineConfig`, from `@prisma/orm-toolchain/cli/config-types` or `@prisma/orm-framework/config/config-types`, which names the target, adapter and driver itself, gets no default, because only the PostgreSQL `defineConfig` knows it. A source given no `requiredCapabilities` writes, on the next `prisma contract emit`, a contract that lists no capabilities, with no warning. The client then refuses the features that need a capability: `transaction()` is a type error and throws `ORM.CAPABILITY_MISSING`, and row locks, `distinctOn`, skip-on-conflict writes, prepared reads with includes, and writes that read back their rows through `db.returning`, such as a `create()` whose key the database generates, are refused with the same code. Includes still work, with one query per relation. A schema with a scalar list (`String[]`) or `@@check` does not emit at all. So add `requiredCapabilities: [...postgres18, ...postgresDriver]` to the source, and `import { postgres18, postgresDriver } from '@prisma/orm-postgres/config';` to the config, before emitting.
|
|
1321
|
+
|
|
1322
|
+
Then emit and sign, as in steps 3 and 4 above.
|
|
1323
|
+
|
|
1324
|
+
### `postgres-emitted-contract-is-emitted-again`
|
|
1325
|
+
|
|
1326
|
+
A `contract.json` that a release candidate emitted, and each migration snapshot under `migrations/`, stores what the contract requires as `capabilities`, with keys such as `sql.returning` and `postgres.distinctOn`. This release stores it as `requiredCapabilities`, with `db.` and `conn.` keys, and refuses to read a `contract.json` that still has `capabilities`, with `CONTRACT.VALIDATION_FAILED`:
|
|
1327
|
+
|
|
1328
|
+
> 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
|
|
1329
|
+
|
|
1330
|
+
A command that reads a migration snapshot the release candidate wrote refuses it before that check, with `MIGRATION.CONTRACT_SNAPSHOT_CONTENT_MISMATCH`, because its storage hash was computed by the old hash rules. The client, `prisma db sign`, `prisma db verify` and the migration commands all read these files, so each refuses until they are rewritten.
|
|
1331
|
+
|
|
1332
|
+
The `contract-hash-inputs` script of this release rewrites every one of them, and, where it finds it, the type of the list in the `contract.d.ts` beside each: it renames the field, gives each key its new prefix, and drops the flags in `postgres-capability-flags-removed`. Its own instructions describe how to run it. `prisma contract emit` rewrites only the head snapshot of each extension, from the extension's new version, so the script is the only way to bring the application's snapshots, and an extension's earlier ones, to this release. After the script, run `prisma contract emit` (step 3 above), which writes the contract's own list.
|
|
1333
|
+
|
|
1334
|
+
### `postgres-transaction-needs-interactive-transactions`
|
|
1335
|
+
|
|
1336
|
+
`transaction()` on the PostgreSQL client, on a serverless connection, and on a Supabase role-bound client now needs the contract to require `conn.interactiveTransactions`. The PostgreSQL driver provides it, and `postgresDriver` lists it, so a contract that spreads `postgresDriver` into its list has it.
|
|
1337
|
+
|
|
1338
|
+
For a contract without it, the callback passed to `transaction()` is a type error that names `conn.interactiveTransactions`, and calling it throws `ORM.CAPABILITY_MISSING`:
|
|
1339
|
+
|
|
1340
|
+
> `transaction()` is unavailable: your contract declares no dependency on `conn.interactiveTransactions`. To enable it, add `conn.interactiveTransactions` to your contract's required capabilities.
|
|
1341
|
+
|
|
1342
|
+
With `@prisma/orm-better-auth`, `prismaAdapter(db, { transaction: true })` needs the same capability in the client's contract.
|
|
1343
|
+
|
|
1344
|
+
### `postgres-hand-built-contract-lists-capabilities`
|
|
1345
|
+
|
|
1346
|
+
A contract stores what it requires as `requiredCapabilities`, the list of keys, sorted and without duplicates: `db.` for the database and `conn.` for the connection:
|
|
1347
|
+
|
|
1348
|
+
```json
|
|
1349
|
+
"requiredCapabilities": ["conn.interactiveTransactions", "db.distinctOn", "db.lateral", "db.returning"]
|
|
1350
|
+
```
|
|
1351
|
+
|
|
1352
|
+
The client used to add the capabilities of its target, adapter and driver to the contract's. It no longer does: it offers exactly what the contract lists. An emitted contract already lists what it needs. A contract built by hand, for example a JSON object written in a test, must list every capability the code uses in `requiredCapabilities`. Take the keys from a contract emitted with the same list. A key whose prefix is neither `db.` nor `conn.` is read as written, and no check selects it.
|
|
1353
|
+
|
|
1354
|
+
Code that reads a contract's capabilities reads `contract.requiredCapabilities`: `contract.capabilities.sql.returning` becomes `contract.requiredCapabilities.includes('db.returning')`, and `contract.capabilities.postgres.distinctOn` becomes `contract.requiredCapabilities.includes('db.distinctOn')`.
|
|
1355
|
+
|
|
1356
|
+
### `postgres-signing-refuses-servers-older-than-15`
|
|
1357
|
+
|
|
1358
|
+
`prisma db verify`, `prisma db sign`, `prisma db migrate`, `prisma db update` and `prisma db init` read the server's version and check that it provides every capability the contract requires of the database, its `db.` keys. On failure, nothing is signed and nothing is changed. Verification reports the code `CONTRACT.DATABASE_CAPABILITIES_NOT_PROVIDED`, and the migration commands report `MIGRATION.DATABASE_CAPABILITIES_NOT_PROVIDED`.
|
|
1359
|
+
|
|
1360
|
+
A server older than PostgreSQL 15 is always refused. For example, for PostgreSQL 14.10:
|
|
1361
|
+
|
|
1362
|
+
> This release of Prisma requires PostgreSQL 15 or later. This database runs PostgreSQL 14.10. Upgrade the database to PostgreSQL 15 or later.
|
|
1363
|
+
|
|
1364
|
+
Upgrade such a database to PostgreSQL 15 or later. When the server's version cannot be read, the refusal says:
|
|
1365
|
+
|
|
1366
|
+
> Prisma could not read this database's PostgreSQL version, so it cannot check that the database provides what your contract requires. Check that the connection reaches a PostgreSQL server, and that SHOW server_version_num returns its version there.
|
|
1367
|
+
|
|
1368
|
+
Point the connection at a PostgreSQL server that reports its version, then run the command again.
|
|
1369
|
+
|
|
1370
|
+
### `postgres-capability-flags-removed`
|
|
1371
|
+
|
|
1372
|
+
These flags are removed from PostgreSQL contracts. Nothing read them, and no `db.` key replaces them:
|
|
1373
|
+
|
|
1374
|
+
- `postgres.orderBy`, `postgres.limit`, `postgres.lateral`, `postgres.jsonAgg` and `postgres.returning`. The `db.lateral`, `db.jsonAgg` and `db.returning` flags, which were `sql.lateral`, `sql.jsonAgg` and `sql.returning`, remain.
|
|
1375
|
+
- `sql.enums`. MySQL and MariaDB contracts keep it, as `db.enums`.
|
|
1376
|
+
- `postgres.pgvector.cosine` from `@prisma/orm-extension-pgvector`, `postgres.postgis.geometry` from `@prisma/orm-extension-postgis` and `postgres.paradedb/bm25` from `@prisma/orm-extension-paradedb`.
|
|
1377
|
+
|
|
1378
|
+
The `contract-hash-inputs` script removes them from `contract.json`, `contract.d.ts` and each snapshot. Remove them from any contract you build by hand, and from any code or type that names them.
|
|
1379
|
+
|
|
1380
|
+
### `postgres-capability-exports-moved`
|
|
1381
|
+
|
|
1382
|
+
Change these, if the project has them. `postgresAdapterCapabilities` keeps compiling until Prisma 8.0 removes it:
|
|
1383
|
+
|
|
1384
|
+
| Before | After |
|
|
1385
|
+
| --- | --- |
|
|
1386
|
+
| `postgresAdapterCapabilities` from `@prisma/orm-target-postgres/adapter/adapter` | Nothing: it is empty. Remove the import and the code that reads it |
|
|
1387
|
+
| The capabilities that `postgresAdapterCapabilities` listed | `postgres15` to `postgres18` from `@prisma/orm-postgres/contract-builder` or `@prisma/orm-postgres/config`, or the table they are built from, `postgresCapabilitiesByVersion` (one row per version, each a list of keys such as `db.returning`) from `@prisma/orm-target-postgres/target/server-version` |
|
|
1388
|
+
| `pgVersion` (text) on `PostgresDatabaseSchemaNode` from `@prisma/orm-target-postgres/target/types` | `serverVersionNumber`: the server's `server_version_num` as a number, such as `150004` for 15.4, or `undefined` when it could not be read |
|
|
1389
|
+
|
|
1390
|
+
`postgresAdapterCapabilities` is now an empty list: every key in `postgresCapabilitiesByVersion` is a fact about the database, and the target declares those by version. The driver's list, `postgresDriverCapabilities`, `['conn.interactiveTransactions']`, is in `@prisma/orm-target-postgres/driver/capabilities`.
|
|
1391
|
+
|
|
1392
|
+
## Stored files carry a format version
|
|
1393
|
+
|
|
1394
|
+
### `stored-files-format-version`
|
|
1395
|
+
|
|
1396
|
+
Each file Prisma writes into your repository now says which version of its format it is in, so a later release can tell an old file from a new one and refuse a file written by a newer release instead of misreading it. Prisma writes the new form from this release on:
|
|
1397
|
+
|
|
1398
|
+
```jsonc
|
|
1399
|
+
// contract.json, before
|
|
1400
|
+
{ "schemaVersion": "1", "targetFamily": "sql", ... }
|
|
1401
|
+
// after
|
|
1402
|
+
{ "formatVersion": 1, "targetFamily": "sql", ... }
|
|
1403
|
+
|
|
1404
|
+
// migration.json and refs/<name>.json, before
|
|
1405
|
+
{ "from": null, "to": "...", ... }
|
|
1406
|
+
// after
|
|
1407
|
+
{ "formatVersion": 1, "from": null, "to": "...", ... }
|
|
1408
|
+
```
|
|
1409
|
+
|
|
1410
|
+
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
|
+
|
|
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:
|
|
1413
|
+
|
|
1414
|
+
```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
|
|
1416
|
+
```
|
|
1417
|
+
|
|
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/`.
|
|
1419
|
+
|
|
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:
|
|
1421
|
+
|
|
1422
|
+
- 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
|
+
- 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.
|
|
1424
|
+
|
|
1425
|
+
It edits each file in place and keeps the rest of its bytes and layout. It prints each file it changed. A project already in the new form is left unchanged, and the script says nothing changed.
|
|
1426
|
+
|
|
1427
|
+
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
|
+
|
|
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.
|
|
1430
|
+
|
|
1431
|
+
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
|
+
|
|
1433
|
+
The script does not follow symbolic links. A link to a folder inside the project that the walk enters, or to a `.json` file in such a folder, leads to files it reaches anyway, and a link to the project folder or a folder above it leads back to the project; the script ignores both. It reports such a link, and exits 1, when it would not handle the target as it would at the link: for example a ref file in a `refs` folder that links to a file elsewhere, which the script finds as a ref only in a `refs` folder. Replace that link with what it points to. A link to a file or folder inside the project that the walk skips, such as one in a folder whose name starts with a dot, is reported like a link outside the project. A link to a file or folder outside the project, such as a migrations folder shared between packages, that holds a stored file the script would change or report is reported, and the script exits 1: run the script on that folder too.
|
|
1434
|
+
|
|
1435
|
+
No hash covers the format version: storage hashes, snapshot directory names and each `migrationHash` stay as they are, and no database needs signing again.
|
|
1436
|
+
|
|
1437
|
+
Then run the `contract-hash-inputs` script below, and run `prisma contract emit` only after it, as its step 4 says. That emit writes the new form itself.
|
|
1438
|
+
|
|
1439
|
+
## A contract's hashes cover only what the contract means
|
|
1440
|
+
|
|
1441
|
+
### `contract-hash-inputs`
|
|
1442
|
+
|
|
1443
|
+
A contract has three hashes: the storage hash (`storage.storageHash`), which names the database schema the contract describes; the profile hash (`profileHash`); and the execution hash (`execution.executionHash`). Until this release each covered its own section inside a stand-in contract with a fixed `schemaVersion` and blank fields. Now each covers only its own section, and no longer the target or the family. So a project that moves to another target with the same storage, such as from MySQL to MariaDB, keeps its storage hashes, and with them its migrations, snapshots and refs; its profile hash changes where the capabilities differ, as they do from MySQL to MariaDB, and each database is signed again with `prisma db sign`. So every hash in your project changes once, and from `8.0.0` the rules that compute them do not change within the major version.
|
|
1444
|
+
|
|
1445
|
+
The storage hash names a contract everywhere Prisma refers to one: the snapshot directories under `migrations/snapshots/<hash>/`, the `from` and `to` of each `migration.json` and the query plans of a data transform in its `ops.json` (and so its `migrationHash`), the `hash` of each ref file, the snapshot imports and hash literals of each `migration.ts`, and the contract signature Prisma writes in each database. All of them must move to the new hashes together.
|
|
1446
|
+
|
|
1447
|
+
#### 1. Bring every database to the newest contract first
|
|
1448
|
+
|
|
1449
|
+
This is the normal path. The release that upgrades Prisma assumes that every database is at the newest contract, the application's and every extension's.
|
|
1450
|
+
|
|
1451
|
+
Before you upgrade Prisma, deploy every pending migration to every database the project uses (development, staging, production and any other) with the release you are on now, application and extension migrations alike. Upgrade each extension to its latest version for that release first, and deploy its migrations too: an extension's version for this release adds no migration. Each database is then at the newest contract, and the upgrade's own release carries no migration, except in the one case step 4 describes. `prisma migration status`, run against a database, lists the migrations still pending in each space.
|
|
1452
|
+
|
|
1453
|
+
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
|
+
|
|
1455
|
+
#### 2. Upgrade Prisma and run the script
|
|
1456
|
+
|
|
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:
|
|
1458
|
+
|
|
1459
|
+
```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
|
|
1461
|
+
```
|
|
1462
|
+
|
|
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/`.
|
|
1464
|
+
|
|
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.
|
|
1466
|
+
|
|
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.
|
|
1468
|
+
|
|
1469
|
+
Then it computes each contract's new hashes and rewrites, keeping every other byte of each file:
|
|
1470
|
+
|
|
1471
|
+
- the list of capabilities in every contract, and its type in the `contract.d.ts` beside it, described below;
|
|
1472
|
+
- the storage, profile and execution hash in every contract, and the same hashes in the `contract.d.ts` beside it;
|
|
1473
|
+
- the name of each snapshot directory, `snapshots/<old>/` to `snapshots/<new>/`;
|
|
1474
|
+
- `from` and `to` in every `migration.json`, each old storage hash in the `ops.json` beside it (a data transform's query plans carry the storage hash of the contract they were built for), and its `migrationHash`, which covers both (the rule for the migration hash is unchanged);
|
|
1475
|
+
- `hash` in every ref file;
|
|
1476
|
+
- each old storage hash in every `migration.ts`, which names its snapshots in its imports.
|
|
1477
|
+
|
|
1478
|
+
A contract stored the capabilities it requires as `capabilities`, each key in the namespace of its vocabulary: `sql.` for a key the SQL targets share, `postgres.` for PostgreSQL's own. This release stores them as `requiredCapabilities`, each key in the namespace of who provides it: `conn.interactiveTransactions` for the connection, and `db.` for every other key, which the database provides. So `sql.returning` becomes `db.returning` and `postgres.distinctOn` becomes `db.distinctOn`. The script renames the field and the keys in every contract and snapshot, and the type of the list in the `contract.d.ts` beside each. A PostgreSQL contract also loses the nine keys the release candidates wrote that nothing reads: `postgres.jsonAgg`, `postgres.lateral`, `postgres.limit`, `postgres.orderBy`, `postgres.returning`, `postgres.paradedb/bm25`, `postgres.pgvector.cosine`, `postgres.postgis.geometry` and `sql.enums`; and any contract loses the keys in a namespace other than `sql` and `postgres`, such as one an extension declared in an earlier release, which nothing reads either. The profile hash it writes covers the renamed list. This release refuses to read a contract that still has `capabilities`, and `prisma contract emit` writes only the head snapshot of each extension again, so the script is the only way to bring the application's snapshots, and an extension's earlier ones, to this release. 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.
|
|
1479
|
+
|
|
1480
|
+
It prints each file it rewrote, each directory it renamed, each hash it replaced and each contract whose capabilities it renamed. A snapshot directory's new name may already exist: `prisma contract emit` with this release writes an extension's snapshot under its new hash, for example when you ran it at the end of the format version step. When the contract in that directory gives the same storage hash, the script keeps that directory as it is, removes the old one, and lists both; snapshots are named by storage hash, and two contracts with the same storage share one. Otherwise it changes no file and names both directories. If you ran `prisma contract emit` with this release before the script, and the contract source holds a value the earlier release left out (step 4), 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; step 4 says what to do. A second run changes nothing. A run that stops partway, for example on a full disk, leaves each file either as it was or rewritten, and running the script again finishes the upgrade.
|
|
1481
|
+
|
|
1482
|
+
The script 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: one inside the project where the walk skips, such as a folder whose name starts with a dot, or one outside the project, such as a migrations folder shared between packages; or that the walk reaches but reads as another kind of file, such as a ref in a `refs` folder 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. It does the same 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.
|
|
1483
|
+
|
|
1484
|
+
The script exits 1 without changing that file when it cannot finish one:
|
|
1485
|
+
|
|
1486
|
+
- 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.
|
|
1487
|
+
- 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
|
+
- A `contract.json` has neither `formatVersion` nor `schemaVersion`, so no release of Prisma wrote it. The script leaves it alone.
|
|
1489
|
+
- 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
|
+
- 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.
|
|
1491
|
+
|
|
1492
|
+
#### 3. Upgrade every extension with Prisma
|
|
1493
|
+
|
|
1494
|
+
An extension package bundles a contract and migrations with its hashes, and this release checks them when it loads the extension. An extension built for an earlier release fails to load with `MIGRATION.DESCRIPTOR_HEAD_HASH_MISMATCH`, whose message names the extension. Upgrade each extension to its version for this release in the same change. Its migrations that are already in your databases come with it, renamed to the new hashes; step 1 already applied them.
|
|
1495
|
+
|
|
1496
|
+
#### 4. Emit the contract and commit
|
|
1497
|
+
|
|
1498
|
+
Run `prisma contract emit` and commit the result with the script's changes. It writes the emitted contract, with the storage and execution hashes the script wrote, and the files Prisma keeps for each extension under `migrations/<extension>/`. It also replaces the snapshot of each extension's head, under `migrations/snapshots/<hash>/`, with the extension's contract as this release builds it: the storage hash stays, and the required capabilities and the profile hash may change. That is expected; commit it. The profile hash covers the contract's `requiredCapabilities`. For a PostgreSQL contract, `contract emit` writes the list the contract gives in `requiredCapabilities`. A PostgreSQL contract that gives none is covered by this guide's PostgreSQL capability entries, from `postgres-contract-lists-required-capabilities` on: under the PostgreSQL `defineConfig` it requires the newest supported version's list and the driver's, with a warning, but a `prismaContract` or `prisma7Contract` source under the core `defineConfig` gets no list at all. For other databases it takes them from the target and the adapter. When this release writes the same capabilities as your release did, the emitted contract keeps the profile hash the script wrote. When it writes different ones, the emitted contract has this release's list and the profile hash of that list. That happens for every contract that now requires `conn.interactiveTransactions`, which no release candidate's contract listed: every MySQL, MariaDB and SQLite contract, and a PostgreSQL contract whose list spreads `postgresDriver` or that takes the default. It happens too for a PostgreSQL list that differs from what the release candidate wrote. That is expected: step 5 signs each database with the emitted contract.
|
|
1499
|
+
|
|
1500
|
+
##### When the emitted contract gets a different storage hash
|
|
1501
|
+
|
|
1502
|
+
The earlier release left out almost every `false`, `[]` and `{}` in the storage section when it wrote `contract.json`. This release keeps every such value except the defaults each family names as the same as leaving the value out, such as an index's `unique: false`. The values the earlier release left out and this release keeps include a PostgreSQL index's options, a type's parameters, a value set member that is an object (such as `{ "round": false }`), the entries an extension pack adds to storage, a MongoDB index's partial filter expression, a MongoDB collation's `backwards: false` and `normalization: false`, a MongoDB collection's storage engine and clustered index options, and a MongoDB validator's `additionalItems: false`. For example, an index with the options `{ fastupdate: false }` was written with the options `{}`, and its migration created the index without `fastupdate = false`. This release keeps those values. If your contract source holds one, the script gives the stored contract, without the value, its new hash, and `prisma contract emit` then writes the value back and a different storage hash. To tell, compare the emitted contract's `storageHash` with the new hash the script printed for it under "Storage hashes (old -> new)", or, if you ran `prisma contract emit` before the script, read the list of such contracts that the script prints; `git diff` on `contract.json` also shows the value restored. The same happens to a default generator's parameters, but they are in the execution section, not in storage: `prisma contract emit` writes such a value back and gives the contract a new execution hash, which no database or migration checks, so it needs no migration. After `prisma contract emit`, the file may also list a table's foreign keys and a collection's MongoDB indexes in a new order, which changes no hash; only the `storageHash` comparison tells whether the hash changed.
|
|
1503
|
+
|
|
1504
|
+
The emitted contract then truly differs from your databases, which were built without the value, so this is the one case where the release that upgrades Prisma carries a migration. Plan it with `prisma migration plan` and review it: it applies the value to the database for the first time. The planner cannot plan every such change. For a change to an index's options, such as `fastupdate`, `prisma migration plan` stops with `MIGRATION.PLANNING_FAILED` and advises `migration new`, so write that migration by hand:
|
|
1505
|
+
|
|
1506
|
+
1. Run `prisma migration new --name <name>`. It writes a migration from the contract the `db` ref names, which the script rewrote, to the emitted contract. Where there is no `db` ref, add `--from <hash>`, with the new hash the script printed for the `to` of your last migration.
|
|
1507
|
+
2. In the new `migration.ts`, import `rawSql` from `@prisma/orm-postgres/migration`, beside `Migration` and `MigrationCLI`, and return one operation that runs the `ALTER INDEX … SET (…)` statement. Name the index as the emitted `contract.json` does, in its `name`. For the `fastupdate` example:
|
|
1508
|
+
|
|
1509
|
+
```ts
|
|
1510
|
+
import { Migration, MigrationCLI, rawSql } from '@prisma/orm-postgres/migration';
|
|
1511
|
+
|
|
1512
|
+
// in the class that `prisma migration new` wrote:
|
|
1513
|
+
override get operations() {
|
|
1514
|
+
return [
|
|
1515
|
+
rawSql({
|
|
1516
|
+
id: 'index.post_meta_gin_3aa57499.fastupdate',
|
|
1517
|
+
label: 'Set fastupdate = off on index "post_meta_gin_3aa57499"',
|
|
1518
|
+
operationClass: 'widening',
|
|
1519
|
+
target: {
|
|
1520
|
+
id: 'postgres',
|
|
1521
|
+
details: { schema: 'public', objectType: 'index', name: 'post_meta_gin_3aa57499' },
|
|
1522
|
+
},
|
|
1523
|
+
precheck: [],
|
|
1524
|
+
execute: [
|
|
1525
|
+
{
|
|
1526
|
+
description: 'Set fastupdate = off',
|
|
1527
|
+
sql: 'ALTER INDEX "public"."post_meta_gin_3aa57499" SET (fastupdate = off)',
|
|
1528
|
+
},
|
|
1529
|
+
],
|
|
1530
|
+
postcheck: [],
|
|
1531
|
+
}),
|
|
1532
|
+
];
|
|
1533
|
+
}
|
|
1534
|
+
```
|
|
1535
|
+
|
|
1536
|
+
3. Run `node <migration directory>/migration.ts`. It writes the migration's `ops.json` and its hash into `migration.json`.
|
|
1537
|
+
|
|
1538
|
+
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
|
+
|
|
1540
|
+
#### 5. Sign every database in that release's deploy
|
|
1541
|
+
|
|
1542
|
+
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
|
+
|
|
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:
|
|
1545
|
+
|
|
1546
|
+
```sh
|
|
1547
|
+
prisma db sign --no-advance-ref
|
|
1548
|
+
prisma db migrate
|
|
1549
|
+
```
|
|
1550
|
+
|
|
1551
|
+
If step 4 gave the release a migration, name the directory of the migration before it in the first line, as step 4 says.
|
|
1552
|
+
|
|
1553
|
+
`--no-advance-ref` keeps `db sign` from moving the `db` ref of each space it signs to the contract it signs, which would write `migrations/<space>/refs/db.json` and a snapshot into the checkout the deploy runs from. `db migrate` then advances `db` by its own rule, as in every deploy: not when the CLI detects CI, and not with `--db` (`db-init-db-update-ref-rule`). A deploy that must write no ref, run where CI is not detected, passes `--no-advance-ref` to `db migrate` too.
|
|
1554
|
+
|
|
1555
|
+
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
|
+
|
|
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:
|
|
1558
|
+
|
|
1559
|
+
```sh
|
|
1560
|
+
verify=$(prisma db verify --signature-only --json || true)
|
|
1561
|
+
case "$verify" in
|
|
1562
|
+
*'"code":"CONTRACT.SIGNATURE_MISSING"'*) ;;
|
|
1563
|
+
*) prisma db sign --no-advance-ref ;;
|
|
1564
|
+
esac
|
|
1565
|
+
prisma db migrate
|
|
1566
|
+
```
|
|
1567
|
+
|
|
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.
|
|
1569
|
+
|
|
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.
|
|
1571
|
+
|
|
1572
|
+
##### A database that is still behind
|
|
1573
|
+
|
|
1574
|
+
A database that did not get every migration before the upgrade is behind the newest contract. If at least one of the application's migrations, and none of an extension's, is pending on it, sign it at the contract it is at instead, then let `db migrate` apply the rest:
|
|
1575
|
+
|
|
1576
|
+
```sh
|
|
1577
|
+
prisma db sign --no-advance-ref <migration directory name>
|
|
1578
|
+
prisma db migrate
|
|
1579
|
+
```
|
|
1580
|
+
|
|
1581
|
+
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
|
+
|
|
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:
|
|
1584
|
+
|
|
1585
|
+
- `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
|
+
- `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
|
+
|
|
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.
|
|
1589
|
+
|
|
1590
|
+
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
|
+
|
|
1592
|
+
If no application row ends at the signature's hash, the database was moved at some point by `prisma db update` or `prisma db sign`, and its ledger of applied migrations does not show the contract it is at. Do not guess a directory: `db sign` ignores tables and columns the contract does not have, so it accepts a migration the database has already moved past, and `db migrate` then runs migrations the database already has.
|
|
1593
|
+
|
|
1594
|
+
The route does not apply when an extension's migrations are pending on the database. Whatever contract you name for the application, `db sign` signs each extension at its newest contract, so that extension's pending migrations either make the signature fail or never run. To check after the upgrade that no extension is behind, look at each extension's rows in `prisma migration log`: the last one must end at the first 7 characters of the old hash that the script's output, under "Storage hashes (old -> new)", maps to the hash in `migrations/<extension>/refs/head.json`. Before the upgrade, `prisma migration status` lists the pending migrations of each space directly. Bring such a database, and one whose ledger does not show its contract, to the newest contract with the release you were on before the upgrade, as step 1 says, then sign it with the two lines above. A database whose change policy permits `db update`, such as a development database, can instead be brought to the newest contract with `prisma db update`, which does not run the migrations' data transforms.
|
|
1595
|
+
|
|
1596
|
+
##### If you skip signing
|
|
1597
|
+
|
|
1598
|
+
The database stays usable, but the commands that compare it with the project see a contract they do not know:
|
|
1599
|
+
|
|
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.
|
|
1601
|
+
- `prisma migration status` warns with `MIGRATION.SIGNATURE_NOT_IN_GRAPH`: "Database was updated outside the migration system".
|
|
1602
|
+
- `prisma db verify` fails with `CONTRACT.SIGNATURE_MISMATCH`: "The database is signed with a different contract".
|
|
1603
|
+
- 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.
|
|
1604
|
+
|
|
1605
|
+
##### What `migration status` shows afterwards
|
|
1606
|
+
|
|
1607
|
+
After the upgrade, `prisma migration status` shows none of the migrations applied before it as applied. The database's ledger records each applied migration by its `migrationHash`, the ledger keeps the old values, and the script gave every migration a new one. `prisma migration log` likewise lists the earlier migrations with their old hashes. No command decides anything from the ledger: `db migrate` decides what to apply from the contract signature, which `db sign` moved to the new hash. The ledger is otherwise read only to explain a signature that is outside the migration graph, should that happen later. Migrations applied after the upgrade show as applied.
|
|
1608
|
+
|
|
1609
|
+
## A `__proto__` key in a generated `migration.ts`
|
|
1610
|
+
|
|
1611
|
+
### `migration-ts-proto-key-computed`
|
|
1612
|
+
|
|
1613
|
+
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
|
+
|
|
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:
|
|
1616
|
+
|
|
1617
|
+
```ts
|
|
1618
|
+
// before
|
|
1619
|
+
lit({ __proto__: { x: 1 }, a: 2 })
|
|
1620
|
+
// after
|
|
1621
|
+
lit({ ['__proto__']: { x: 1 }, a: 2 })
|
|
1622
|
+
```
|
|
1623
|
+
|
|
1624
|
+
## Prisma's own tables are in the `prisma` schema
|
|
1625
|
+
|
|
1626
|
+
Prisma 8 keeps a few tables of its own in your PostgreSQL database. The release candidates kept three, in a schema named `prisma_contract`:
|
|
1627
|
+
|
|
1628
|
+
- `marker` recorded which contract (the description of your data model that Prisma emits as `contract.json`) the database was last brought to, once for each contract space. A contract space is a set of tables with its own contract and migrations: the application's own, and one for each extension that brings tables, such as pgvector. From `8.0.0-rc.25` on, the application's row could also hold the database's policies, under its `meta` column.
|
|
1629
|
+
- `ledger` records each migration applied.
|
|
1630
|
+
- `contract` holds the contract of each migration.
|
|
1631
|
+
|
|
1632
|
+
They are now in a schema named `prisma`, and `marker` is replaced by two tables:
|
|
1633
|
+
|
|
1634
|
+
- `prisma.signatures` has one row for each contract space, with the columns `space`, `core_hash`, `profile_hash`, `invariants` and `signed_at`. `signed_at` is the release candidates' `updated_at`. The columns `contract_json`, `canonical_version`, `app_tag` and `meta` are gone.
|
|
1635
|
+
- `prisma.config` has at most one row, for the whole database. Its `policies` column holds the change policy and the data protection policy, in the form a ref's `policies` declares them, with every setting filled in. No row means the default policies.
|
|
1636
|
+
|
|
1637
|
+
`prisma.ledger` and `prisma.contract` are unchanged.
|
|
1638
|
+
|
|
1639
|
+
Prisma now creates and updates these tables with migrations of its own, which it applies before anything else. You run no extra command for this, and these migrations are not listed with your own.
|
|
1640
|
+
|
|
1641
|
+
### `prisma-tables-move-to-prisma-schema`
|
|
1642
|
+
|
|
1643
|
+
#### What the database needs
|
|
1644
|
+
|
|
1645
|
+
The first command that changes the database, `prisma db init`, `prisma db update`, `prisma db migrate` or `prisma db sign`, run with the new release, brings Prisma's tables up to date before it reads anything else. On a database a release candidate set up, it renames the schema `prisma_contract` to `prisma`. Then it copies each row of `marker` into `signatures`, copies the policies on the application's row, when it has them, into `config`, and drops `marker`. Everything Prisma recorded is kept; any other key a project wrote into `meta` is not. Renaming a schema changes only PostgreSQL's catalogue, so it is instant however large the tables are, and `marker` has only one row for each contract space.
|
|
1646
|
+
|
|
1647
|
+
For each database the project deploys to (development, staging, production), run the command the project already uses to change it, `prisma db migrate`, `prisma db update` or `prisma db sign`, once with the new release. Do this before the application on the new release is deployed against that database.
|
|
1648
|
+
|
|
1649
|
+
#### Move every tool that changes the database to this release at once
|
|
1650
|
+
|
|
1651
|
+
Once a database has been brought up to date, a release candidate's `prisma db migrate`, or any other of its commands that change a database, does not see the records Prisma keeps in `prisma`. It creates a new, empty `prisma_contract` schema, concludes that no migration was ever applied, and applies every migration again from the beginning. Operations whose result already holds are skipped. A data migration, or raw SQL with no check that its result already holds, runs again on live data.
|
|
1652
|
+
|
|
1653
|
+
So every service, deploy script and continuous-integration pipeline that changes the database must move to this release together, and from then on only the new release runs migrations against it. Tell the user this before the first database is brought up to date, and list every place in the project that runs a `prisma` command against a database.
|
|
1654
|
+
|
|
1655
|
+
The command renames the schema first, before its own checks. So a command that the database's change policy then refuses, such as `prisma db update` on a database whose policy permits only `db migrate`, or a command the user cancels at a prompt, has still renamed the schema. This is harmless: the rename and the move change only Prisma's own tables, keep every record, and are what the next command would do anyway. The command reads the policies it checks from `prisma.config`, after the move.
|
|
1656
|
+
|
|
1657
|
+
Commands that only read the database do not rename anything: `prisma db verify`, `prisma migration status`, `prisma migration log`, `prisma db migrate --show` and a dry run of a command. Pointed at a database that still has `prisma_contract`, they stop with `CONTRACT.PRISMA_SPACE_BEHIND`, which says that the records Prisma keeps for itself are not up to date with the installed release of Prisma. It tells the user to run the command the project already uses to change its database: `prisma db migrate` in a project that applies migrations, `prisma db update` in one that changes its database with `db update`, or `prisma db sign` in one that only signs it. Each brings the records up to date before it does its usual work, so `prisma db migrate` also applies the pending migrations. This includes `prisma db verify --schema-only`. Run that command, then run the read again.
|
|
1658
|
+
|
|
1659
|
+
The application's check when the client is first used does not stop queries. On such a database it logs a warning with the same code, summary and advice, and runs the query. It logs the warning to the console, or to the `log` the application passes (`default-logger-console`).
|
|
1660
|
+
|
|
1661
|
+
#### When the command stops
|
|
1662
|
+
|
|
1663
|
+
The command checks the following before it renames, and stops without changing anything if one of them fails.
|
|
1664
|
+
|
|
1665
|
+
**The role that runs it does not own the schema and its tables.** PostgreSQL lets a role rename a schema only if it has the privileges of the schema's owner and the CREATE privilege on the database. Later releases of Prisma change these tables with migrations of their own, such as one that adds a column, and this release drops `marker` after moving its rows; PostgreSQL lets a role alter or drop a table only if it has the privileges of the table's owner. So the command checks these privileges before it renames, though creating tables never needed either. If an administrator role created `prisma_contract` or its tables and the role that runs migrations only has grants on them, the command stops with `MIGRATION.PRECHECK_FAILED` and says that the role that runs it must have the privileges of the role that owns `prisma_contract`, or of the role that owns one of its tables. These queries name the owners:
|
|
1666
|
+
|
|
1667
|
+
```sql
|
|
1668
|
+
SELECT nspowner::regrole FROM pg_namespace WHERE nspname = 'prisma_contract';
|
|
1669
|
+
SELECT relname, relowner::regrole FROM pg_class WHERE relnamespace = to_regnamespace('prisma_contract') AND relkind = 'r';
|
|
1670
|
+
```
|
|
1671
|
+
|
|
1672
|
+
Give the schema and its three tables to the role that runs migrations, then run the command as usual. This needs a person with the administrator role, so ask the user first:
|
|
1673
|
+
|
|
1674
|
+
```sql
|
|
1675
|
+
ALTER SCHEMA "prisma_contract" OWNER TO <migrating role>;
|
|
1676
|
+
ALTER TABLE "prisma_contract"."marker" OWNER TO <migrating role>;
|
|
1677
|
+
ALTER TABLE "prisma_contract"."ledger" OWNER TO <migrating role>;
|
|
1678
|
+
ALTER TABLE "prisma_contract"."contract" OWNER TO <migrating role>;
|
|
1679
|
+
```
|
|
1680
|
+
|
|
1681
|
+
Running the command once as the role that owns them also works, but the schema and tables then stay owned by that role, so every later release whose migrations change Prisma's tables needs that role again. Prefer giving them to the role that runs migrations.
|
|
1682
|
+
|
|
1683
|
+
**The role that runs it does not have the CREATE privilege on the database.** The command stops with `MIGRATION.PRECHECK_FAILED` and says that the role that runs it must have the CREATE privilege on the database. This can happen even when the role owns `prisma_contract`. Ask the user whether to grant it, or to run the command once as a role that has it and also owns the schema and its tables. Only the rename needs it:
|
|
1684
|
+
|
|
1685
|
+
```sql
|
|
1686
|
+
GRANT CREATE ON DATABASE <database> TO <migrating role>;
|
|
1687
|
+
```
|
|
1688
|
+
|
|
1689
|
+
**Another object depends on `prisma_contract.marker`.** The command drops `marker` once its rows are moved, and PostgreSQL does not drop a table that a view, a function, a foreign key or another object depends on. The command stops with `MIGRATION.PRECHECK_FAILED` and changes nothing. Its message says that no object outside `prisma_contract.marker` may depend on it, then names each object with its schema, for example "In this database, those objects are view public.marker_view." A function that takes or returns `marker` rows, including an array of them, counts too. Show them to the user and ask whether to drop them; once the command has run, create each again over `prisma.signatures`, or `prisma.config` for the policies.
|
|
1690
|
+
|
|
1691
|
+
**Row-level security is forced on `prisma_contract.marker`.** Row-level security hides rows from a read without an error, so the copy would move only the rows the role may see and the drop would lose the rest. When it applies to the role that runs the command, which for the table's owner means it is forced, the command stops with `MIGRATION.PRECHECK_FAILED` and changes nothing. The role reaches this check only once it owns the schema and its tables, because the ownership checks run first, so it can turn forced row-level security off itself. Ask the user whether to turn it off with `ALTER TABLE "prisma_contract"."marker" NO FORCE ROW LEVEL SECURITY`, or to run the command once as a role that bypasses row-level security and also owns the schema and its tables. A role that bypasses row-level security but owns neither is stopped by the ownership checks instead.
|
|
1692
|
+
|
|
1693
|
+
**A schema named `prisma` already exists and holds something other than Prisma's own tables.** The project may have a schema of its own named `prisma`, for example because its contract declares a namespace `prisma`. This release keeps Prisma's own tables in `prisma` and never mixes them with a project's own objects, so the command checks, whether `prisma_contract` exists or not, that `prisma` is Prisma's. It is when its table `signatures` has the columns every release of Prisma 8 reads, `space`, `core_hash`, `profile_hash` and `invariants`, so a database a later release of Prisma 8 has already changed passes. Otherwise `prisma` may hold only Prisma's own tables, each with exactly the columns this release gives it: `signatures`, `config`, `ledger` and `contract`, and a release candidate's `marker` while its rows wait to be moved. Their indexes, constraints and the sequence behind `ledger.id` belong to them. Anything else, of any kind, counts: a table, view, sequence, function or type of the project's own, or a table with one of those names in another form. The check reads PostgreSQL's catalogue, so it finds every object whatever the role's privileges on it. When it fails, the command stops with `MIGRATION.PRECHECK_FAILED` and changes nothing, on a new database as on one a release candidate set up. Its summary names what it found, for example `Schema "prisma" holds table prisma.users and view prisma.emails, which Prisma did not create.` The explanation starts with `Schema "prisma" must hold nothing but Prisma's own tables` and ends by naming each object again, for example `In this database, those objects are table prisma.users and view prisma.emails.`
|
|
1694
|
+
|
|
1695
|
+
This is the project's own schema, not Prisma's records. Stop and tell the user that this release keeps Prisma's own tables in a schema named `prisma`, so the project's schema needs another name. With the user's approval, rename it:
|
|
1696
|
+
|
|
1697
|
+
```sql
|
|
1698
|
+
ALTER SCHEMA "prisma" RENAME TO <other schema>;
|
|
1699
|
+
```
|
|
1700
|
+
|
|
1701
|
+
Then change the project's code, grants and scripts that name it. If the project's contract declares the namespace `prisma`, follow `rename-a-namespace-named-prisma` below as well, before anything else runs against the database. Then run the command again: no schema named `prisma` exists any more, so it creates `prisma`, or renames `prisma_contract` to it on a database a release candidate set up. If the user would rather keep only some of the objects in place, move each of them to another schema instead (for example `ALTER TABLE "prisma"."<table>" SET SCHEMA <other schema>`, `ALTER FUNCTION "prisma"."<function>"(<argument types>) SET SCHEMA <other schema>` or `ALTER TYPE "prisma"."<type>" SET SCHEMA <other schema>`) and drop the rest, with the user's approval.
|
|
1702
|
+
|
|
1703
|
+
If the objects it names include a table named `signatures`, `config`, `marker`, `ledger` or `contract`, do not drop or change it before you know what it holds: it is in a form Prisma does not give it, so it is either the project's own table or Prisma's records from something other than this release. List the tables in each schema, as described below, and stop and ask the user.
|
|
1704
|
+
|
|
1705
|
+
**The role that runs it may not create tables in an empty `prisma`.** The project or its provisioning code may have created an empty `prisma` ahead of the upgrade, for example an administrator who creates every schema and grants the role that runs migrations `USAGE` and `CREATE` on it. On a new database, the command keeps Prisma's tables in such a `prisma`, and the role need not own the schema: the tables it creates are its own, which is what later releases need to change them. Without `USAGE` and `CREATE` on `prisma`, the command stops with `MIGRATION.PRECHECK_FAILED`, changes nothing, and says so. Ask the user whether to grant them, or to drop the empty schema:
|
|
1706
|
+
|
|
1707
|
+
```sql
|
|
1708
|
+
GRANT USAGE, CREATE ON SCHEMA "prisma" TO <migrating role>;
|
|
1709
|
+
-- or
|
|
1710
|
+
DROP SCHEMA "prisma";
|
|
1711
|
+
```
|
|
1712
|
+
|
|
1713
|
+
On a database a release candidate set up, the command instead drops the empty `prisma` and renames `prisma_contract` to it. Dropping a schema needs the privileges of its owner, so there the command stops, changes nothing, and says that the role must have the privileges of the role that owns `prisma`. Ask the user whether to give the empty schema to the role that runs migrations with `ALTER SCHEMA "prisma" OWNER TO <migrating role>`, or to drop it.
|
|
1714
|
+
|
|
1715
|
+
On a database a release candidate set up, the command drops an empty `prisma` before the rename, with a plain `DROP SCHEMA "prisma"`. Any grants and default privileges set on that empty `prisma` go with it; the renamed schema keeps the grants of `prisma_contract`. So apply changes to provisioning code that name `prisma` after the first command has run against the database, or apply them again then.
|
|
1716
|
+
|
|
1717
|
+
**`prisma_contract` exists and `prisma` holds Prisma's own tables too.** Prisma does not choose between the two schemas. The command stops with `MIGRATION.PRECHECK_FAILED`, changes nothing, and its explanation starts with `Schema "prisma" must be empty while schema "prisma_contract" exists.` Do not drop either schema before you know which holds the records. First list the tables in each:
|
|
1718
|
+
|
|
1719
|
+
```sql
|
|
1720
|
+
SELECT n.nspname, c.relname FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
1721
|
+
WHERE n.nspname IN ('prisma_contract', 'prisma') AND c.relkind IN ('r', 'p', 'f', 'v', 'm') ORDER BY 1, 2;
|
|
1722
|
+
```
|
|
1723
|
+
|
|
1724
|
+
This reads the catalogue, so it lists every table, partitioned table, foreign table and view whatever the role's privileges on it. Then count the rows of `marker`, `signatures` and `ledger` in each schema that has them. If the role may not read one of them, ask the user to run the count as a role that may. Stop and ask the user, because a schema that is dropped loses its rows.
|
|
1725
|
+
|
|
1726
|
+
**`prisma_contract` holds something other than the release candidates' tables.** The command renames `prisma_contract` to `prisma`, which holds only Prisma's own tables, so it first checks that `prisma_contract` holds nothing but the tables `marker`, `ledger` and `contract`, with their sequences (such as the one behind `ledger.id`), indexes and constraints. These three are Prisma's tables whatever columns the project added to them, such as an audit column on `ledger`: the checks of their columns accept extra columns, and the command renames `ledger` and `contract` and keeps them with those columns. `marker` is different, as the next paragraph says. A view, table, function or other object the project put there, such as a report over `prisma_contract.ledger`, stops the command with `MIGRATION.PRECHECK_FAILED` before anything changes. Its summary names each object, for example `Schema "prisma_contract" holds view prisma_contract.migrations_by_space, which Prisma did not create.` Show them to the user and ask whether to move each to a schema of the project's own, for example `ALTER VIEW "prisma_contract"."migrations_by_space" SET SCHEMA <other schema>`, or to drop it. A view moved that way still reads Prisma's tables after the rename, since PostgreSQL follows the table, not its name. Never drop or move `marker`, `ledger` or `contract` to get past this check: they hold Prisma's records, and the check never names them.
|
|
1727
|
+
|
|
1728
|
+
**The project added a column to `prisma_contract.marker`.** The command copies the rows of `marker` into `signatures` and `config`, which keep only some of its columns, and then drops it, so the data in a column the project added would be lost. So before anything changes, the command checks that `marker` has no columns but the release candidates' (`space`, `core_hash`, `profile_hash`, `contract_json`, `canonical_version`, `updated_at`, `app_tag`, `meta` and `invariants`), and stops with `MIGRATION.PRECHECK_FAILED` otherwise. Its summary names each added column, for example `Table "prisma_contract"."marker" has column note, which Prisma did not create and does not keep.` Show it to the user and ask where its data should go. Copy it to a table of the project's own, for example `CREATE TABLE <table> AS SELECT "space", <column> FROM "prisma_contract"."marker"`, then drop the column with `ALTER TABLE "prisma_contract"."marker" DROP COLUMN <column>`, and run the command again. Drop the column only once the user has agreed, since dropping it loses its data.
|
|
1729
|
+
|
|
1730
|
+
For the checks that name objects they found, the command's summary names them, as above. Every check points to these instructions. For every other check, the command's summary is `The records Prisma keeps for itself in this database could not be brought up to date`, and its explanation is the check that failed.
|
|
1731
|
+
|
|
1732
|
+
**A table in `prisma_contract` is in a form from before the release candidates.** Prisma checks the columns of each of its tables. A database set up by a `0.x` release can have tables in an older form, and those forms are not migrated. The command stops with an error that names the table and the column it expected. Stop and tell the user. Prisma's tables in such a database cannot be kept, but the application's own tables can. First list everything in `prisma_contract` and show it to the user:
|
|
1733
|
+
|
|
1734
|
+
```sql
|
|
1735
|
+
SELECT pg_describe_object(classid, objid, objsubid) FROM pg_depend
|
|
1736
|
+
WHERE refclassid = 'pg_namespace'::regclass AND refobjid = to_regnamespace('prisma_contract') AND deptype = 'n';
|
|
1737
|
+
```
|
|
1738
|
+
|
|
1739
|
+
The list also shows `sequence prisma_contract.ledger_id_seq`, which belongs to the `ledger` table and is dropped with it. If it holds anything other than Prisma's tables `marker`, `ledger` and `contract` and that sequence, ask the user whether to move each such object to another schema or drop it, and do neither without their approval. Then, after a backup and with the user's approval, drop Prisma's tables and the schema without `CASCADE`:
|
|
1740
|
+
|
|
1741
|
+
```sql
|
|
1742
|
+
DROP TABLE IF EXISTS "prisma_contract"."marker", "prisma_contract"."ledger", "prisma_contract"."contract";
|
|
1743
|
+
DROP SCHEMA "prisma_contract";
|
|
1744
|
+
```
|
|
1745
|
+
|
|
1746
|
+
Without `CASCADE`, PostgreSQL refuses and names the object when something outside the schema, such as a view, a foreign key or a function, depends on one of these tables, or when the schema still holds something else. Show that error to the user and ask what to do; do not add `CASCADE`, which drops those objects too. Then run `prisma db sign`, which checks that the database matches the contract and records it in a new `prisma.signatures`. The history of applied migrations in the old `ledger` is lost. No release before the release candidates recorded policies, so the database keeps the default policies it had.
|
|
1747
|
+
|
|
1748
|
+
**A table in `prisma` is not in the form this release creates.** Prisma reads and writes its tables only in the form it creates. A table of one of its names in `prisma` in another form is named by the check that `prisma` holds only Prisma's own tables, described above: for example the project keeps a table of its own named `signatures`, `config`, `marker`, `ledger` or `contract` in a schema of its own named `prisma`. Stop and tell the user. Do not drop or change the table without asking. If it is the project's own table, it can be moved to another schema with `ALTER TABLE "prisma"."<table>" SET SCHEMA <other schema>`, after which the command can run again; the project's code that names it must then name the other schema.
|
|
1749
|
+
|
|
1750
|
+
#### Check each database before the deploy
|
|
1751
|
+
|
|
1752
|
+
The checks above run in the deploy of the upgrade, and several need an administrator to fix. Find them before that deploy. Run these read-only queries against each PostgreSQL database, connected as the role that will run the deploy's `prisma` commands. Queries 1 to 6 each mirror one check of the command, and return a row only when that check would stop it. Query 7 is different: it lists a schema named `prisma` and what it holds, which is not by itself a problem. A database with no `prisma_contract` returns no row from the queries that name it; the command creates `prisma` there.
|
|
1753
|
+
|
|
1754
|
+
```sql
|
|
1755
|
+
-- 1. The role lacks the privileges of the owner of prisma_contract or of one of its tables
|
|
1756
|
+
SELECT 'schema prisma_contract' AS object, nspowner::regrole AS owner FROM pg_namespace
|
|
1757
|
+
WHERE nspname = 'prisma_contract' AND NOT pg_has_role(current_user, nspowner, 'USAGE')
|
|
1758
|
+
AND NOT (SELECT rolsuper FROM pg_roles WHERE rolname = current_user)
|
|
1759
|
+
UNION ALL
|
|
1760
|
+
SELECT 'table prisma_contract.' || relname, relowner::regrole FROM pg_class
|
|
1761
|
+
WHERE relnamespace = to_regnamespace('prisma_contract') AND relname IN ('marker', 'ledger', 'contract')
|
|
1762
|
+
AND NOT pg_has_role(current_user, relowner, 'USAGE')
|
|
1763
|
+
AND NOT (SELECT rolsuper FROM pg_roles WHERE rolname = current_user);
|
|
1764
|
+
|
|
1765
|
+
-- 2. The role lacks the CREATE privilege on the database, which renaming prisma_contract needs
|
|
1766
|
+
SELECT 'no CREATE on the database' AS problem
|
|
1767
|
+
WHERE to_regnamespace('prisma_contract') IS NOT NULL
|
|
1768
|
+
AND NOT has_database_privilege(current_database(), 'CREATE')
|
|
1769
|
+
AND NOT (SELECT rolsuper FROM pg_roles WHERE rolname = current_user);
|
|
1770
|
+
|
|
1771
|
+
-- 3. prisma_contract holds something other than the tables marker, ledger and contract and the sequences their columns own
|
|
1772
|
+
SELECT pg_describe_object(d.classid, d.objid, d.objsubid) AS object FROM pg_depend d
|
|
1773
|
+
WHERE d.refclassid = 'pg_namespace'::regclass AND d.refobjid = to_regnamespace('prisma_contract') AND d.deptype = 'n'
|
|
1774
|
+
AND NOT (d.classid = 'pg_class'::regclass AND d.objid IN (
|
|
1775
|
+
SELECT c.oid FROM pg_class c
|
|
1776
|
+
WHERE c.relnamespace = to_regnamespace('prisma_contract') AND c.relkind = 'r'
|
|
1777
|
+
AND c.relname IN ('marker', 'ledger', 'contract')
|
|
1778
|
+
UNION ALL
|
|
1779
|
+
SELECT dep.objid FROM pg_depend dep JOIN pg_class t ON t.oid = dep.refobjid
|
|
1780
|
+
WHERE dep.classid = 'pg_class'::regclass AND dep.refclassid = 'pg_class'::regclass
|
|
1781
|
+
AND dep.deptype IN ('a', 'i') AND t.relnamespace = to_regnamespace('prisma_contract')));
|
|
1782
|
+
|
|
1783
|
+
-- 4. An object outside marker depends on it, on its row type or on the array of its row type
|
|
1784
|
+
SELECT DISTINCT pg_describe_object(d.classid, d.objid, d.objsubid) AS object
|
|
1785
|
+
FROM pg_depend d
|
|
1786
|
+
JOIN pg_class c ON c.oid = to_regclass('prisma_contract.marker')
|
|
1787
|
+
JOIN pg_type t ON t.oid = c.reltype
|
|
1788
|
+
WHERE d.deptype = 'n'
|
|
1789
|
+
AND ((d.refclassid = 'pg_class'::regclass AND d.refobjid = c.oid)
|
|
1790
|
+
OR (d.refclassid = 'pg_type'::regclass AND d.refobjid IN (c.reltype, t.typarray)))
|
|
1791
|
+
AND NOT (d.classid = 'pg_class'::regclass AND d.objid = c.oid);
|
|
1792
|
+
|
|
1793
|
+
-- 5. Row-level security can hide rows of marker from the role
|
|
1794
|
+
SELECT relname FROM pg_class
|
|
1795
|
+
WHERE oid = to_regclass('prisma_contract.marker') AND relrowsecurity
|
|
1796
|
+
AND (relforcerowsecurity OR NOT pg_has_role(current_user, relowner, 'USAGE'))
|
|
1797
|
+
AND NOT (SELECT rolsuper OR rolbypassrls FROM pg_roles WHERE rolname = current_user);
|
|
1798
|
+
|
|
1799
|
+
-- 6. marker has a column the project added
|
|
1800
|
+
SELECT attname FROM pg_attribute
|
|
1801
|
+
WHERE attrelid = to_regclass('prisma_contract.marker') AND attnum > 0 AND NOT attisdropped
|
|
1802
|
+
AND attname NOT IN ('space', 'core_hash', 'profile_hash', 'contract_json', 'canonical_version', 'updated_at', 'app_tag', 'meta', 'invariants');
|
|
1803
|
+
|
|
1804
|
+
-- 7. A schema named prisma exists, and what it holds
|
|
1805
|
+
SELECT n.nspname, pg_describe_object(d.classid, d.objid, d.objsubid) AS object
|
|
1806
|
+
FROM pg_namespace n LEFT JOIN pg_depend d
|
|
1807
|
+
ON d.refclassid = 'pg_namespace'::regclass AND d.refobjid = n.oid AND d.deptype = 'n'
|
|
1808
|
+
WHERE n.nspname = 'prisma';
|
|
1809
|
+
```
|
|
1810
|
+
|
|
1811
|
+
What to do with each result:
|
|
1812
|
+
|
|
1813
|
+
- Queries 1 to 6: each row is a check that stops the command. Fix it as the paragraph above on that check says, then run the query again.
|
|
1814
|
+
- Query 7 is different: a row is not by itself a problem. A row whose `object` is empty means an empty `prisma` schema. On a new database the command keeps Prisma's tables in it, if the role has `USAGE` and `CREATE` on it; on a database a release candidate set up, the command drops it before the rename, if the role has the privileges of its owner. Rows that name objects mean `prisma` holds something, and the paragraph on a schema named `prisma` that already exists says when that stops the command. Read those paragraphs and decide with the user. Do not drop or rename a `prisma` schema that the project or its provisioning code created on purpose, and never drop one that holds anything, without the user's approval.
|
|
1815
|
+
|
|
1816
|
+
On SQLite, check each database for what `sqlite-prisma-tables-renamed` lists: a view or trigger that names `_prisma_marker` or `_prisma_ledger`, a foreign key to either, a column the project added to either, and an object named `prisma_signatures`, `prisma_config` or `prisma_ledger`. `sqlite3 <database file> .schema` prints all of them.
|
|
1817
|
+
|
|
1818
|
+
#### After the database is brought up to date
|
|
1819
|
+
|
|
1820
|
+
A release candidate's application pointed at the database finds no contract signature in `prisma_contract` and keeps running, so instances of the old application that run during a deploy keep working. It logs a warning about the missing signature only when the application gives its client a `log`.
|
|
1821
|
+
|
|
1822
|
+
A release candidate's command-line tool must not be used against the database again. As the section on moving every tool at once says, it creates a new `prisma_contract` schema beside `prisma`, writes its records there, and applies every migration again; the new release neither reads those records nor reports them. Its `prisma db verify` reports that the database is not signed and suggests `prisma db sign`, which would also write into a new `prisma_contract`.
|
|
1823
|
+
|
|
1824
|
+
If a release candidate's tool may have run against the database after it was brought up to date, check whether a `prisma_contract` schema exists again:
|
|
1825
|
+
|
|
1826
|
+
```sql
|
|
1827
|
+
SELECT count(*) FROM pg_namespace WHERE nspname = 'prisma_contract';
|
|
1828
|
+
```
|
|
1829
|
+
|
|
1830
|
+
If it does, the older tool ran migrations against the database from the beginning. List what it recorded:
|
|
1831
|
+
|
|
1832
|
+
```sql
|
|
1833
|
+
SELECT space, migration_name, destination_core_hash FROM prisma_contract.ledger ORDER BY id;
|
|
1834
|
+
```
|
|
1835
|
+
|
|
1836
|
+
Compare each row with `prisma.ledger` by space and `destination_core_hash`, not by migration name. A database first set up by `prisma db init` has a ledger row with an empty `migration_name` for the contract `db init` reached, so a migration that leads to the same contract has a name only in `prisma_contract`.
|
|
1837
|
+
|
|
1838
|
+
- A row whose destination is also a destination in `prisma.ledger` for the same space is a migration the older tool ran again. Its operations whose result already held were skipped, but its data migrations, and raw SQL with no such check, ran a second time.
|
|
1839
|
+
- A row whose destination is not in `prisma.ledger` is a migration only the older tool applied, and it is not in the new release's history.
|
|
1840
|
+
|
|
1841
|
+
Stop and tell the user what you found before dropping anything.
|
|
1842
|
+
|
|
1843
|
+
### `name-the-prisma-schema`
|
|
1844
|
+
|
|
1845
|
+
PostgreSQL keeps grants when a schema is renamed, so roles that were granted privileges on the schema `prisma_contract` or on its `ledger` and `contract` tables keep them. Grants on `prisma_contract.marker` do not carry over: the table is dropped once its rows are moved, and `prisma.signatures` and `prisma.config` are new tables, which only their owner and superusers may read, unless default privileges for the role that runs the command (`ALTER DEFAULT PRIVILEGES`) grant more. Anything that names the schema or the `marker` table in its own text still names the old one.
|
|
1846
|
+
|
|
1847
|
+
Search the project for `prisma_contract`, outside `node_modules` and build output. Look in particular at:
|
|
1848
|
+
|
|
1849
|
+
- SQL files the project runs itself.
|
|
1850
|
+
- Migrations: do not edit a migration that has been planned. Its hash covers its SQL, so an edited migration fails to load with `MIGRATION.HASH_MISMATCH`. A migration that names `prisma_contract` and has already been applied to every database needs no change. If one will still run on a database that has not applied it, stop and tell the user: from this release it fails there, because the schema it names no longer exists, and the user decides how to replace it.
|
|
1851
|
+
- Scripts that drop or reset the database, such as a `drop-db` or `reset` script, and test helpers that reset the database between tests.
|
|
1852
|
+
- Infrastructure code that grants privileges, such as Terraform, Pulumi, Helm charts or SQL run by a provisioning step.
|
|
1853
|
+
- Monitoring and alerting queries.
|
|
1854
|
+
- Row-level-security setup.
|
|
1855
|
+
|
|
1856
|
+
Replace `prisma_contract` with `prisma` in each of these, except planned migrations, which stay as they are. `prisma` needs no quotes in SQL. Where one of them names the `marker` table, name the table that now holds what it uses:
|
|
1857
|
+
|
|
1858
|
+
- The contract a space was signed with, its hashes and its invariants: `prisma.signatures`, which has the columns `space`, `core_hash`, `profile_hash`, `invariants` and `signed_at`. Use `signed_at` where it used `updated_at`. The columns `contract_json`, `canonical_version`, `app_tag` and `meta` are gone, and nothing replaces the first three.
|
|
1859
|
+
- The change policy and the data protection policy, which it read from `meta` on the application's row (`meta -> 'policies'`): the `policies` column of `prisma.config`, which has at most one row. No row means the default policies.
|
|
1860
|
+
|
|
1861
|
+
The application's role reads `prisma.signatures` when the client is first used, to check which contract the database was signed with. It does not read `prisma.config`. Without `SELECT` on `prisma.signatures`, that check cannot read which contract the database was signed with, and queries still run. It logs a warning, to the console unless the application passes its own `log`: `CONTRACT.SIGNATURE_MISSING` ("Contract signature not found in database"), because Prisma looks for the table in `information_schema.tables`, which lists only tables the role has a privilege on. A client created with `verifyContractSignature: false` makes no such check.
|
|
1862
|
+
|
|
1863
|
+
A role that runs Prisma's commands may read more. `prisma db migrate`, `db migrate --show`, `db update` and `db sign` read the policies from `prisma.config`, so a role that runs them needs `SELECT` on `prisma.signatures` and on `prisma.config`. Without `SELECT` on `prisma.config`, the command stops with `CONTRACT.DATABASE_POLICIES_READ_FAILED` and names `prisma.config`; it never reads the default policies in their place. It stops the same way when row-level security applies to the role on `prisma.config`, because a row that row-level security hides cannot be told apart from no row. `prisma migration status` reports the same code as a warning and still gives its report. `prisma db verify` does not read the policies, so it needs `SELECT` on `prisma.signatures` only.
|
|
1864
|
+
|
|
1865
|
+
A role that owns these tables needs no grant. The role that ran the first command of this release against the database owns `prisma.signatures` and `prisma.config`, so an application that connects as that role, as a default Supabase project does with `postgres`, needs nothing. Only an application that connects as another role needs the grant.
|
|
1866
|
+
|
|
1867
|
+
For example, for the application's role, `app`:
|
|
1868
|
+
|
|
1869
|
+
```sql
|
|
1870
|
+
-- Before
|
|
1871
|
+
GRANT USAGE ON SCHEMA prisma_contract TO app;
|
|
1872
|
+
GRANT SELECT ON prisma_contract.marker TO app;
|
|
1873
|
+
|
|
1874
|
+
-- After
|
|
1875
|
+
GRANT USAGE ON SCHEMA prisma TO app;
|
|
1876
|
+
GRANT SELECT ON prisma.signatures TO app;
|
|
1877
|
+
```
|
|
1878
|
+
|
|
1879
|
+
Apply a change like this to each database after the first command of the new release has run against it: before that, `prisma` and its new tables do not exist, and the grants on the schema `prisma_contract` carry over in the rename anyway. The grant on `signatures` is needed from the moment that command has run, so apply it right after it, before the application on the new release is deployed. Do not make provisioning code create `prisma` ahead of the upgrade to make such a grant succeed; the command drops an empty `prisma` before the rename, with its grants.
|
|
1880
|
+
|
|
1881
|
+
A script that drops Prisma's tables to reset a database should drop `prisma`. If it also runs against databases that have not been brought up to date yet, keep a second statement that drops `prisma_contract`:
|
|
1882
|
+
|
|
1883
|
+
```ts
|
|
1884
|
+
await client.query('DROP SCHEMA IF EXISTS prisma CASCADE');
|
|
1885
|
+
await client.query('DROP SCHEMA IF EXISTS prisma_contract CASCADE');
|
|
1886
|
+
```
|
|
1887
|
+
|
|
1888
|
+
A test that creates Prisma's tables by hand must create them in `prisma`.
|
|
1889
|
+
|
|
1890
|
+
Prisma Studio reads the `ledger` and `contract` tables for its Migrations view. Studio 0.37.0 is the first version that reads them from `prisma`: versions before 0.36.0 read them from `prisma_contract`, and 0.36.0 reads them from `_prisma`, a schema no release of Prisma uses. So once the database has been brought up to date, the Migrations view of an earlier Studio is empty. Where the project depends on `@prisma/studio-core`, upgrade it to 0.37.0 or later. If the user runs Studio some other way, tell them an empty Migrations view means their Studio is older than 0.37.0, and that the records are still in `prisma.ledger` and `prisma.contract`.
|
|
1891
|
+
|
|
1892
|
+
### `rename-a-namespace-named-prisma`
|
|
1893
|
+
|
|
1894
|
+
On PostgreSQL, each namespace of the project's contract is a schema in the database. The schemas `prisma` and `prisma_contract` are reserved for Prisma's own tables: this release keeps them in `prisma`, and the release candidates kept them in `prisma_contract`. So the project's contract may not declare a namespace whose schema has either name. `prisma migration plan`, `prisma db init` and `prisma db update` refuse such a contract with `MIGRATION.PLANNING_FAILED`, and `prisma db migrate` refuses a migration that leads to one with `MIGRATION.CONTRACT_SPACE_VIOLATION`. Both say, for example, `Namespace "prisma" of this contract is the schema "prisma", which is reserved for Prisma's own tables.` Neither changes the database. `prisma contract emit` does not refuse the contract.
|
|
1895
|
+
|
|
1896
|
+
Look in the contract source for a namespace named `prisma` or `prisma_contract`: `namespace prisma {` in a `.prisma` file, or, for a TypeScript contract, a namespace with either id in the emitted `contract.json` under `storage.namespaces`. If there is none, nothing needs to change.
|
|
1897
|
+
|
|
1898
|
+
If there is one, stop and tell the user that the namespace and the schema need another name, and ask which. Then, with the user's approval:
|
|
1899
|
+
|
|
1900
|
+
1. In each database that has the schema, rename it, before the first command of this release runs against that database: that command brings Prisma's own tables up to date first and stops while the project's schema is named `prisma`.
|
|
1901
|
+
|
|
1902
|
+
```sql
|
|
1903
|
+
ALTER SCHEMA "prisma" RENAME TO <new name>;
|
|
1904
|
+
```
|
|
1905
|
+
|
|
1906
|
+
2. Rename the namespace in the contract source, change every place in the project that names the schema, and run `prisma contract emit`.
|
|
1907
|
+
3. A project that changes its databases with `prisma db update` then runs it as usual: it reads each database as it is.
|
|
1908
|
+
|
|
1909
|
+
A project that applies migrations needs the user's decision before step 1. Its planned migrations create the schema `prisma` and the project's tables in it, and a planned migration is not edited. On a new database, this release creates Prisma's own tables in `prisma` before it applies the project's migrations, so those migrations cannot run there as they are. On an existing database, the records of applied migrations name the old contract, whose namespace is `prisma`. Tell the user both, and do not edit, delete or plan migrations until they decide how to proceed.
|
|
1910
|
+
|
|
1911
|
+
## The marker table is split into signatures and config
|
|
1912
|
+
|
|
1913
|
+
### `marker-table-is-signatures`
|
|
1914
|
+
|
|
1915
|
+
The change `prisma-tables-move-to-prisma-schema` describes the whole upgrade, including how the first command moves the rows. This entry covers only text in the project that names the marker table.
|
|
1916
|
+
|
|
1917
|
+
Search the project for `prisma.marker` and `prisma_contract.marker`, also written with quoted names (`"prisma"."marker"`, `"prisma_contract"."marker"`), outside `node_modules`, build output and planned migrations, and for docs that describe "the marker table". Also search for SQL that names `marker` without a schema, in code that sets `search_path` to include `prisma_contract`: such a query reads the same table when no schema earlier in that `search_path` has a `marker` of its own (check that before rewriting it; if one does, the query is the project's, and stays), and fails once Prisma's is dropped; changing `search_path` does not help, since `prisma` has no `marker` either. This upgrade does not edit planned migrations: a migration's hash covers its SQL, and a migration a database has already applied must stay as it ran. Search them too, for the same names, but only to read. A planned migration that names the marker table follows the rule `prisma-tables-move-to-prisma-schema` gives for one that names `prisma_contract`: if it has already been applied to every database it needs no change; if it will still run on a database that has not applied it, stop and tell the user that from this release it fails there, because the table it names no longer exists, and the user decides how to replace it. In each of the other matches:
|
|
1918
|
+
|
|
1919
|
+
- Where it reads which contract a space was signed with, its hashes or its invariants, name `prisma.signatures`. Use `signed_at` where it used `updated_at`. The columns `contract_json`, `canonical_version`, `app_tag` and `meta` are gone.
|
|
1920
|
+
- Where it reads the policies from `meta -> 'policies'` on the application's row, read the `policies` column of `prisma.config`, which has at most one row.
|
|
1921
|
+
|
|
1922
|
+
`prisma.signatures` also has a row for the space `_prisma`, the contract space of Prisma's own tables. A query or a doc that lists every space should leave it out or say it is there. For example:
|
|
1923
|
+
|
|
1924
|
+
```sql
|
|
1925
|
+
-- Before
|
|
1926
|
+
select space, core_hash, invariants from prisma_contract.marker order by space;
|
|
1927
|
+
|
|
1928
|
+
-- After
|
|
1929
|
+
select space, core_hash, invariants from prisma.signatures where space <> '_prisma' order by space;
|
|
1930
|
+
```
|
|
1931
|
+
|
|
1932
|
+
## Prisma's own tables on SQLite have new names
|
|
1933
|
+
|
|
1934
|
+
### `sqlite-prisma-tables-renamed`
|
|
1935
|
+
|
|
1936
|
+
Every service and pipeline that changes a SQLite database must move to this release at the same time. Once this release has moved a database's tables, a release candidate's command-line tool no longer finds them, concludes the database was never migrated, and applies every migration again from the beginning.
|
|
1937
|
+
|
|
1938
|
+
Search the project for `_prisma_marker` and `_prisma_ledger`, outside `node_modules`, build output and planned migrations. Search planned migrations too, but only to read: a migration's hash covers its SQL, so this upgrade does not edit them. If a planned migration that names one of these tables will still run on a database that has not applied it, stop and tell the user that from this release it fails there, because the table no longer exists; the user decides how to replace it. In each other match:
|
|
1939
|
+
|
|
1940
|
+
- Where it reads which contract a space was signed with, its hashes or its invariants, name `prisma_signatures`. Use `signed_at` where it used `updated_at`. The columns `contract_json`, `canonical_version`, `app_tag` and `meta` are gone.
|
|
1941
|
+
- Where it reads the policies from `meta` on the application's row (`json_extract(meta, '$.policies')`), read the `policies` column of `prisma_config`.
|
|
1942
|
+
- Where it reads the ledger, name `prisma_ledger`. Its columns `contract_json_before` and `contract_json_after` are gone; no release wrote them.
|
|
1943
|
+
|
|
1944
|
+
`prisma_signatures` and `prisma_ledger` also have rows for the space `_prisma`, the contract space of Prisma's own tables. A query or a doc that lists every space should leave it out or say it is there. For example:
|
|
1945
|
+
|
|
1946
|
+
```sql
|
|
1947
|
+
-- Before
|
|
1948
|
+
SELECT space, core_hash FROM _prisma_marker ORDER BY space;
|
|
1949
|
+
|
|
1950
|
+
-- After
|
|
1951
|
+
SELECT space, core_hash FROM prisma_signatures WHERE space <> '_prisma' ORDER BY space;
|
|
1952
|
+
```
|
|
1953
|
+
|
|
1954
|
+
While `_prisma_marker` or `_prisma_ledger` exists, a view or trigger that names it, even in a string, or a project table with a foreign key to it, stops the first command before anything changes, and the message names each one. Remove such a foreign key by rebuilding the table without it. Drop it, run the command, then create it again over the new tables. Once the old tables are gone, such a view stops nothing.
|
|
1955
|
+
|
|
1956
|
+
A column a project added to `_prisma_marker` or `_prisma_ledger`, generated or not, also stops the first command, and the message names it, because the command drops those tables. Copy its data to a table of the project's own, drop the column with `ALTER TABLE "<table>" DROP COLUMN <column>`, then run the command again.
|
|
1957
|
+
|
|
1958
|
+
The first command also stops on an object that takes one of Prisma's table names, `prisma_signatures`, `prisma_config` or `prisma_ledger`, in any letter case:
|
|
1959
|
+
|
|
1960
|
+
- An index or view of one of these names always stops it. SQLite cannot rename an index or a view: drop it and create it again under another name.
|
|
1961
|
+
- A project table of one of these names stops it, unless Prisma can take it as its own. Prisma takes a table whose columns are exactly Prisma's, with Prisma's types and nullability. Once `prisma_signatures` has the four columns every release reads (`space`, `core_hash`, `profile_hash`, `invariants`), it also takes all three tables with extra columns, because a later release may have added them; each table must still have every one of Prisma's columns, with Prisma's types and nullability. For example, a `prisma_config` with columns `id`, `policies` and `theme` stops the command on a database without Prisma's tables but is taken once `prisma_signatures` is Prisma's, while a `prisma_ledger` that lacks `operations`, or whose `operations` is not `TEXT NOT NULL`, always stops it. Map the model to another table name in the contract, and rename the table with `ALTER TABLE "<table>" RENAME TO <new name>` before running the command.
|
|
1962
|
+
- The planner refuses a contract that declares a table of one of these names.
|
|
1963
|
+
|
|
1964
|
+
## `db init` and `db update` advance the `db` ref by the same rule as `db migrate`
|
|
1965
|
+
|
|
1966
|
+
### `db-init-db-update-ref-rule`
|
|
1967
|
+
|
|
1968
|
+
`prisma db init` and `prisma db update` now advance refs by the rule `prisma db migrate` follows. Without `--advance-ref`, they no longer advance the `db` ref when the CLI detects CI, and say so with `MIGRATION.REF_NOT_ADVANCED_IN_CI`; they still advance nothing with `--db`. Both take the new `--no-advance-ref`, which a pipeline passes to write no ref and silence the notice. A ref they cannot write is now a warning and the command exits 0, which matters to a script that checks their exit code. A pipeline or script that runs `db init` or `db update` from the config in CI and needs `migrations/app/refs/db.json` written passes `--advance-ref db`. Without a ref they also store no snapshot of the contract they applied, so a pipeline that later runs `db update` with statements such as `--rename` passes `--advance-ref <name>` on the earlier run. The detection finds `db init` and `db update` commands that pass `--advance-ref`, and those that pass neither `--db` nor `--no-advance-ref`, including a Dockerfile's exec form, a YAML list and a command split with a backslash between `db` and the command; it reads the flags only up to the end of that command on its line (a `;`, `&`, `|` or an unescaped quote, so a command in a JSON string is read alone, and an exec form such as `["prisma","db","update","--db","$URL"]` matches even with `--db`); check each against the cases below, and look for others in files it does not search.
|
|
1969
|
+
|
|
1970
|
+
`prisma db init` and `prisma db update` move the `db` ref to the contract the database is at only when the connection comes from `db.connection` in `prisma.config.ts` and the CLI does not detect CI, as `prisma db migrate` does. Unless the `CI` environment variable is `false`, which turns detection off whatever else is set, the CLI detects CI when `CI` is set or when a variable that CI services set is present, such as `BUILD_NUMBER`, `BUILD_ID` or `GITHUB_ACTIONS`. When CI detection is what stops the advance, the command says so with `MIGRATION.REF_NOT_ADVANCED_IN_CI`, in one line: `Ref db not advanced because CI was detected. Silence this warning with --no-advance-ref.` `prisma db migrate` prints the same line; its notice used to be several lines long with next actions, so a script or test that matched that text matches the code `MIGRATION.REF_NOT_ADVANCED_IN_CI` instead.
|
|
1971
|
+
|
|
1972
|
+
| Situation | Before | Now |
|
|
1973
|
+
| --- | --- | --- |
|
|
1974
|
+
| Connection from `prisma.config.ts`, CI not detected | `db` | `db` |
|
|
1975
|
+
| Connection from `prisma.config.ts`, CI detected | `db` | None, and the run says so |
|
|
1976
|
+
| `--db <url>` | None | None |
|
|
1977
|
+
| `--advance-ref <name>` | `<name>` | `<name>`, in every case above |
|
|
1978
|
+
| `--no-advance-ref` | Not accepted | None, and no notice |
|
|
1979
|
+
| `--dry-run` in CI, connection from the config, with neither `--advance-ref` nor `--no-advance-ref` | Reports `db` as `plannedAdvanceRef` | Reports none, and says an apply would not advance one |
|
|
1980
|
+
|
|
1981
|
+
Change the commands the project runs:
|
|
1982
|
+
|
|
1983
|
+
- Where `db init` or `db update` runs from the config in a CI job and a later step needs the `db` ref, for example a job that commits `migrations/app/refs/db.json` or runs `migration plan` from it, add `--advance-ref db`.
|
|
1984
|
+
|
|
1985
|
+
```bash
|
|
1986
|
+
# Before
|
|
1987
|
+
prisma db update
|
|
1988
|
+
# After, in CI, when the job needs the db ref
|
|
1989
|
+
prisma db update --advance-ref db
|
|
1990
|
+
```
|
|
1991
|
+
|
|
1992
|
+
- Where a pipeline runs `db update` with statements such as `--rename` against a database an earlier `db init` or `db update` in CI moved, give that earlier run `--advance-ref <name>`. A ref is how those commands store the snapshot of the contract they applied, and `db update` reads that snapshot to resolve the statements; without it, it fails with `MIGRATION.STATEMENT_ORIGIN_UNKNOWN`.
|
|
1993
|
+
- Where `db init` or `db update` runs from the config in a pipeline that does not need the ref, add `--no-advance-ref`, which writes no ref and silences the notice.
|
|
1994
|
+
- On a development machine where the notice appears, a variable in the shell, or in a `.env` file that `prisma.config.ts` loads, made the CLI detect CI. Unset it, or set `CI=false`.
|
|
1995
|
+
|
|
1996
|
+
A ref that `db init` or `db update` cannot write, for example on a read-only filesystem, is now a warning, `MIGRATION.REF_NOT_WRITTEN`, and the command exits 0. Before, the command failed after the database had changed. A script that checked the exit code to detect that failure reads the warning from the `--json` result's diagnostics instead. The warning's next action is the command it prints: `migration ref set <name> <hash>` when a migration on disk ends at the contract the database is at and its snapshot is stored, and otherwise the run's command with `--advance-ref <name>` and without its statements (`--rename`, `--delete`, `--allow`), which applies nothing if the contract has not changed since and writes the ref. Run the printed command, not the original one: a `db update` with statements fails when run again as typed.
|
|
1997
|
+
|
|
1998
|
+
## One parser reads a contract argument on every command
|
|
1999
|
+
|
|
2000
|
+
### `contract-argument-one-parser`
|
|
2001
|
+
|
|
2002
|
+
Many commands take a contract as an argument: a hash, a hash prefix, a ref name, a migration directory name, `<dir>^` for the contract a migration starts from, or a reserved word, `@empty`, `@db` or `@contract`. Each command used to read the argument with code of its own. They now share one parser. Two things that failed now work:
|
|
2003
|
+
|
|
2004
|
+
- A path to a migration directory, such as `migrations/app/20261130T1230_init`, works wherever the directory's name does. It is resolved against the folder the command runs in, and must name a folder directly inside the space's migrations folder.
|
|
2005
|
+
- `migration new --from` takes everything `migration plan --from` takes, `@empty` included.
|
|
2006
|
+
|
|
2007
|
+
Search the project's scripts, CI files and docs for `migration new --from`, for `@db` or `@contract` passed to `migration ref set`, `migration plan --from` or `--to`, and for code that matches on the error codes below. Change each as this table says:
|
|
2008
|
+
|
|
2009
|
+
| Command and argument | Before | Now |
|
|
2010
|
+
| --- | --- | --- |
|
|
2011
|
+
| `migration new --from` with a hash prefix shorter than six characters | Accepted | `MIGRATION.REF_NOT_FOUND`. Write six characters or more |
|
|
2012
|
+
| `migration new --from ""` in a project with migrations | Matched every migration | `MIGRATION.REF_INVALID_FORMAT` |
|
|
2013
|
+
| `migration new --from` with an unknown name, prefix or path | `MIGRATION.HASH_NOT_IN_GRAPH` | `MIGRATION.REF_NOT_FOUND`. A full hash no migration records stays `MIGRATION.HASH_NOT_IN_GRAPH` |
|
|
2014
|
+
| `migration new --from` with a prefix that matches several contracts | Looked only at contracts a migration ends at | `MIGRATION.REF_AMBIGUOUS`, counting contracts a migration only starts from too |
|
|
2015
|
+
| `migration new --from @empty`, `empty` or `<first migration>^` | `MIGRATION.HASH_NOT_IN_GRAPH` | Accepted: the migration starts from an empty database |
|
|
2016
|
+
| `migration ref set`, `migration plan --from` or `--to`, `migration new --from` with `@db` | `MIGRATION.HASH_NOT_IN_GRAPH` | `MIGRATION.REF_WRONG_GRAMMAR` |
|
|
2017
|
+
| The same four with `@contract` | `MIGRATION.REF_NOT_FOUND` (`MIGRATION.HASH_NOT_IN_GRAPH` on `migration new`) | `MIGRATION.REF_WRONG_GRAMMAR` |
|
|
2018
|
+
| `migration plan --from empty` or `--from <first migration>^` | `CLI.UNEXPECTED` or `MIGRATION.HASH_NOT_IN_GRAPH`, or `MIGRATION.SNAPSHOT_MISSING` with no migrations | Plans from an empty database |
|
|
2019
|
+
| `migration plan --from <ref>`, when no migration records the ref's contract and its snapshot is missing | `MIGRATION.SNAPSHOT_MISSING` | `MIGRATION.HASH_NOT_IN_GRAPH` |
|
|
2020
|
+
|
|
2021
|
+
`migration ref set <name>` with `@empty`, `empty` or `<first migration>^` is still refused with `MIGRATION.REF_SET_EMPTY_SENTINEL`, with new text. `@db` is not accepted by `migration ref set`, because that command does not connect to a database: name the contract the database is at by its hash, ref or migration directory instead.
|
|
2022
|
+
|
|
2023
|
+
Where a script matched on an old code to detect one of these cases, match on the new code. Where it worked around the old rules, for example by passing a migration's directory name where it had a path, it may now pass the path.
|
|
2024
|
+
|
|
2025
|
+
### `control-api-ref-resolution-takes-migration-dir`
|
|
2026
|
+
|
|
2027
|
+
A program that resolves contract arguments through the control API passes the folder a path argument is resolved against, and the space's migrations folder:
|
|
2028
|
+
|
|
2029
|
+
```ts
|
|
2030
|
+
import { join } from 'node:path';
|
|
2031
|
+
import { resolveContractRef } from '@prisma/orm-toolchain/cli/control-api';
|
|
2032
|
+
|
|
2033
|
+
// before
|
|
2034
|
+
resolveContractRef(input, { ...context });
|
|
2035
|
+
// after
|
|
2036
|
+
resolveContractRef(input, {
|
|
2037
|
+
...context,
|
|
2038
|
+
migrationDirResolution: { cwd: process.cwd(), spaceMigrationsDir: join(projectDir, 'migrations/app') },
|
|
2039
|
+
});
|
|
2040
|
+
```
|
|
2041
|
+
|
|
2042
|
+
The same field goes in the options of `resolveContractRefToSnapshot`, `resolveFromForPlan` and `resolveToForPlan`.
|
|
2043
|
+
|
|
2044
|
+
## A MongoDB field, relation or enum named `__proto__`
|
|
2045
|
+
|
|
2046
|
+
### `mongo-proto-field-and-relation-names-refused`
|
|
2047
|
+
|
|
2048
|
+
JavaScript reads `__proto__` as the prototype of an object rather than as a key. The previous release refused a MongoDB model, composite type, collection or root of that name, and a field stored under that name. It did not refuse a relation, a member of a composite type or value object, a field stored under another name, or a field of a Prisma 6 schema with no `@map`: depending on the contract source, such a name was left out of the contract or out of every row the client read, without an error. A Mongo PSL contract also left an enum named `__proto__` out of the contract. All of these are now refused. The TypeScript builder raises `CONTRACT.NAME_UNUSABLE_AS_KEY`; a PSL contract reports `PSL_STORED_NAME_UNSUPPORTED` at the field, relation or enum:
|
|
2049
|
+
|
|
2050
|
+
```text
|
|
2051
|
+
A field of model "Item" is named "__proto__", which JavaScript reads as the prototype of an object rather than as a key. Choose another name.
|
|
2052
|
+
```
|
|
2053
|
+
|
|
2054
|
+
A Mongo PSL contract also refuses `__proto__` as an `include` or `exclude` path of a wildcard index, with `PSL_INVALID_INDEX`; the path used to be dropped from the index without an error. Remove it.
|
|
2055
|
+
|
|
2056
|
+
Rename the field, relation, member or enum. Renaming an enum changes no document. What the other renames do to stored documents is listed below. Two rules hold for every update in this section. Stop every process that writes to the collection before you start, and restart one only when the update has finished, including any run you repeat, and the process uses the new names. And where an update moves a value to `<new name>`, choose a name that no document already uses as a key in that place; otherwise one of the two values is lost.
|
|
2057
|
+
|
|
2058
|
+
- **A model's field.** Keep its stored name with `@map("…")`, or `.mongo({ field })` in TypeScript, and no document changes. A field stored as `__proto__` cannot keep that stored name; give it another one. The TypeScript builder and Mongo PSL already refused such a field. A Prisma 6 schema with a field named `__proto__` and no `@map` lost the field from the contract without an error; documents may hold its values under a top-level `__proto__` key, so move them with the top-level update in the relation bullet below.
|
|
2059
|
+
- **A member of a composite type or value object.** It is always stored under its own name, so renaming it changes the key in the embedded documents. Documents may already hold values under `__proto__`, and a rename leaves them under the old key. Move them to the new key. For a member of an embedded document:
|
|
2060
|
+
|
|
2061
|
+
```js
|
|
2062
|
+
db.getCollection("<collection>").updateMany(
|
|
2063
|
+
{ "<field>.__proto__": { $exists: true } },
|
|
2064
|
+
[{ $set: { "<field>.<new name>": "$<field>.__proto__" } }, { $unset: "<field>.__proto__" }],
|
|
2065
|
+
)
|
|
2066
|
+
```
|
|
2067
|
+
|
|
2068
|
+
For a list of composite values, rename the key in each element:
|
|
2069
|
+
|
|
2070
|
+
```js
|
|
2071
|
+
db.getCollection("<collection>").updateMany(
|
|
2072
|
+
{ "<field>.__proto__": { $exists: true } },
|
|
2073
|
+
[{ $set: { "<field>": { $map: { input: "$<field>", as: "e", in: { $arrayToObject: { $map: {
|
|
2074
|
+
input: { $objectToArray: "$$e" }, as: "kv",
|
|
2075
|
+
in: { k: { $cond: [{ $eq: ["$$kv.k", "__proto__"] }, "<new name>", "$$kv.k"] }, v: "$$kv.v" },
|
|
2076
|
+
} } } } } } }],
|
|
2077
|
+
)
|
|
2078
|
+
```
|
|
2079
|
+
- **A relation.** A reference relation's name is not stored, so no document changes. An embed relation is stored under its name, or under the name the TypeScript contract gives it with `storageRelations`. The client never read or wrote an embed relation named `__proto__`, and a create dropped the value of one stored as `__proto__`; that stored name is now refused with `CONTRACT.ARGUMENT_INVALID`. Give the relation another name or stored name. An embed relation is stored at the top level of the document, so to move embedded documents that another writer stored under `__proto__`, use this update:
|
|
2080
|
+
|
|
2081
|
+
```js
|
|
2082
|
+
db.getCollection("<collection>").updateMany(
|
|
2083
|
+
{ ["__proto__"]: { $exists: true } },
|
|
2084
|
+
[{ $set: { "<new name>": "$__proto__" } }, { $unset: "__proto__" }],
|
|
2085
|
+
)
|
|
2086
|
+
```
|
|
2087
|
+
|
|
2088
|
+
Write the filter key as `["__proto__"]`. Written as `"__proto__":` it sets the filter's prototype, the filter matches every document, and the update removes `<new name>` from documents that have no `__proto__`.
|
|
2089
|
+
|
|
2090
|
+
## A changed stored name is a rename on MongoDB
|
|
2091
|
+
|
|
2092
|
+
A model, field or enum member with the same name in the contract source on both sides of a change is now the same object on MongoDB, as on PostgreSQL and SQLite. When only what it is stored as changes, `migration plan` and `db update` rename the storage or replace the value. This needs a snapshot of the contract the database is at.
|
|
2093
|
+
|
|
2094
|
+
### `mongo-stored-name-change-is-a-rename`
|
|
2095
|
+
|
|
2096
|
+
Before, changing `@@map("users")` to `@@map("app_users")` on `model User` planned a drop of `users` and a create of `app_users`, and asked for `--delete User`. To keep the documents you renamed the collection by hand: with `db update`, in `mongosh`; with `migration plan`, by writing `renameCollection(...)` into the `migration.ts` and deleting the drop.
|
|
2097
|
+
|
|
2098
|
+
Now the same change plans `Rename collection users to app_users` and asks nothing. The documents, indexes and validator stay with the collection. A changed `@map` on a field plans `Rename field email to mail in collection users`. A changed `@map` on a field of an embedded model renames the key in every place the model is stored, as in `Rename key "sku" to "code" at path "$[*]" in field lines of collection orders`. An enum member that keeps its name and changes its stored value, such as `ARCHIVED = "archived"` to `ARCHIVED = "retired"`, has the value replaced in every field and key the enum types, scalar or list. A collection is renamed only when everything stored in it moves and its control policy is `managed` in both contracts.
|
|
2099
|
+
|
|
2100
|
+
Stop renaming by hand. Make the contract change and plan it. Migrations you already wrote by hand stay as they are. If you already renamed a collection by hand and use `db update`, it finds the collection under its new name and plans nothing for it.
|
|
2101
|
+
|
|
2102
|
+
### `mongo-stored-name-delete-is-unused`
|
|
2103
|
+
|
|
2104
|
+
Before:
|
|
2105
|
+
|
|
2106
|
+
```bash
|
|
2107
|
+
prisma db update --delete User
|
|
2108
|
+
```
|
|
2109
|
+
|
|
2110
|
+
Now this fails with `CLI.CONSENT_UNUSED`, since nothing asks about `User`. Remove the `--delete` from the script:
|
|
2111
|
+
|
|
2112
|
+
```bash
|
|
2113
|
+
prisma db update
|
|
2114
|
+
```
|
|
2115
|
+
|
|
2116
|
+
The same holds for `--delete User.email` after a changed `@map`, and `--delete Status.ARCHIVED` after a changed stored value of a member that keeps its name.
|
|
2117
|
+
|
|
2118
|
+
### `mongo-stored-name-empty-collection`
|
|
2119
|
+
|
|
2120
|
+
Before, a changed `@@map` gave you an empty collection under the new name once you answered `--delete User`. Now it keeps the documents. To start empty, make two changes, each planned and applied before the next:
|
|
2121
|
+
|
|
2122
|
+
1. Remove `model User` from the schema, plan, and answer `--delete User`.
|
|
2123
|
+
2. Add `model User` back with `@@map("app_users")`, and plan again.
|
|
2124
|
+
|
|
2125
|
+
### `mongo-stored-name-swaps-refused`
|
|
2126
|
+
|
|
2127
|
+
Two models that swap collections (`User` from `users` to `accounts` and `Account` from `accounts` to `users`), two fields that swap stored names, a chain where one moves to a name another frees, and a model that takes the collection of one the change removes are refused with `MIGRATION.PLANNING_FAILED`, as in:
|
|
2128
|
+
|
|
2129
|
+
```text
|
|
2130
|
+
Cannot rename collection "accounts" to "users": collection "users" is renamed in the same plan
|
|
2131
|
+
```
|
|
2132
|
+
|
|
2133
|
+
Enum members are refused when they swap stored values, shift them along a chain (`A` takes `"b"` while `B` takes `"c"`), or take the stored value of another member of the origin. Before, a swap or chain was asked about, with advice to make the change in two migrations. MongoDB applies a migration's operations one at a time with no transaction, so a rewrite that reads a value another rewrite of the same migration writes is not safe to run again after a stop.
|
|
2134
|
+
|
|
2135
|
+
Follow the message: make the change in two plans, each planned and applied before the next, through temporary names or values neither contract uses, such as `prisma_swap_users` or `prisma_swap_1`, or, for a takeover, by first removing the collection's model, the field or the enum member that holds the name. For a field held by a field of another root model in the same collection, removing that model does not free the name, since its documents keep the key: keep the model and remove only its field first, or keep the stored name. A boolean enum has no third value, so members that swap `true` and `false` are refused with no route: keep the stored values of the enum in the contract.
|
|
2136
|
+
|
|
2137
|
+
A collection rename whose old name the change uses again, for a new model or another model's collection, is refused too: make the rename in one plan and add what uses the old name in the next.
|
|
2138
|
+
|
|
2139
|
+
When the two collections or fields have the same shape and nothing else changes, the storage does not change at all, so `migration plan` still reports no change and writes nothing; `db update` refuses the swap. Make such a swap through a temporary name in the same way. `migration plan` cannot see the database, so if the database already has a collection or field of a suggested temporary name, pick another.
|
|
2140
|
+
|
|
2141
|
+
### `mongo-shared-collection-rename-refused`
|
|
2142
|
+
|
|
2143
|
+
Before, `--rename User:Member`, where `User` shares collection `users` with another root model and `Member` has a collection of its own, renamed `users` to `members`, and the other model's documents moved too. Now it is refused:
|
|
2144
|
+
|
|
2145
|
+
```text
|
|
2146
|
+
Cannot rename model "User" to "Member": collection "users" also stores model "Admin"
|
|
2147
|
+
```
|
|
2148
|
+
|
|
2149
|
+
A plan cannot tell the two models' documents apart, since nothing in a document names its root model. Without the statement the plan does not move them either: `User` is removed and nothing is asked, since nothing is deleted; its documents stay in `users`, where `Admin` still reads them, and `Member` starts with none. If the new validator of `users` does not accept them, its change stops the apply in every database that holds them, until they are deleted or moved there. To keep them, move them in a hand-written migration with `migration plan`, as the message describes.
|
|
2150
|
+
|
|
2151
|
+
The message says where the move goes in the operations, and when its copy must skip document validation: `rawAggregate` now takes `{ bypassDocumentValidation: true }` as its last argument, as `rawUpdateMany` does. The option is new; nothing you wrote before changes.
|
|
2152
|
+
|
|
2153
|
+
### `mongo-create-collection-postcheck`
|
|
2154
|
+
|
|
2155
|
+
Before, `createCollection` had no check after it ran. When a later operation of the same migration stopped, running `db migrate` again tried the create again, and it stopped because the collection already existed. Now the create checks that the collection exists with the options it sets, and a re-run skips it, so a migration that stopped part way is finished by fixing what stopped it and running `db migrate` again.
|
|
2156
|
+
|
|
2157
|
+
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
|
+
|
|
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.
|
|
2160
|
+
|
|
2161
|
+
## The runtime's contract signature check only warns
|
|
2162
|
+
|
|
2163
|
+
### `runtime-signature-check-only-warns`
|
|
2164
|
+
|
|
2165
|
+
On its first use of the database, the runtime reads the database's contract signature and compares it with the contract. A mismatch and a missing signature already only warned. Two more cases now only warn:
|
|
2166
|
+
|
|
2167
|
+
- the signature cannot be read, logged as `CONTRACT.SIGNATURE_READ_FAILED`;
|
|
2168
|
+
- the signature row cannot be decoded, logged as `CONTRACT.SIGNATURE_ROW_CORRUPT`.
|
|
2169
|
+
|
|
2170
|
+
In both cases the query runs. Before, the call rejected with that code, and every later call read the signature again and rejected again until a read succeeded.
|
|
2171
|
+
|
|
2172
|
+
Most applications need no change. Search for the two codes in the application's code. If the application catches one of them from a query, that branch no longer runs. Decide what it was for:
|
|
2173
|
+
|
|
2174
|
+
- To stop a deploy when the database does not match the contract, run `prisma db verify` in the deploy. It still exits with an error for every one of these cases.
|
|
2175
|
+
- To report the problem, pass `log` to the client and read the warnings there:
|
|
2176
|
+
|
|
2177
|
+
```ts
|
|
2178
|
+
const db = postgres({
|
|
2179
|
+
contract,
|
|
2180
|
+
url,
|
|
2181
|
+
log: {
|
|
2182
|
+
...console,
|
|
2183
|
+
warn: (entry) => report(entry),
|
|
2184
|
+
},
|
|
2185
|
+
});
|
|
2186
|
+
```
|
|
2187
|
+
|
|
2188
|
+
When the server does not answer or refuses the connection, the first query now rejects with the driver's own connection error, where before it rejected with `CONTRACT.SIGNATURE_READ_FAILED`. When a PostgreSQL or MySQL server answers and refuses the sign-in, or reports that the database does not exist, the runtime logs the `CONTRACT.SIGNATURE_READ_FAILED` warning and the query rejects with the server's own error. Code that matched on the signature code to detect a database it cannot use matches on those errors instead.
|
|
2189
|
+
|
|
2190
|
+
## The client logs to the console by default
|
|
2191
|
+
|
|
2192
|
+
### `default-logger-console`
|
|
2193
|
+
|
|
2194
|
+
The runtime logs warnings and errors that do not stop a call: the contract signature warnings such as `CONTRACT.SIGNATURE_MISMATCH` and `CONTRACT.SIGNATURE_MISSING`, the `CONTRACT.CAPABILITIES_NOT_PROVIDED` warning, the warnings of `lints()` and of `budgets()` in `mode: 'permissive'`, the `runtime.close.waiting-for-activities` warning, and the errors a middleware's `activityEnded` or `activityFinalized` hook throws. A client created without `log` used to drop all of them. It now passes each event object, unchanged, to the console:
|
|
2195
|
+
|
|
2196
|
+
| Level | Goes to |
|
|
2197
|
+
| --- | --- |
|
|
2198
|
+
| `error` | `console.error` (standard error in Node) |
|
|
2199
|
+
| `warn` | `console.warn` (standard error in Node) |
|
|
2200
|
+
| `info` | `console.info` (standard output in Node) |
|
|
2201
|
+
| `debug` | nowhere |
|
|
2202
|
+
|
|
2203
|
+
A client created with `log` receives exactly what it received before. An error that one of its methods throws is now discarded everywhere: it no longer fails a query or the creation of a client.
|
|
2204
|
+
|
|
2205
|
+
Most applications need no change: a warning that now prints points to something to fix, such as a database signed for another contract. In each file the detection matches, look at each client created without `log`. If the application must keep its console silent, for example a command-line tool whose output another program reads, pass a logger that does nothing:
|
|
2206
|
+
|
|
2207
|
+
```ts
|
|
2208
|
+
const silent = { info() {}, warn() {}, error() {} };
|
|
2209
|
+
const db = postgres({ contract, url, log: silent });
|
|
2210
|
+
```
|
|
2211
|
+
|
|
2212
|
+
A test that asserts on console output, or fails on any console write, may now see these events; pass the silent logger to the clients it creates.
|
|
2213
|
+
|
|
2214
|
+
`mongo()` takes the same `log` option. Its runtime logs the errors a middleware's `activityEnded` or `activityFinalized` hook throws, which it swallows.
|
|
2215
|
+
|
|
2216
|
+
## A fragment for any model is made on the client
|
|
2217
|
+
|
|
2218
|
+
### `fragment-on-the-client`
|
|
2219
|
+
|
|
2220
|
+
`fragment(fields, body)` moved from the ORM client to the client itself. It needs no database connection, so it is on every client and transaction: `postgres()`, the serverless client from `postgresServerless()` and each connection it returns, `sqlite()`, the MySQL and MariaDB clients, each Supabase role-bound client, `tx` inside a transaction and a nested transaction, and the client the static entry returns (`postgresStatic`, `sqliteStatic`, `mysqlStatic`, `mariadbStatic`).
|
|
2221
|
+
|
|
2222
|
+
| Before | After |
|
|
2223
|
+
| --- | --- |
|
|
2224
|
+
| `db.orm.fragment(fields, body)` | `db.fragment(fields, body)` |
|
|
2225
|
+
| `tx.orm.fragment(fields, body)` | `tx.fragment(fields, body)` |
|
|
2226
|
+
| `const { orm } = db; orm.fragment(fields, body)` | `const { fragment } = db; fragment(fields, body)` |
|
|
2227
|
+
| `orm({ runtime, context }).fragment(fields, body)` | `fragmentMember<Contract>().fragment(fields, body)`, with `fragmentMember` from `@prisma/orm-postgres/orm-client` (or the `orm-client` entry of the database's package) |
|
|
2228
|
+
|
|
2229
|
+
In each file the detection matches, find each call `X.fragment(fields, body)` whose first argument is field declarations, written in place as an object or held in a variable:
|
|
2230
|
+
|
|
2231
|
+
- If `X` is `db.orm` or `tx.orm`, or another expression that ends in `.orm`, remove `.orm`.
|
|
2232
|
+
- If `X` is a variable holding `db.orm`, call `fragment` on the client the variable came from.
|
|
2233
|
+
- If `X` is the client `orm()` returned, replace `X.fragment` with `fragmentMember<Contract>().fragment`, where `Contract` is the contract type `orm()` was given, and import `fragmentMember` from the `orm-client` entry the file imports `orm` from.
|
|
2234
|
+
|
|
2235
|
+
The detection also matches calls whose first argument is a variable, so a file may hold calls that need no change. Leave calls on a collection, such as `db.orm.public.Post.fragment((posts) => ...)` or `posts.fragment(summarise)`, unchanged: they take one argument, a function.
|
|
2236
|
+
|
|
2237
|
+
On SQLite, MySQL and MariaDB, a model named `fragment` was hidden: `db.orm.fragment` was the method. It is now the model's collection.
|
|
2238
|
+
|
|
2239
|
+
## `fns` comparisons on a model field take the field's input type
|
|
2240
|
+
|
|
2241
|
+
### `orm-fns-comparison-takes-field-input-type`
|
|
2242
|
+
|
|
2243
|
+
Each field of the model accessor that an ORM callback receives, such as `p` in `db.Post.where((p, { fns }) => ...)` from `@prisma/orm-postgres/orm-client`, now carries the field's input type from the contract. The comparisons of `fns` read it, so a plain value compared with the field must be of that type. For an enum field, that is one of its members:
|
|
2244
|
+
|
|
2245
|
+
```ts
|
|
2246
|
+
db.Post.where((p, { fns }) => fns.eq(p.status, 'NOT_A_MEMBER'));
|
|
2247
|
+
```
|
|
2248
|
+
|
|
2249
|
+
This compiled before and no longer compiles. It is the same check that `p.status.eq('NOT_A_MEMBER')` and `where({ status: 'NOT_A_MEMBER' })` already made.
|
|
2250
|
+
|
|
2251
|
+
A new type error on a call to `fns.eq`, `fns.ne`, `fns.gt`, `fns.gte`, `fns.lt`, `fns.lte`, `fns.in` or `fns.notIn` marks a condition that compiled before. On a column that stores the members as text, a value that is not a member:
|
|
2252
|
+
|
|
2253
|
+
- in `fns.eq` and `fns.in` matched no row;
|
|
2254
|
+
- in `fns.ne` and `fns.notIn` excluded no row;
|
|
2255
|
+
- in `fns.gt`, `fns.gte`, `fns.lt` and `fns.lte` was compared in text order and can match rows.
|
|
2256
|
+
|
|
2257
|
+
Do not edit such a call and do not remove the condition. Report each call that no longer compiles to the user, say which value or narrowing you would propose, say that the condition would then match different rows than before, which before `updateAll` or `deleteAll` changes which rows are written, and ask. This holds for a literal and for a variable of a wider type, such as `string`.
|
|
2258
|
+
|
|
2259
|
+
Nothing changes at run time.
|
|
2260
|
+
|
|
2261
|
+
## `updateAll` and `updateAndCount` take no explicit type argument
|
|
2262
|
+
|
|
2263
|
+
### `update-all-explicit-type-argument`
|
|
2264
|
+
|
|
2265
|
+
`updateAll` and `updateAndCount` now take either the object they took before or a callback that returns it, so they have two type parameters: the collection the call is made on, which TypeScript infers from `this`, and the values the callback returns. A call that passed one explicit type argument fails to compile with `TS2558: Expected 2 type arguments, but got 1`.
|
|
2266
|
+
|
|
2267
|
+
In each file the detection matches, first check that the call is made on a Prisma ORM collection, such as `db.orm.public.Post.where(...)` or a variable that holds one, and that it passes one type argument. Leave a method of the same name on another object alone. On such a call, remove the type argument. TypeScript infers both, and the call does what it did before:
|
|
2268
|
+
|
|
2269
|
+
```ts
|
|
2270
|
+
// before: the type argument named the collection the call is made on
|
|
2271
|
+
const drafts = db.orm.public.Post.where({ draft: true });
|
|
2272
|
+
await drafts.updateAll<typeof drafts>({ draft: false });
|
|
2273
|
+
// after
|
|
2274
|
+
await drafts.updateAll({ draft: false });
|
|
2275
|
+
```
|
|
2276
|
+
|
|
2277
|
+
Nothing changes at run time.
|
|
2278
|
+
|
|
2279
|
+
## A column name that several joined tables share needs its table
|
|
2280
|
+
|
|
2281
|
+
### `sql-builder-shared-join-column-name-needs-table`
|
|
2282
|
+
|
|
2283
|
+
In a query that joins three or more tables, a column name that more than one of them has, such as `id`, is no longer a top-level field. This code now fails to type-check:
|
|
2284
|
+
|
|
2285
|
+
```ts
|
|
2286
|
+
db.public.users
|
|
2287
|
+
.innerJoin(db.public.posts, (f, fns) => fns.eq(f.users.id, f.posts.user_id))
|
|
2288
|
+
.innerJoin(db.public.profiles, (f, fns) => fns.eq(f.users.id, f.profiles.user_id))
|
|
2289
|
+
.select((f) => ({ id: f.id }));
|
|
2290
|
+
```
|
|
2291
|
+
|
|
2292
|
+
What this code did before depends on the release:
|
|
2293
|
+
|
|
2294
|
+
- In 8.0.0-rc.25 it type-checked and ran without an error, and `f.id` returned the column of the last joined table that has the name: `profiles.id` here.
|
|
2295
|
+
- In earlier releases the database refused the query because `id` was ambiguous.
|
|
2296
|
+
|
|
2297
|
+
Do not assume the last joined table that has the name is the right one. Read the code, decide which table's column it means, and name that table. In this example the code most likely meant the user's id:
|
|
2298
|
+
|
|
2299
|
+
```ts
|
|
2300
|
+
.select((f) => ({ id: f.users.id }));
|
|
2301
|
+
```
|
|
2302
|
+
|
|
2303
|
+
If it meant another table, name that one instead, such as `f.posts.id` or `f.profiles.id`. If the code ran on 8.0.0-rc.25 and meant a table other than the last joined table that has the name, the results it produced, and any data written from them, hold the wrong table's values; check them. The same applies to such a name read in `where`, `orderBy` and the other callbacks.
|
|
2304
|
+
|
|
2305
|
+
Passing the name as a string is different. `select('id')`, `orderBy('id')`, `groupBy('id')` and `distinctOn('id')` sent a bare `"id"`, which the database refused as ambiguous in 8.0.0-rc.25 and every earlier release, so that code never returned wrong results. It is now a type error, and it throws `ORM.COLUMN_AMBIGUOUS` when `select` (or `orderBy`, `groupBy` or `distinctOn`) is called, instead of failing in the database. The error's `fix` lists the tables that have the name; decide which one the code means and name it, such as `select('id', (f) => f.users.id)`, or `orderBy((f) => f.users.id)` and the same for `groupBy` and `distinctOn`. Keep `orderBy`'s options; for `select`, `groupBy` and `distinctOn`, put any other names in a separate call, which adds to the earlier one.
|
|
2306
|
+
|
|
2307
|
+
In a join of two tables, a name both share was already not a top-level field, so passing it as a string was a type error before too. Code that reached it anyway, through a cast or a name built at run time, used to get `ORM.COLUMN_UNKNOWN` and now gets `ORM.COLUMN_AMBIGUOUS`.
|
|
2308
|
+
|
|
2309
|
+
Inside the subquery of `lateralJoin` or `outerLateralJoin`, both forms could run without an error: a name that the subquery's table shared with the parent tables read the subquery's own table. If the code meant a parent table's column, its results hold the wrong values; check them. Write the table's name, such as `f.profiles.id`.
|
|
2310
|
+
|
|
2311
|
+
Names that only one joined table has stay available at top level.
|
|
2312
|
+
|
|
2313
|
+
## A list column is a list in the PostgreSQL SQL builder
|
|
2314
|
+
|
|
2315
|
+
### `sql-builder-list-column-in-a-one-value-position`
|
|
2316
|
+
|
|
2317
|
+
In the PostgreSQL SQL builder (`db.sql`), a list column (a `String[]` or other scalar list field) is now typed as a list, so it is refused where one value goes. `fns.eq` and `fns.ne` still compare a list column with an array or another list of the same element type.
|
|
2318
|
+
|
|
2319
|
+
These no longer compile:
|
|
2320
|
+
|
|
2321
|
+
- An ordered comparison of a list column, such as `fns.gt(f.tags, ['b'])`. Write it in raw SQL (`db.raw.sql`).
|
|
2322
|
+
- A list column as the left operand of `fns.in` / `fns.notIn`, such as `fns.in(f.tags, [['a'], ['b']])`. Write `fns.in` as `fns.or(fns.eq(f.tags, ['a']), fns.eq(f.tags, ['b']))`, and `fns.notIn` as `fns.and(fns.ne(f.tags, ['a']), fns.ne(f.tags, ['b']))`. Each form leaves out a row whose list is null, as `in` and `notIn` did.
|
|
2323
|
+
- A raw SQL expression declared as one value where a list goes, such as ``tags: fns.raw`array_append(${f.tags}, 'x')`.returns('pg/text@1')`` in an `update` callback, or the same expression compared with a list column in `fns.eq`. Declare it as a list: `.returns({ codecId: 'pg/text@1', many: { elementNullable: false } })`.
|
|
2324
|
+
|
|
2325
|
+
## `char(n)[]` values written with 8.0.0-rc.25
|
|
2326
|
+
|
|
2327
|
+
### `postgres-char-bit-list-values-check`
|
|
2328
|
+
|
|
2329
|
+
On PostgreSQL, 8.0.0-rc.25 cast each element of a list it wrote to `character` or `bit` without the column's length. PostgreSQL reads those names as length 1. Each element of a `char(n)[]` value was cut to its first character, and the column padded it with spaces. A `bit(n)[]` value was refused instead: the write failed with `bit string length 1 does not match type bit(n)`, so no cut value was stored. This release casts to `bpchar` and `varbit`, which keep the length, so both writes now work. `char(n)[]` values already written stay as they were stored.
|
|
2330
|
+
|
|
2331
|
+
Find each `char(n)[]` column, with `n` greater than 1, in the emitted `contract.json`. For each, report it to the user, say that rows written with 8.0.0-rc.25 may hold cut values, and give a query that finds them. A cut element reads back as one character followed by spaces:
|
|
2332
|
+
|
|
2333
|
+
```sql
|
|
2334
|
+
SELECT * FROM "public"."product"
|
|
2335
|
+
WHERE EXISTS (SELECT 1 FROM unnest("codes") AS code WHERE length(code) = 1);
|
|
2336
|
+
```
|
|
2337
|
+
|
|
2338
|
+
Do not change the data yourself: only the user knows what the cut values were. A `bit(n)[]` column needs no check.
|
|
2339
|
+
|
|
2340
|
+
## A prepared declaration's parameter can be a list
|
|
2341
|
+
|
|
2342
|
+
### `prepared-declaration-param-spec-can-be-a-list`
|
|
2343
|
+
|
|
2344
|
+
A prepared statement on PostgreSQL can now take a whole list as one parameter, declared as `{ codecId: 'pg/int8@1', many: { elementNullable: false } }`. So `ParamSpec`, the type of each parameter in a declaration, gains `many?: { readonly elementNullable: boolean }`. It is exported from `@prisma/orm-family-sql/runtime` and from the `family-runtime` entry of each SQL database package, such as `@prisma/orm-postgres/family-runtime`; `PrepareMember` and `prepareQuery` come from the `orm-client` entries. The `ParamSpec` of `@prisma/orm-framework/operations`, which types the arguments and result of an operation, is a different type and does not change. The guide's search finds both, so check which one a file imports before you change it.
|
|
2345
|
+
|
|
2346
|
+
Code that only calls `db.prepare` with its own declaration does not change. Code that is generic over a declaration may no longer type-check: a function that wraps `prepare`, `prepareQuery` or `delegatingRuntime`, a class that implements `PrepareMember` or `DelegatingRuntime`, or a type that maps each parameter of a declaration to the value it takes. Where such code treats every parameter as one value of its codec, give a spec with `many` a list of its codec's values (with `null` elements when `elementNullable` is `true`), or pass the declaration type on to `prepare` unchanged. The type check finds each place.
|
|
2347
|
+
|
|
2348
|
+
## Sets of values a later 8.x release may grow
|
|
2349
|
+
|
|
2350
|
+
### `app-middleware-handles-later-activities`, `app-switches-over-later-values`
|
|
2351
|
+
|
|
2352
|
+
A middleware's hooks can now receive an activity, an ended result or a value of a kind a later 8.x release adds. `Activity` and `ActivityEndedResult` gain a member whose `kind` is a `FutureCase`, and `ActivityContext.mode` and `.scope`, `TransactionEnded.outcome`, `StatementEnded.outcome` and `.source`, `ClientActivityEnded.outcome` and `.source` and `ActivityFinalizedResult.outcome` accept any string beside their named values. Where a middleware checks every kind or value, with a `switch` or a `never` assignment, give it a branch for the rest, and act there as for a value it does not know: for example, cache nothing or pass the activity on. A middleware that narrows away `'statement'` and `'transaction'` and then reads a client activity's `contentHash` must instead check that the kind is a client kind, whose name always contains a hyphen (such as `orm-call`). `FutureCase` (a type every entry of your database package and of the extensions exports, such as `@prisma/orm-postgres/runtime`) only stands for a later kind in the type, and no code can write it; at run time a later kind arrives under its own name, so check for the kinds the middleware knows. Likewise `StatementActivity.returns` accepts any string beside `'rows'` and `'stats'`, and `StatementEnded` gains a member whose `returns` is a `FutureCase`: read `rowCount` after `returns === 'rows'` and `stats` after `returns === 'stats'`, not in an `else` branch.
|
|
2353
|
+
|
|
2354
|
+
Sets of values that a later 8.x release may grow now say so in their types. Each is written `NonExhaustive<…>`. `NonExhaustive` and `FutureCase` are types every entry of your database package and of the extensions exports, so import them as types from the entry you import the union from, such as `import type { ColumnDefault, FutureCase } from '@prisma/orm-postgres/contract-builder'`. A union of strings gains `(string & {})`; a union of objects gains a member whose `kind` (or, for a migration statement, `entity`; for the other unions below, the property named) is a `FutureCase`, a value no release has and no code can write, which stands for one a later release adds. The sets:
|
|
2355
|
+
|
|
2356
|
+
- a column default (`ColumnDefault`, kinds `'literal'` and `'function'`) and a field's type (`ContractFieldType`, kinds `'scalar'`, `'valueObject'` and `'union'`);
|
|
2357
|
+
- the database policies a ref declares (`ChangeStrategy`, `DataLossLevel`, `AccessWideningLevel`);
|
|
2358
|
+
- a migration statement (`ResolvedMigrationStatement` and `MigrationStatementJson`, told apart by `kind` and `entity`) and a migration subject (`MigrationSubject` and `MigrationSubjectJson`);
|
|
2359
|
+
- the PSL parser's symbols, scope resolutions, token kinds, syntax kinds and diagnostic codes (`PslSymbol`, `ScopeResolution`, `TokenKind`, `SyntaxKind`, `PslDiagnosticCode`);
|
|
2360
|
+
- the `mode` of the result of the control API's `dbInit()` and `dbUpdate()`;
|
|
2361
|
+
- more of what the control API hands back: the `outcome` of a `spanEnd` progress event an `onProgress` callback receives, the `kind` of each entry of a result's `perSpace`, the `kind` of a migration plan's `migrationsToTarget`, what a plan question's `namespaceAnswer()` returns, the `reason` of the `unreachable` position `classifyInstalledSpaceRow()` returns, and the `verb` an `answerQuestions` callback receives for each subject answered without asking;
|
|
2362
|
+
- the `appliedStatements` of a `dbUpdate()` or migration plan result: a consent statement's `statement.kind` accepts any string beside `'delete'` and `'allow'`, and `AppliedStatementReport` gains a member whose `verb` is a `FutureCase` and which has no `statement`;
|
|
2363
|
+
- what the control API's `dbSign()` returns for each space (`DbSignSpaceOutcome`): its `status` gains a member whose `status` is a `FutureCase`, and a signature conflict gains a member whose `reason` is a `FutureCase` and which has no `expected` or `found`;
|
|
2364
|
+
- the `setting` of each policy difference a result's `databasePoliciesUpdated` lists (`DatabasePolicyDifference`), whose new member's `declared` and `inForce` are a string or a list of strings;
|
|
2365
|
+
- the `by` of a migration runner failure's `failedTypeChange` (`FailedTypeChange`), and the `provenance` of what `contractAt()` returns (`ContractAtResult`);
|
|
2366
|
+
- the `format` of a contract source (`ContractSourceProvider`, as `loadConfig()`, `loadConfigForFile()` and `loadConfigForSections()` return it in `contract.source`), which gains a member whose `format` is a `FutureCase`;
|
|
2367
|
+
- the `setting` and `subject` of the MongoDB contract builder's refusals (`BuildRefusal`, in a `BuildFailure`);
|
|
2368
|
+
- what the SQL contract DSL hands back: the state `RelationBuilder.build()` returns (its `kind`, and the `kind` and `source` of its `toModel` and `through`) and the `source` of a `TargetFieldRef` from `constraints.ref()`.
|
|
2369
|
+
|
|
2370
|
+
What to do:
|
|
2371
|
+
|
|
2372
|
+
- Where code checks every value, with a `switch` or a `const unreachable: never = value` assignment, add a `default` branch that acts as for a value the code does not know: report it, skip it, or throw.
|
|
2373
|
+
- To keep the compiler's check that every kind you know is handled, assign the value in the `default` branch to `FutureCase` in place of `never`: `const later: FutureCase = columnDefault.kind`. A kind the code forgets is still a compile error, and only a kind a later release adds reaches the branch.
|
|
2374
|
+
- Where code reads a member's own property in an `else` branch, such as `columnDefault.expression` after ruling out `'literal'`, check for the kind it means instead: `columnDefault.kind === 'function'`.
|
|
2375
|
+
- For `AppliedStatementReport`, read `statement` only after narrowing on a `verb` you handle.
|
|
2376
|
+
- For `DbSignSpaceOutcome`, `status === 'conflict'` no longer narrows to the conflict over the signature's hashes: read `expected` and `found` after `reason === 'storageHash'`.
|
|
2377
|
+
- For `ContractSourceProvider`'s `format`, branch on `'psl'` and `'typescript'` by name, and treat any other format as one the code does not read, never as TypeScript.
|
|
2378
|
+
- For the `mode` of a `dbInit()` or `dbUpdate()` result, use the `mode` the call was given.
|
|
2379
|
+
- A table keyed by one of these sets, such as a `Record` from each value to a message, accepts any key once the set is open, so a lookup with a value a later release adds returns `undefined` although its type says otherwise: check that the key is present, for example with `Object.hasOwn(table, key)`, before using what it returns.
|
|
2380
|
+
|
|
2381
|
+
## A PostGIS geometry may be of a type a later release adds
|
|
2382
|
+
|
|
2383
|
+
### `app-geometry-may-gain-types`
|
|
2384
|
+
|
|
2385
|
+
A PostGIS geometry (`Geometry`, also published as `GeometryValue`) may be of a type a later 8.x release adds, such as a geometry collection, which has no `coordinates`. The union gains a member whose `type` is a `FutureCase` and which carries only `type` and `srid`, so code that reads `coordinates` before checking `type` no longer compiles: check `type` first, for example `if (geometry.type === 'Point') use(geometry.coordinates)`. A `switch` over `type` that handles every type needs a `default` branch; to keep the compiler's check that every type you know is handled, assign the value there to `FutureCase` in place of `never`, as in `const later: FutureCase = geometry.type`. `FutureCase` is a type every entry of `@prisma/orm-extension-postgis` exports, so import it from the entry you import `Geometry` from, such as `import type { FutureCase, Geometry } from '@prisma/orm-extension-postgis/geojson'`. It only stands for a later type in the type, and no code can write it; at run time a later type arrives under its own name.
|