@prisma/orm-mongo 8.0.0-rc.9-dev.13 → 8.0.1-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/README.md +48 -8
  2. package/dist/components-CWskH7lF-Dkc9ysZz.mjs +18 -0
  3. package/dist/components-CWskH7lF-Dkc9ysZz.mjs.map +1 -0
  4. package/dist/config.d.mts +14 -5
  5. package/dist/config.d.mts.map +1 -1
  6. package/dist/config.mjs +47 -25
  7. package/dist/config.mjs.map +1 -1
  8. package/dist/contract-builder.d.mts +33 -91
  9. package/dist/contract-builder.d.mts.map +1 -1
  10. package/dist/contract-builder.mjs +23 -7
  11. package/dist/contract-builder.mjs.map +1 -1
  12. package/dist/contract-types.d.mts +3 -0
  13. package/dist/contract-types.mjs +1 -0
  14. package/dist/contract__format-version.d.mts +1 -0
  15. package/dist/contract__format-version.mjs +2 -0
  16. package/dist/contract__internal__format-version.d.mts +1 -0
  17. package/dist/contract__internal__format-version.mjs +2 -0
  18. package/dist/contract__validate-once.d.mts +1 -0
  19. package/dist/contract__validate-once.mjs +2 -0
  20. package/dist/contract__validate-storage.d.mts +1 -0
  21. package/dist/contract__validate-storage.mjs +2 -0
  22. package/dist/control.d.mts +1 -1
  23. package/dist/control.d.mts.map +1 -1
  24. package/dist/control.mjs +3 -9
  25. package/dist/control.mjs.map +1 -1
  26. package/dist/driver__runtime.d.mts +3 -0
  27. package/dist/driver__runtime.mjs +3 -0
  28. package/dist/family-contract__data-type.d.mts +1 -0
  29. package/dist/family-contract__data-type.mjs +2 -0
  30. package/dist/init-quick-reference.md +116 -0
  31. package/dist/init-readme.md +35 -0
  32. package/dist/init.d.mts +7 -0
  33. package/dist/init.d.mts.map +1 -0
  34. package/dist/init.mjs +245 -0
  35. package/dist/init.mjs.map +1 -0
  36. package/dist/migration.d.mts +1 -0
  37. package/dist/migration.mjs +2 -0
  38. package/dist/module-base-B70DHaBE-k_c3Klu4.mjs +6 -0
  39. package/dist/module-base-B70DHaBE-k_c3Klu4.mjs.map +1 -0
  40. package/dist/mongo-static-BrplLPTr-DGOk19X8.mjs +74 -0
  41. package/dist/mongo-static-BrplLPTr-DGOk19X8.mjs.map +1 -0
  42. package/dist/{mongo-static-BdSGXYgQ-DSA-2DiK.d.mts → mongo-static-DabeBtmV-DILuhcbE.d.mts} +18 -5
  43. package/dist/mongo-static-DabeBtmV-DILuhcbE.d.mts.map +1 -0
  44. package/dist/runtime.d.mts +49 -44
  45. package/dist/runtime.d.mts.map +1 -1
  46. package/dist/runtime.mjs +104 -42
  47. package/dist/runtime.mjs.map +1 -1
  48. package/dist/static.d.mts +24 -2
  49. package/dist/static.d.mts.map +1 -0
  50. package/dist/static.mjs +2 -2
  51. package/dist/target__codec-ids.d.mts +1 -0
  52. package/dist/target__codec-ids.mjs +2 -0
  53. package/dist/target__codecs.d.mts +1 -0
  54. package/dist/target__codecs.mjs +2 -0
  55. package/dist/target__data-types.d.mts +1 -0
  56. package/dist/target__data-types.mjs +2 -0
  57. package/dist/target__server-version.d.mts +1 -0
  58. package/dist/target__server-version.mjs +2 -0
  59. package/dist/utils__guards.d.mts +1 -0
  60. package/dist/utils__guards.mjs +2 -0
  61. package/dist/utils__text.d.mts +1 -0
  62. package/dist/utils__text.mjs +2 -0
  63. package/dist/utils__upgrade-guides.d.mts +1 -0
  64. package/dist/utils__upgrade-guides.mjs +2 -0
  65. package/package.json +37 -13
  66. package/skills/prisma-8/SKILL.md +23 -18
  67. package/skills/prisma-8/references/build-a-target-package.md +117 -0
  68. package/skills/prisma-8/references/build.md +12 -16
  69. package/skills/prisma-8/references/contract.md +181 -75
  70. package/skills/prisma-8/references/debug.md +35 -24
  71. package/skills/prisma-8/references/feedback.md +8 -8
  72. package/skills/prisma-8/references/migration-model.md +23 -14
  73. package/skills/prisma-8/references/migration-review.md +23 -52
  74. package/skills/prisma-8/references/migrations.md +294 -80
  75. package/skills/prisma-8/references/queries-mongo.md +53 -17
  76. package/skills/prisma-8/references/queries-postgres.md +345 -34
  77. package/skills/prisma-8/references/queries.md +44 -25
  78. package/skills/prisma-8/references/quickstart.md +25 -22
  79. package/skills/prisma-8/references/runtime.md +172 -72
  80. package/skills/prisma-8/references/supabase.md +22 -19
  81. package/skills/prisma-8/references/upgrade-app.md +57 -22
  82. package/skills/prisma-8/references/upgrade-extension.md +72 -23
  83. package/skills/prisma-8/upgrading/app/upgrades/0.11-to-0.12/instructions.md +1 -1
  84. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.10-to-8.0.0-rc.11/instructions.md +34 -0
  85. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/instructions.md +639 -0
  86. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/scripts/multifile-psl/add-use-prisma-8-directive.mjs +60 -0
  87. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/scripts/psl-verbatim-table-names/add-model-map.mjs +256 -0
  88. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/instructions.md +332 -0
  89. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/scripts/execution-ref-entry-field/rename-execution-ref-keys.ts +193 -0
  90. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.13-to-8.0.0-rc.14/instructions.md +489 -0
  91. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.14-to-8.0.0-rc.15/instructions.md +1368 -0
  92. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.14-to-8.0.0-rc.15/scripts/data-type-in-contract/data-type-in-contract.ts +1492 -0
  93. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.15-to-8.0.0-rc.16/instructions.md +108 -0
  94. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.16-to-8.0.0-rc.17/instructions.md +755 -0
  95. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.17-to-8.0.0-rc.18/instructions.md +973 -0
  96. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.17-to-8.0.0-rc.18/scripts/sql-expression-literals-psl/rewrite-sql-strings.mjs +271 -0
  97. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/instructions.md +1862 -0
  98. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/client-takes-contract-value/contract-from-json.ts +597 -0
  99. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/data-type-values/data-type-values.ts +1120 -0
  100. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/default-generators-to-on-create/rewrite-default-generators.mjs +86 -0
  101. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/mongo-field-storage-names/mongo-field-storage-names.ts +304 -0
  102. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/remove-nocheck/remove-nocheck.ts +2462 -0
  103. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/instructions.md +513 -0
  104. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/scripts/expand-type-aliases/expand-type-aliases.ts +1206 -0
  105. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.20-to-8.0.0-rc.21/instructions.md +803 -0
  106. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/instructions.md +586 -0
  107. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/scripts/value-objects-in-storage/value-objects-in-storage.ts +1184 -0
  108. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.22-to-8.0.0-rc.23/instructions.md +480 -0
  109. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.22-to-8.0.0-rc.23/scripts/mongo-index-names/mongo-index-names.ts +317 -0
  110. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/instructions.md +336 -0
  111. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-convenience-date-time-types/rewrite-mongo-date-types.ts +220 -0
  112. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-type-helpers/rewrite-mongo-field-types.ts +621 -0
  113. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.24-to-8.0.0-rc.25/instructions.md +1561 -0
  114. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.9-to-8.0.0-rc.10/instructions.md +13 -0
  115. package/skills/prisma-8/upgrading/extension/upgrades/0.11-to-0.12/instructions.md +1 -1
  116. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.10-to-8.0.0-rc.11/instructions.md +34 -0
  117. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/instructions.md +857 -0
  118. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/scripts/psl-verbatim-table-names/add-model-map.mjs +256 -0
  119. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/instructions.md +504 -0
  120. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/scripts/execution-ref-entry-field/rename-execution-ref-keys.ts +193 -0
  121. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.13-to-8.0.0-rc.14/instructions.md +143 -0
  122. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.14-to-8.0.0-rc.15/instructions.md +2168 -0
  123. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.14-to-8.0.0-rc.15/scripts/data-type-in-contract/data-type-in-contract.ts +1492 -0
  124. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.15-to-8.0.0-rc.16/instructions.md +223 -0
  125. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.16-to-8.0.0-rc.17/instructions.md +583 -0
  126. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.17-to-8.0.0-rc.18/instructions.md +1008 -0
  127. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/instructions.md +2186 -0
  128. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/client-takes-contract-value/contract-from-json.ts +597 -0
  129. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/data-type-values/data-type-values.ts +1120 -0
  130. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/default-generators-to-on-create/rewrite-default-generators.mjs +86 -0
  131. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/mongo-field-storage-names/mongo-field-storage-names.ts +304 -0
  132. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/remove-nocheck/remove-nocheck.ts +2462 -0
  133. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/instructions.md +381 -0
  134. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/scripts/expand-type-aliases/expand-type-aliases.ts +1206 -0
  135. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.20-to-8.0.0-rc.21/instructions.md +570 -0
  136. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/instructions.md +464 -0
  137. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.22-to-8.0.0-rc.23/instructions.md +410 -0
  138. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/instructions.md +303 -0
  139. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-convenience-date-time-types/rewrite-mongo-date-types.ts +220 -0
  140. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-type-helpers/rewrite-mongo-field-types.ts +621 -0
  141. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.24-to-8.0.0-rc.25/instructions.md +1593 -0
  142. package/dist/adapter__codec-ids.d.mts +0 -1
  143. package/dist/adapter__codec-ids.mjs +0 -2
  144. package/dist/adapter__codec-types.d.mts +0 -1
  145. package/dist/adapter__codec-types.mjs +0 -2
  146. package/dist/adapter__codecs.d.mts +0 -1
  147. package/dist/adapter__codecs.mjs +0 -2
  148. package/dist/mongo-static-BdSGXYgQ-DSA-2DiK.d.mts.map +0 -1
  149. package/dist/mongo-static-_wy-fC4P-mXlhePy0.mjs +0 -38
  150. package/dist/mongo-static-_wy-fC4P-mXlhePy0.mjs.map +0 -1
@@ -7,9 +7,9 @@ The data contract is the single source of truth for your data layer. You edit a
7
7
 
8
8
  1. **You edit your data contract.**
9
9
  2. **The system plans the migrations for you.** (`references/migrations.md`)
10
- 3. **If you need data migrations, you edit `migration.ts` and execute it.** (`references/migrations.md`)
10
+ 3. **If you need a data migration, you write a `dataTransform` in `migration.ts` and execute it.** Inserts, updates and deletes never go in a `rawSql` step. (`references/migrations.md`)
11
11
 
12
- Behind step 1 the agent runs `prisma contract emit` after every contract edit (or installs the Vite plugin so the bundler runs it on save — see `references/build.md`). Emit reads the contract source through the provider the façade picks based on the file extension of `contract:` in `prisma.config.ts`, then writes two artefacts colocated with the source:
12
+ Behind step 1 the agent runs `prisma contract emit` after every contract edit (or installs the Vite plugin so the bundler runs it on save — see `references/build.md`). Emit reads the contract source through the provider the database package picks based on the file extension of `contract:` in `prisma.config.ts`, then writes two artefacts colocated with the source:
13
13
 
14
14
  - `contract.json` — the canonical, content-hashed Contract IR. Read by the planner, the runtime, and `db verify`.
15
15
  - `contract.d.ts` — the precise TypeScript types the runtime + lanes propagate when you import `Contract` from it.
@@ -23,10 +23,11 @@ Both files are **emitted artefacts**. Edit the source; never the JSON or `.d.ts`
23
23
  - User wants to add a namespace block (Postgres schema) or a cross-contract foreign key.
24
24
  - User wants to set `@@control` on a model or configure `defaultControlPolicy`.
25
25
  - User wants to use a custom type from an extension (`pgvector.Vector(length: 1536)`, `postgis.Geometry(...)`).
26
- - User wants to install or configure an extension via `extensions: [...]` in `prisma.config.ts`, including `@internal/extension-supabase`.
26
+ - User needs a column of a database type no Prisma column type covers (`tsvector`, `ltree`, `circle`, a domain): a raw column, ``Raw(sql`...`)``.
27
+ - User wants to install or configure an extension via `extensions: [...]` in `prisma.config.ts`, including `@prisma/orm-extension-supabase`.
27
28
  - User is migrating between authoring sources (PSL ↔ TypeScript builder).
28
29
  - User received `CONFIG.CONTRACT_MISSING`, `CONTRACT.VALIDATION_FAILED`, or `CONFIG.MISSING_EXTENSION_PACKS` from `contract emit`.
29
- - User mentions: *schema, fields, models, attributes, prisma schema, PSL, contract.prisma, contract.ts, contract.json, contract.d.ts, contract emit, façade imports, `@internal/postgres/config`, `@internal/postgres/contract-builder`, extensions, pgvector, postgis, paradedb, supabase, namespaces, cross-space FK, `@@control`, enums, check constraints, `@@check`, value objects, validations, callbacks, soft delete, paranoid, scopes*. (The last cluster routes to *What Prisma 8 doesn't do yet* below.)
30
+ - User mentions: *schema, fields, models, attributes, prisma schema, PSL, contract.prisma, contract.ts, contract.json, contract.d.ts, contract emit, database package imports, `@prisma/orm-postgres/config`, `@prisma/orm-postgres/contract-builder`, extensions, pgvector, postgis, supabase, namespaces, cross-space FK, `@@control`, enums, check constraints, `@@check`, value objects, validations, callbacks, soft delete, paranoid, scopes*. (The last cluster routes to *What Prisma 8 doesn't do yet* below.)
30
31
 
31
32
  ## When Not to Use
32
33
 
@@ -40,31 +41,35 @@ Both files are **emitted artefacts**. Edit the source; never the JSON or `.d.ts`
40
41
 
41
42
  ## Key Concepts
42
43
 
43
- - **The `@internal/<target>` façade is the only surface user-authored code imports from.** For a Postgres app: `@internal/postgres/config`, `@internal/postgres/contract-builder`, `@internal/postgres/control`, `@internal/postgres/runtime`. Mongo has the same layout (`@internal/mongo/config`, `@internal/mongo/contract-builder`, `@internal/mongo/runtime`). Each extension publishes its own façade — `@internal/extension-pgvector/control`, `@internal/extension-postgis/control`, `@internal/extension-paradedb/control`. **Never reach into `@internal/cli/*`, `@internal/family-*`, `@internal/target-*`, `@internal/adapter-*`, `@internal/driver-*`, or `@internal/sql-contract-*` from user code.** The façade bakes the family / target / adapter / driver wiring in. See *Common Pitfalls* #4.
44
+ - **The `@prisma/orm-<target>` package is the only surface user-authored code imports from.** For a Postgres app: `@prisma/orm-postgres/config`, `@prisma/orm-postgres/contract-builder`, `@prisma/orm-postgres/control`, `@prisma/orm-postgres/runtime`, `@prisma/orm-postgres/static`. Mongo has the same layout (`@prisma/orm-mongo/config`, `@prisma/orm-mongo/contract-builder`, `@prisma/orm-mongo/runtime`, `@prisma/orm-mongo/static`). Each extension publishes its own entry points — `@prisma/orm-extension-pgvector/control`, `@prisma/orm-extension-postgis/control`. **Never import the platform packages (`@prisma/orm-framework`, `@prisma/orm-family-*`, `@prisma/orm-target-*`, `@prisma/orm-toolchain`) from user code.** The database package bakes the family / target / adapter / driver wiring in. See *Common Pitfalls* #4.
44
45
  - **Contract source.** A file the framework reads and lowers to the canonical Contract IR. Two flavours, both first-class:
45
- - **`contract.prisma` (PSL)** — schema-flavoured DSL. Canonical for typical apps and brownfield Prisma users. Wired by `contract: './<path>/contract.prisma'` — the target config (`ormConfig`, below) detects the `.prisma` extension and routes through the PSL provider.
46
- - **`contract.ts` (TypeScript builder)** — programmatic authoring with `defineContract({...}, ({ field, model, rel, type }) => ({...}))` from `@internal/postgres/contract-builder` (or `@internal/mongo/contract-builder`). Wired by `contract: './<path>/contract.ts'` — the façade detects the `.ts` extension and routes through the TS provider. Use when you need programmatic composition (per-tenant variants, generated fields) or constructs PSL doesn't yet express (e.g. registering a parameterised extension type — see pgvector's contract).
47
- - **`prisma.config.ts`.** Wires the contract source, the database connection, the migrations directory, and any installed extensions. The file is an *envelope*: the unified CLI's `definePrismaConfig({...})` from `@prisma/cli-engine` wraps an `orm:` section built by the target's `defineConfig` — conventionally imported as `ormConfig` from `@internal/postgres/config` (or `@internal/mongo/config`). There is no flat form; a bare `defineConfig({ contract, ... })` default export fails with `CONFIG.VERSION_MARKER_MISSING`.
46
+ - **`contract.prisma` (PSL)** — schema-flavoured DSL. Canonical for typical apps and brownfield Prisma users. Wired by `contract: './<path>/contract.prisma'` — the target config (`ormConfig`, below) detects the `.prisma` extension and routes through the PSL provider. On PostgreSQL the entry is an object that also lists every capability the contract requires: `contract: { path: './<path>/contract.prisma', requiredCapabilities: [...postgres18, ...postgresDriver] }`, with `postgres18` (what PostgreSQL 18 provides; `postgres15` to `postgres17` for older databases) and `postgresDriver` (what the driver's connection provides, such as interactive transactions) imported from `@prisma/orm-postgres/config`. The list must not be empty and nothing is added to it; filter a key out to stop requiring it. The first line of every `.prisma` file is `// use prisma-8`; `orm init` and `contract infer` write it, and the language server only serves diagnostics, completion, and formatting on files that carry it (it still recognises the header earlier releases wrote and rewrites it on Format).
47
+ - **`contract.ts` (TypeScript builder)** — programmatic authoring with `defineContract({...}, ({ field, model, rel, type }) => ({...}))` from `@prisma/orm-postgres/contract-builder` (or `@prisma/orm-mongo/contract-builder`, `@prisma/orm-sqlite/contract-builder`, `@prisma/orm-mysql/contract-builder`, `@prisma/orm-mariadb/contract-builder`). Wired by `contract: './<path>/contract.ts'` — the database package detects the `.ts` extension and routes through the TS provider. On PostgreSQL, `defineContract` takes `requiredCapabilities: [...postgres18, ...postgresDriver]` the same way, imported from `@prisma/orm-postgres/contract-builder`. Use when you need programmatic composition (per-tenant variants, generated fields) or constructs PSL doesn't yet express (e.g. registering a parameterised extension type — see pgvector's contract).
48
+ - **An existing Prisma schema, during adoption.** A project that still runs an earlier Prisma can point `contract:` at its current `schema.prisma` instead of writing a Prisma 8 contract: `contract: prisma6Schema('prisma/schema.prisma')` from `@prisma/orm-mongo/config` reads a Prisma 6 MongoDB schema, and `prisma7Schema` from `@prisma/orm-postgres/config` reads a Prisma 7 Postgres schema. The earlier Prisma keeps owning the database; after each change there, run `contract emit` and `db sign`. A construct Prisma 8 cannot express fails `contract emit` with a `PSL.PRISMA6_MONGO_*` or `PSL.PRISMA7_*` diagnostic. See the database package READMEs for the details.
49
+ - **`prisma.config.ts`.** Wires the contract source, the database connection, the migrations directory, and any installed extensions. The file is an *envelope*: the unified CLI's `definePrismaConfig({...})` from `@prisma/cli-engine` wraps an `orm:` section built by the target's `defineConfig` — conventionally imported as `ormConfig` from `@prisma/orm-postgres/config` (or `@prisma/orm-mongo/config`). There is no flat form; a bare `defineConfig({ contract, ... })` default export fails with `CONFIG.VERSION_MARKER_MISSING`. Pass `formatter: { indent, newline }` to `ormConfig` to set how `prisma contract format` and the language server lay out PSL files: `indent` is a whole number of spaces, 1 or more (default 2), or `'tab'`. `newline` is `'LF'` or `'CRLF'`; without it, `contract format` uses the operating system's line ending and the language server uses LF.
48
50
 
49
51
  ```typescript
50
52
  // prisma.config.ts — what `prisma orm init` scaffolds
51
53
  import 'dotenv/config';
54
+ import { defineConfig as ormConfig, postgres18, postgresDriver } from '@prisma/orm-postgres/config';
52
55
  import { definePrismaConfig } from '@prisma/cli-engine';
53
- import { defineConfig as ormConfig } from '@internal/postgres/config';
54
56
 
55
57
  export default definePrismaConfig({
56
58
  orm: ormConfig({
57
- contract: './src/prisma/contract.prisma',
59
+ contract: {
60
+ path: './src/prisma/contract.prisma',
61
+ requiredCapabilities: [...postgres18, ...postgresDriver],
62
+ },
58
63
  db: { connection: process.env['DATABASE_URL']! },
59
64
  }),
60
65
  });
61
66
  ```
62
67
 
63
- The fields `ormConfig` accepts: `contract` (path string — `.prisma` or `.ts`), `output` (optional override for where `contract.json` lands), `db` (`{ connection?: string }`), `extensions` (array of control descriptors), `migrations` (`{ dir?: string }`). Without `output`, the path for `contract.json` is derived from `contract` (e.g. `./src/prisma/contract.prisma` → `./src/prisma/contract.json`). Keep `import 'dotenv/config'` when the config reads `process.env`.
64
- - **Emit pipeline.** `prisma contract emit --config <path>?` reads `prisma.config.ts`, calls the provider the façade picked, validates the resulting Contract, then atomically writes `contract.json` + `contract.d.ts` colocated with the source.
65
- - **Extension namespaces.** Extensions contribute namespaced constructors (`pgvector.Vector(length: 1536)`, `postgis.Geometry(...)`) and helper presets. Install them by adding the descriptor to **two** places — both fields are named `extensions`, but the two surfaces consume two different descriptor types and shapes:
66
- - **In the config (façade and core):** `extensions: [pgvector]` — array of *control* descriptors imported from `@internal/extension-<name>/control`.
67
- - **In the TS builder's `defineContract` (only when authoring `contract.ts`):** `extensions: { pgvector }` — record of *pack* descriptors imported from `@internal/extension-<name>/pack`.
68
+ The fields `ormConfig` accepts: `contract` (path string — `.prisma` or `.ts`), `output` (optional override for where `contract.json` lands), `db` (`{ connection?: string }`), `extensions` (array of control descriptors), `migrations` (`{ dir?: string }`), `formatter` (`{ indent?: number | 'tab'; newline?: 'LF' | 'CRLF' }`). Without `output`, the path for `contract.json` is derived from `contract` (e.g. `./src/prisma/contract.prisma` → `./src/prisma/contract.json`). Keep `import 'dotenv/config'` when the config reads `process.env`.
69
+ - **Emit pipeline.** `prisma contract emit --config <path>?` reads `prisma.config.ts`, calls the provider the database package picked, validates the resulting Contract, then atomically writes `contract.json` + `contract.d.ts` colocated with the source.
70
+ - **Extension namespaces.** Extensions contribute namespaced constructors (`pgvector.Vector(length: 1536)`, `postgis.Geometry(...)`) and type aliases. Install them by adding the descriptor to **two** places — both fields are named `extensions`, but the two surfaces consume two different descriptor types and shapes:
71
+ - **In the config (database package and core):** `extensions: [pgvector]` — array of *control* descriptors imported from `@prisma/orm-extension-<name>/control`.
72
+ - **In the TS builder's `defineContract` (only when authoring `contract.ts`):** `extensions: { pgvector }` — record of *pack* descriptors imported from `@prisma/orm-extension-<name>/pack`.
68
73
  - **Contract space.** Every package that emits a contract owns its own *contract space* — a `prisma.config.ts` at package root, a contract source, the colocated emitted artefacts, and a `migrations/` directory. **There are two intentional on-disk layouts**, picked by whether the contract space is the consuming application or a contract-space package (an extension, an internal aggregate-root package, etc.):
69
74
  - **Application layout** (what you use when building an *app*). `prisma.config.ts` at repo root; `src/prisma/contract.{prisma,ts}`; `src/prisma/contract.{json,d.ts}` colocated; `src/prisma/db.ts` colocated; migrations under `migrations/app/<timestamp>_<slug>/`. The `app/` segment is the consuming application's space-id; extension space-ids land in sibling `migrations/<extension-space-id>/` directories that the extension packages manage. This is what `examples/prisma-8-demo` uses and what `prisma orm init` scaffolds by default (`src/prisma/contract.prisma` with `db.ts` beside it).
70
75
  - **Contract-space-package layout** (what you use when *publishing* a contract-space package — extensions, internal monorepo packages). `prisma.config.ts` at package root; `src/contract.{prisma,ts}` directly (no `prisma/` subdir); `src/contract.{json,d.ts}` colocated; `migrations/<timestamp>_<slug>/` directly under `migrations/` (no `<space-id>` segment — the package *is* a single space). Documented in `.cursor/rules/contract-space-package-layout.mdc` and ADR 212.
@@ -77,14 +82,14 @@ Both files are **emitted artefacts**. Edit the source; never the JSON or `.d.ts`
77
82
 
78
83
  | Code | Meaning | Next move |
79
84
  |---|---|---|
80
- | `CONFIG.CONTRACT_MISSING` | `contract` not set in `prisma.config.ts`. | Add `contract: './src/prisma/contract.prisma'` (app layout) or `'./src/contract.prisma'` (contract-space-package layout) — likewise for `.ts` sources — to the `ormConfig({...})` section. |
85
+ | `CONFIG.CONTRACT_MISSING` | `contract` not set in `prisma.config.ts`. | Add `contract: './src/prisma/contract.prisma'` (app layout) or `'./src/contract.prisma'` (contract-space-package layout) — likewise for `.ts` sources — to the `ormConfig({...})` section. On PostgreSQL a `.prisma` path is an object with its required capabilities: `{ path: './src/prisma/contract.prisma', requiredCapabilities: [...postgres18, ...postgresDriver] }`. |
81
86
  | `CONFIG.VERSION_MARKER_MISSING` | The default export was not produced by `definePrismaConfig` / `ormConfig` (a flat `defineConfig({...})`, a plain object, or a Prisma 7 config). | Rewrite to the envelope form in *Key Concepts* above. |
82
87
  | `CONTRACT.VALIDATION_FAILED` | Source loaded but the Contract IR failed structural validation. | Read `meta.errors` for the offending model/field, fix the source, re-emit. |
83
- | `CONFIG.MISSING_EXTENSION_PACKS` | The contract uses a namespaced constructor (e.g. `pgvector.Vector(...)`) but `extensions` in the config does not list a matching descriptor. `meta.missingExtensionPacks` names them. | Install the package, import its control descriptor (`import pgvector from '@internal/extension-pgvector/control'`), add it to `extensions: [...]` in `ormConfig({...})`. |
88
+ | `CONFIG.MISSING_EXTENSION_PACKS` | The contract uses a namespaced constructor (e.g. `pgvector.Vector(...)`) but `extensions` in the config does not list a matching descriptor. `meta.missingExtensionPacks` names them. | Install the package, import its control descriptor (`import pgvector from '@prisma/orm-extension-pgvector/control'`), add it to `extensions: [...]` in `ormConfig({...})`. |
84
89
 
85
90
  ## Workflow — Read the contract source of truth
86
91
 
87
- The concept: every contract change starts by locating the source file. The config is authoritative — read `prisma.config.ts`, find the `contract:` field (a path string under the façade), and open the file it points at. The same field tells you the installed `extensions: [...]`.
92
+ The concept: every contract change starts by locating the source file. The config is authoritative — read `prisma.config.ts`, find the `contract:` field (a path string under the database package), and open the file it points at. The same field tells you the installed `extensions: [...]`.
88
93
 
89
94
  ```bash
90
95
  cat prisma.config.ts
@@ -94,12 +99,13 @@ If `contract:` ends in `.prisma`, the source is PSL; if it ends in `.ts`, the so
94
99
 
95
100
  ## Workflow — Edit a model / field / relation (PSL)
96
101
 
97
- The concept: PSL models lower to tables (or collections, on Mongo); fields lower to columns; `@relation(...)` declares the FK side. Add the relation only on the owning side — the framework derives the back-reference automatically.
102
+ The concept: PSL models lower to tables (or collections, on Mongo); fields lower to columns; `@relation(...)` declares the FK side. The other model gets a relation, and something to `include` from, only when it declares the back-reference itself with no `fields`/`references`: a list field (`posts Post[]`), or an optional singular field for a one-to-one (`profile Profile?`). A singular back-reference needs the FK fields to be unique (`@unique`, or `@@unique([...])` on the FK side); otherwise emit fails with `PSL_NON_UNIQUE_BACKRELATION`.
98
103
 
99
104
  ```prisma
100
105
  model User {
101
106
  id Int @id @default(autoincrement())
102
107
  email String @unique
108
+ posts Post[]
103
109
  }
104
110
 
105
111
  model Post {
@@ -115,18 +121,37 @@ model Post {
115
121
 
116
122
  Then run `pnpm prisma contract emit` (or rely on the Vite plugin — see `references/build.md`). Specify cascade behaviour explicitly with `onDelete` / `onUpdate`; the default is `Restrict`.
117
123
 
118
- **Temporal columns.** On PostgreSQL, `Date`, `Timestamp(p)`, `Timestamptz(p)` and `Time(p)` read and write `Temporal` values (`Temporal.PlainDate`, `PlainDateTime`, `Instant`, `PlainTime`), never JavaScript `Date`. They need a global `Temporal` at query time: Node.js 26.8.2 and later ship `globalThis.Temporal`; 26.8.1 and earlier — including every 22 and 24 release — do not, and the first read or write of such a column throws `RUNTIME.TEMPORAL_UNAVAILABLE`. On those runtimes either `import 'temporal-polyfill/full/global'` before the first query (add `temporal-polyfill` as a dependency) or author the column as `DateString` / `TimestampString(p)` / `TimestamptzString(p)` / `TimeString(p)`, which carry PostgreSQL's own text and need no `Temporal`.
124
+ **Integer, decimal, float, text, boolean, binary and JSON types.** On PostgreSQL, `Int`, `BigInt`, `Float`, `Decimal`, `String`, `Boolean`, `Bytes` and `Json` are convenience types: bare, each is the usual type (`Int` an `int4`, `BigInt` an `int8` read as a `bigint`, `Decimal` a `numeric` read as decimal text, `String` a `text`, `Json` a `json`). An optional `storage` chooses another database type, and `BigInt` also takes `as`: `Int(storage: int2)`, `BigInt(as: number)` (an `int8` read as a `number` in the safe-integer range), `BigInt(storage: numeric)` (an integer of any size, read as a `bigint`), `Float(storage: float4)`, `Decimal(precision: 10, scale: 2)`, `String(storage: varchar, length: 12)`, `String(storage: char, length: 3)`, `Json(storage: jsonb)`. `String(length: 12)` is refused: `length` applies only to `varchar` and `char`. The contract stores the explicit type each call chooses, named after the database type (`Int2`, `Int4`, `Int8BigInt`, `Int8Number`, `NumericString`, `NumericBigInt`, `Float4`, `Float8`, `Text`, `Varchar`, `Char`, `Bool`, `Bytea`, `Jsonb`; a `json` column is `PlainJson`), and writing that type directly is the same. A `json` column cannot be filtered by equality, and PostgreSQL refuses an index or a unique constraint on it; write `Json(storage: jsonb)` for a JSON field that needs any of these. `SmallInt`, `BigIntNumber`, `Numeric`, `UnboundedInt`, `Real` and `VarChar` are deprecated names of `Int2`, `Int8Number`, `NumericString`, `NumericBigInt`, `Float4` and `Varchar`, and warn `PSL_DEPRECATED_SCALAR_NAME`. In a TypeScript contract: `type.BigInt({ as: 'number' })`, `type.String({ storage: 'varchar', length: 64 })`, `type.Json({ storage: 'jsonb' })`. On SQLite, `Int`, `BigInt`, `Float`, `Decimal`, `String`, `Boolean`, `Bytes` and `Json` are convenience types too, each with one `storage`, the SQLite column type: the contract stores `IntegerNumber` (`Int`, and `BigInt(as: number)`), `IntegerBigInt` (`BigInt`), `Real`, `DecimalString` (`Decimal`), `Text`, `IntegerBoolean` (`Boolean`), `Blob` or `PlainJson`, and writing that type directly is the same. Its column helpers are named after these types: `integerNumberColumn`, `integerBigIntColumn`, `realColumn`, `decimalStringColumn`, `textColumn`, `integerBooleanColumn`, `blobColumn`, `plainJsonColumn`. A SQLite `Boolean` is an `integer` column holding 0 or 1; `@default(true)` is written `DEFAULT 1`, and reading any other stored value raises `RUNTIME.DECODE_FAILED` naming the column. An `Int` (`IntegerNumber`) write refuses a number that is not an integer in the safe-integer range, such as `1.5`. A SQLite `Decimal` is decimal text such as `"12.50"` in a `text` column: a write refuses other text, and since text compares by its characters it takes equality filters only, with no ordering and no aggregates. `BigIntNumber` is a deprecated name of `IntegerNumber` and warns `PSL_DEPRECATED_SCALAR_NAME`; write `BigInt(as: number)`. On MySQL and MariaDB, the eight names are convenience types too: the contract stores `Int4` (`Int`, an `int`), `Int8BigInt` (`BigInt`) or `Int8Number` (`BigInt(as: number)`), both a `bigint`, `Float8` (`Float`, a `double`), `NumericString` (`Decimal`, a `decimal(65,30)`; an unwritten `precision` is 65 and an unwritten `scale` 30, so `Decimal(precision: 40)` is `decimal(40,30)`, unlike PostgreSQL: write both), `Varchar` (`String`, a `varchar(191)` unless `length` is written) or `Text` (`String(storage: text)`), `Bool` (`Boolean`, a `tinyint(1)` holding 0 or 1), `Longblob` (`Bytes`) or `PlainJson` (`Json`, a `json` column, which MariaDB stores as `longtext` with a `json_valid` check). A MySQL `Decimal` reads as the server prints it, padded to the column's scale (`"1.50"` in a `decimal(10,2)`), and has no `avg`. A `Json` field has no equality filter or ordering. A `Bytes`, `Json` or `String(storage: text)` field cannot be an `@id`, and on MySQL not `@unique` either: `db migrate` fails, because MySQL needs a prefix length Prisma does not write. Defaults: `@default(true)`, ``@default(longblob`00ff`)``, ``@default(json`{"a": 1}`)``.
119
125
 
120
- `@@index` also accepts `expression:` (instead of a fields list), `where:` (partial-index predicate), `unique:`, `type:`/`options:` (target-registered access method), and `name:` xor `map:`:
126
+ **Date and time types.** On PostgreSQL, write a field with a convenience type named for what it means: `DateTime` (a moment in time, a `timestamptz(3)` read as a JavaScript `Date`), `Date` (a calendar date, read as a string such as `"2024-02-29"`), `Time` (a time of day, read as a string) or `Duration` (an ISO 8601 duration string such as `"P1M"`). None needs `Temporal`. Optional arguments choose another explicit type: `as`, the value the application reads (`jsDate`, `temporal` or `string` for `DateTime`; `string` or `temporal` for `Date` and `Time`; `string` or `parts` for `Duration`), `storage`, the database type that stores it (`timestamptz` or `timestamp` for `DateTime`; `time` or, with `as: string`, `timetz` for `Time`), and `precision`: `DateTime(as: temporal)`, `DateTime(storage: timestamp)`, `Time(precision: 0)`. The contract stores only the explicit type, and `contract print` writes it; the full table is [Scalar types](https://github.com/prisma/orm/blob/main/docs/reference/scalar-types.md). SQLite has the same four types with the same defaults, all stored as text: `DateTime` reads a `Date`, `DateTime(as: temporal)` a `Temporal.Instant` and `DateTime(as: string)` the stored text `"2024-01-01T00:00:00.000Z"`; `Date` and `Time` read `"2024-02-29"` and `"09:30:00.000"`, or `Temporal.PlainDate` and `Temporal.PlainTime` with `as: temporal`; `Duration` reads an ISO 8601 duration. SQLite has no `storage` choices and no `precision`: an instant and a time hold milliseconds. MySQL and MariaDB have the same four types with the same defaults: `DateTime` is a `datetime(3)` read as a `Date`, `storage: timestamp` picks a `timestamp` column (1970 to 2038), and `as: temporal` and `as: string` default to `precision: 6`; `Date` and `Time` read `"2024-02-29"` and `"09:30:00"`; `Duration` is ISO 8601 text in a `varchar(191)`. Every MySQL and MariaDB instant is UTC, and a value written with more fraction digits than its column holds is cut to the column's precision, not rounded, but a value with digits below a microsecond (a `Temporal` value ending in `.123456789`) is refused, so round it to microseconds first; a column with no written precision holds whole seconds. `Time(3)` is refused, because the first argument is `as`; write `Time(precision: 3)`. In a TypeScript contract the helpers take one object: `type.DateTime({ as: 'string', precision: 6 })`, `type.Time({ storage: 'timetz' })`.
127
+
128
+ **Temporal columns.** On PostgreSQL, `DateTemporal`, `TimestampTemporal(p)`, `TimestampInstant(p)`, `TimestamptzTemporal(p)` and `TimeTemporal(p)`, on SQLite `DatetimeTemporal`, `DateTemporal` and `TimeTemporal`, on MySQL and MariaDB `DatetimeTemporal(p)`, `TimestampTemporal(p)`, `DateTemporal` and `TimeTemporal(p)`, on MongoDB `DateInstant`, `DateTemporal` and `TimeTemporal` (and a convenience type with `as: temporal` on any of them) read and write `Temporal` values (`Temporal.PlainDate`, `PlainDateTime`, `Instant` for both instant types, `PlainTime`), never JavaScript `Date`. They need a global `Temporal` at query time: Node.js 26.8.2 and later ship `globalThis.Temporal`; 26.8.1 and earlier — including every 22 and 24 release — do not, and the first read or write of such a column throws `RUNTIME.TEMPORAL_UNAVAILABLE`. On those runtimes either `import 'temporal-polyfill/full/global'` before the first query (add `temporal-polyfill` as a dependency) or author the column as `DateString` / `TimestampString(p)` / `TimestamptzString(p)` / `TimeString(p)`, which carry ISO 8601 text, the same on every server (`2024-01-01T00:00:00Z` for a `timestamptz`, the instant in UTC), and need no `Temporal`, or as `TimestamptzJsDate(p)` / `TimestampJsDate(p)`, which read a JavaScript `Date`. `IntervalParts(p)` reads `{ months, days, micros }` and `IntervalString(p)` an ISO 8601 duration such as `P1Y2M`. `prisma contract emit`, `prisma db init` and the other commands need no global `Temporal`: the Postgres, SQLite, MySQL, MariaDB and MongoDB targets load `temporal-polyfill` as a fallback `Temporal` for the control plane, and set no global. `temporal-polyfill` is a required peer dependency of `@prisma/orm-postgres`, `@prisma/orm-sqlite`, `@prisma/orm-mysql`, `@prisma/orm-mariadb` and `@prisma/orm-mongo`. npm, pnpm and bun install it automatically. With Yarn, add `temporal-polyfill` (`^1.0.4`) to the project's dependencies, or the commands fail because Node.js cannot find the package. That fallback is held once per process. An application that loads control-plane code in its own process, such as server code under `vite dev` with the Prisma Vite plugin or a script that calls the control client, decodes dates without its own `Temporal`, and then fails in production. An application that uses the Temporal codecs must load its own `Temporal`. A TypeScript contract file that constructs a `Temporal` value must load an implementation too.
129
+
130
+ `@@index` also accepts `expression:` (instead of a fields list), `where:` (partial-index predicate), `unique:`, `type:`/`options:` (target-registered access method), and `name:` xor `map:`. Raw SQL in `expression:` and `where:` is a `sql` literal; a quoted string is refused with `PSL_VALUE_TYPE_INCOMPATIBLE`, whose message gives the rewrite:
131
+
132
+ ```prisma
133
+ @@index(expression: sql`lower(email)`, name: "users_email_lower")
134
+ @@index([authorId], where: sql`(archived_at IS NULL)`, name: "posts_author_active")
135
+ ```
136
+
137
+ `name:` declares a wire-named index (physical name `<name>_<8-hex hash>`, renames plan as `ALTER INDEX … RENAME`); `map:` adopts an exact physical name verbatim (for infer-captured objects — combining it with a SQL body warns, because drift detection byte-compares the authored text against Postgres's reprint). An `expression:` requires `name:` or `map:`. The TS builder mirrors this via `constraints.index([cols.x], {...})` / `constraints.index({ expression, ... })`, where `expression` and `where` are `sql` values such as ``sql`lower(email)` `` (a string does not compile) — see `packages/2-sql-family/2-authoring/contract-ts/README.md`.
138
+
139
+ **Full-text search indexes (PostgreSQL).** Do not hand-write the `to_tsvector` expression — Postgres only uses the index when the query carries the same search document: the same columns, configuration and weights. Declare `@@fullTextIndex`, and the index and the queries `fullTextMatches` / `fullTextRank` / `fullTextHeadline` build are rendered from the same definition (see `references/queries-postgres.md`):
121
140
 
122
141
  ```prisma
123
- @@index(expression: "lower(email)", name: "users_email_lower")
124
- @@index([authorId], where: "(archived_at IS NULL)", name: "posts_author_active")
142
+ @@fullTextIndex([text], name: "message_text_search")
143
+ @@fullTextIndex([summary], language: "german", name: "message_summary_search_de")
144
+ @@fullTextIndex([text], where: sql`archived_at IS NULL`, name: "message_text_search_live")
145
+ @@fullTextIndex([[title, subtitle], body], name: "post_search")
125
146
  ```
126
147
 
127
- `name:` declares a wire-named index (physical name `<name>_<8-hex hash>`, renames plan as `ALTER INDEX … RENAME`); `map:` adopts an exact physical name verbatim (for infer-captured objects — combining it with a SQL body warns, because drift detection byte-compares the authored text against Postgres's reprint). An `expression:` requires `name:` or `map:`. The TS builder mirrors this via `constraints.index([cols.x], {...})` / `constraints.index({ expression, ... })` — see `packages/2-sql/2-authoring/contract-ts/README.md`.
148
+ The fields are one field, or a list whose items are fields or lists of fields. Each top-level item is a weight group, strongest first (`A` to `D`, so at most four groups); fields in a nested list share a weight. `[title, body]` is two groups, `[[title, body]]` one. A single field has no weight. Diagnostics refuse more than four groups, an empty group, a field named twice, an unknown field and a field that is not text.
149
+
150
+ The TS builder has the same helper: `fullTextIndex(cols.text, { name: 'message_text_search' })` or `fullTextIndex([[cols.title, cols.subtitle], cols.body], { name: 'post_search' })`, from `@prisma/orm-postgres/contract-builder`, inside the model's `sql({ indexes: [...] })`. Both take an optional `language` (default `english`, from the same allowlist the operations accept), an optional `where:` for a partial index (a `sql` value, ``where: sql`archived_at IS NULL` ``), and `name:` xor `map:`. Both are repeatable. In the SQL builder, pass the index itself, `table.indexes.<name>`, to `fullTextMatches` and `fullTextRank`, which then search its document with its groups and language. A column or a `fullTextDocument` given other groups or another `language` than the index is silent, costing the index and falling back to a sequential scan. The parser that builds the query (`websearchToTsquery` and the others) takes its own `language` for the query side; it does not affect index use. With `map:` the index keeps the exact database name you give it, and `db verify` compares the rendered search document with the text Postgres prints back for the index exactly, character for character. Postgres prints it in its own form (`to_tsvector('english'::regconfig, title)`), so a `map:` full-text index reports drift; `@@fullTextIndex` and `fullTextIndex` warn about this with `PN_EXACT_NAME_BODY_COMPARISON`. Use `name:` unless the database already has the index under that name.
151
+
152
+ The contract stores the index as data, not SQL: an index of type `fullText` whose `columns` are the covered storage columns and whose `options` are `{ weightGroups, language }`, the weight groups as storage column names. The DDL is a GIN index over the rendered document, `to_tsvector('<language>', "<column>")` for one field, and `setweight(...) || ...` with every column wrapped in `coalesce` for several. `@@index(expression: …)` remains only for expressions this attribute does not cover.
128
153
 
129
- PSL alias surface for repeated types lives in a top-level `types {}` block:
154
+ PSL aliases for repeated types are declared in top-level `types {}` blocks. A schema may have several `types` blocks, in one file or several; each name may be declared only once across all of them, and a repeated name fails with `PSL_DUPLICATE_DECLARATION`:
130
155
 
131
156
  ```prisma
132
157
  types {
@@ -139,29 +164,30 @@ model User {
139
164
  }
140
165
  ```
141
166
 
142
- Note: scalar lists (e.g. `String[]`) are gated on the target's `sql.scalarList` capability — PostgreSQL declares it, so `tags String[]` lowers to an array column (with a generated no-NULL-elements check, see `@noCheck` under *Enums*); SQLite does not, and rejects the field with `PSL_SCALAR_LIST_UNSUPPORTED_TARGET`. Implicit Prisma-ORM many-to-many (list navigation on both sides without a join model) is rejected by the SQL interpreter — declare the join model explicitly and the ORM traverses it for you (`references/queries.md`). Composite/embeddable types (`type Address { ... }` with `address Address` on a model) are supported: the interpreter lowers them to `valueObjects` in the domain and stores them as `jsonb` columns. See *Workflow — Value objects* below.
167
+ An alias is expanded into each field that uses it: the column stores the alias's codec and type params, and the contract stores no alias. An alias may carry `@default`, `@onCreate` and `@onUpdate`, which every field typed by it takes: `UpdatedAt = TimestampString(3) @onCreate(now()) @onUpdate(now())`. It may not carry `@id` or `@unique`; write those on the field. A field may add attributes its alias does not set (`updatedAt UpdatedAt @default(now())`), but repeating one the alias sets is `PSL_DUPLICATE_ATTRIBUTE`. An alias may not name another alias. The targets contribute `temporal.CreatedAt` (generated on create) and `temporal.UpdatedAt` (on create and on update), written bare: `createdAt temporal.CreatedAt`. On Postgres they are `DateTime` with its defaults, a `timestamptz(3)` column read as a JavaScript `Date`; on SQLite and MongoDB `DateTime`. They take no arguments; for another kind of value or a precision, write the type and attributes, as in `DateTime(as: string) @onCreate(now())`. The SQL targets also contribute an alias for the column of each identifier format the client generates: `sql.UuidString`, `sql.Ulid`, `sql.Nanoid`, `sql.Cuid2` and `sql.Ksuid`, which Postgres also names at the top level, as `Ulid`. Each stores `Char(n)` of its format's length and carries no generator, so the key writes `id Ulid @id @onCreate(ulid())` and a foreign key writes `authorId Ulid`. On Postgres, a UUID is better stored in the native column: `id Uuid @id @onCreate(uuid(7))`.
168
+
169
+ Values the client generates are written `@onCreate(fn())` and `@onUpdate(fn())`: `id String @id @onCreate(uuid(7))`, `slug String @onCreate(nanoid(12))`, `updatedAt DateTime @onCreate(now()) @onUpdate(now())`. `@default(...)` is a database default only (`now()`, `autoincrement()`, a literal, or `` sql`...` ``); `@default(uuid())` is refused with `PSL_GENERATOR_IN_DEFAULT`. In the TS builder, write `.onCreate(gen.uuid(7))` and `.onUpdate(gen.now())`. Column defaults and generators can sit on one field: `@default(now()) @onCreate(now())`.
170
+
171
+ In the TS builder, an alias is a constant passed as the field, because field builders are immutable: `const Slug = field.column(type.String({ storage: 'varchar', length: 64 }))`, `const UpdatedAt = field.column(type.TimestampString(3)).onCreate(gen.now()).onUpdate(gen.now())`, then `slug: Slug, updatedAt: UpdatedAt.default(now())`. `type.*` has a helper for every PSL type constructor, and the contributed aliases are `type.temporal.CreatedAt()`, `type.temporal.UpdatedAt()` and the identifier aliases such as `type.Ulid()` (`type.sql.Ulid()` on every SQL target), used as `field.column(type.temporal.UpdatedAt())` and `field.column(type.Ulid()).id().onCreate(gen.ulid())`. A definition has no `types` key (`CONTRACT.TYPES_KEY_REMOVED`), and `field.namedType(...)` takes only an enum handle.
172
+
173
+ Note: scalar lists (e.g. `String[]`) are gated on the target's `sql.scalarList` capability — PostgreSQL declares it, so `tags String[]` lowers to an array column (with a generated no-NULL-elements check; write `tags String?[]` for a list whose elements may be null, which gets no such check); SQLite does not, and rejects the field with `PSL_SCALAR_LIST_UNSUPPORTED_TARGET`. Implicit Prisma-ORM many-to-many (list navigation on both sides without a join model) is rejected by the SQL interpreter — declare the join model explicitly and the ORM traverses it for you (`references/queries.md`). Composite/embeddable types (`type Address { ... }` with `address Address` on a model) are supported: the interpreter lowers them to storage value objects, at `storage.namespaces.<ns>.entries.valueObject`, and stores them as `jsonb` columns. See *Workflow — Value objects* below.
143
174
 
144
175
  ## Workflow — Edit a model / field / relation (TS builder)
145
176
 
146
- The concept: same model, different authoring surface. The façade re-exports `defineContract`, `field`, `model`, `rel`, plus the `family`/`target` packs as default exports of `@internal/postgres/family` and `@internal/postgres/target`. Use the callback overload (`defineContract({...}, ({ field, model, rel, type }) => ({...}))`) to get the higher-level helpers (`field.text()`, `field.id.uuidv7String()`, `field.temporal.createdAt()`, `type.sql.String(35)`).
177
+ The concept: same model, different authoring surface. The database package re-exports `defineContract`, `field`, `model`, `rel`, plus the `family`/`target` packs as default exports of `@prisma/orm-postgres/family` and `@prisma/orm-postgres/target`. Use the callback overload (`defineContract({...}, ({ field, model, rel, type, gen }) => ({...}))`) to get the type constructors, type aliases and generator calls (`field.column(type.String())`, `field.column(type.Uuid()).id().onCreate(gen.uuid(7))`, `field.column(type.temporal.CreatedAt())`, `type.sql.Varchar(35)`).
147
178
 
148
179
  ```typescript
149
- import sqlFamily from '@internal/postgres/family';
150
- import { defineContract } from '@internal/postgres/contract-builder';
151
- import postgresPack from '@internal/postgres/target';
180
+ import { defineContract, postgres18, postgresDriver } from '@prisma/orm-postgres/contract-builder';
152
181
 
153
182
  export const contract = defineContract(
154
- {
155
- family: sqlFamily,
156
- target: postgresPack,
157
- },
158
- ({ field, model }) => ({
183
+ { requiredCapabilities: [...postgres18, ...postgresDriver] },
184
+ ({ field, model, gen, type }) => ({
159
185
  models: {
160
186
  User: model('User', {
161
187
  fields: {
162
- id: field.id.uuidv7String(),
163
- email: field.text().unique(),
164
- createdAt: field.temporal.createdAt(),
188
+ id: field.column(type.Uuid()).id().onCreate(gen.uuid(7)),
189
+ email: field.column(type.String()).unique(),
190
+ createdAt: field.column(type.temporal.CreatedAt()),
165
191
  },
166
192
  }).sql({ table: 'app_user' }),
167
193
  },
@@ -169,9 +195,13 @@ export const contract = defineContract(
169
195
  );
170
196
  ```
171
197
 
172
- Then `pnpm prisma contract emit`. The `field.<scalar>()` helpers are only available inside the callback overload; outside the callback only `field.column(...)`, `field.generated(...)`, `field.namedType(...)` exist.
198
+ Then `pnpm prisma contract emit`. Every database package's `contract-builder` entry exports `field` and `gen`. The Postgres, SQLite and MongoDB entries also export `type`. These are the helpers the callback receives, without the ones an extension adds (such as pgvector's `type.pgvector.Vector`); for those, use the callback's helpers. On MySQL and MariaDB, `type` is only available inside the callback overload.
173
199
 
174
- For Mongo, swap every `@internal/postgres/*` import for `@internal/mongo/*`. The Mongo builder also exposes `index` and `valueObject`.
200
+ For Mongo, swap every `@prisma/orm-postgres/*` import for `@prisma/orm-mongo/*`. The Mongo builder also exposes `index` and `valueObject`.
201
+
202
+ Mongo scalar types, as PSL name / TS builder / application type: `String` / `field.scalar(type.String())` / `string`; `Int` / `field.scalar(type.Int())` / `number` (a BSON int); `BigInt` / `field.scalar(type.BigInt())` / `bigint` (a BSON long); `BigInt(as: number)` / `field.scalar(type.BigInt({ as: 'number' }))` / `number` in the safe-integer range (a BSON long); `Float` / `field.scalar(type.Float())` / `number`; `Decimal` / `field.scalar(type.Decimal())` / decimal text as a `string`; `Boolean` / `field.scalar(type.Boolean())` / `boolean`; `DateTime` / `field.scalar(type.DateTime())` / `Date` (an instant, a BSON date); `Date` / `field.scalar(type.Date())` / `string` such as `"2024-02-29"` (a calendar date, a BSON date at midnight UTC); `Time` / `field.scalar(type.Time())` / `string` such as `"09:30:00.000"`; `Duration` / `field.scalar(type.Duration())` / an ISO 8601 duration `string`; `ObjectId` / `field.scalar(type.ObjectId())` / `string`; `Bytes` / `field.scalar(type.Bytes())` / `Uint8Array`; `Json` / `field.scalar(type.Json())` / `JsonValue`; `Bson` / `field.scalar(type.Bson())` / `BsonValue`. `Int`, `BigInt`, `Float`, `Decimal`, `Boolean`, `Bytes`, `String` and `Json` are convenience types: the contract stores the explicit type each chooses, named after the BSON type (`Int32`, `Int64BigInt`, `Int64Number`, `Double`, `Decimal128`, `Bool`, `Binary`, `BsonString`, `PlainJson`), and writing that type directly is the same. `Int64` is a deprecated name of `Int64BigInt` and warns `PSL_DEPRECATED_SCALAR_NAME`; `type.Int64()` no longer exists, so write `type.BigInt()`. `Json` holds a JSON value only, validated as the JSON-representable BSON types (`storage: bson`, its one storage, is not the `Bson` type); `Bson` holds any BSON value, unconstrained by the validator. `DateTime`, `Date` and `Time` take `as: temporal` for `Temporal.Instant`, `Temporal.PlainDate` and `Temporal.PlainTime`, and `DateTime` takes `as: string` for the instant's ISO text. Before Prisma 8's convenience types, MongoDB's `Date` was the instant; write `DateTime` for an instant. The full table, with codec ids and storage types, is [Scalar types](https://github.com/prisma/orm/blob/main/docs/reference/scalar-types.md).
203
+
204
+ Mongo timestamps the ORM fills: in PSL, write `createdAt DateTime @onCreate(now())` (set on create) or `updatedAt DateTime @onCreate(now()) @onUpdate(now())` (set on create and on every update with a non-empty payload), or type the field `temporal.CreatedAt` or `temporal.UpdatedAt`; in TS, use `field.scalar(type.DateTime()).onCreate(gen.now())` or `field.scalar(type.DateTime()).onCreate(gen.now()).onUpdate(gen.now())`. They store a BSON date read back as `Date`, one value per ORM operation, and an explicit value in the write wins. The fields are optional on create. A field with a generated value cannot be optional (`?`), a list, `@id`, or a field of a composite type.
175
205
 
176
206
  ## Workflow — Add an extension-typed scalar (pgvector)
177
207
 
@@ -182,12 +212,12 @@ The concept: an extension contributes a namespace (`pgvector.*`) plus two descri
182
212
  ```typescript
183
213
  import 'dotenv/config';
184
214
  import { definePrismaConfig } from '@prisma/cli-engine';
185
- import pgvector from '@internal/extension-pgvector/control';
186
- import { defineConfig as ormConfig } from '@internal/postgres/config';
215
+ import pgvector from '@prisma/orm-extension-pgvector/control';
216
+ import { defineConfig as ormConfig, postgres18, postgresDriver } from '@prisma/orm-postgres/config';
187
217
 
188
218
  export default definePrismaConfig({
189
219
  orm: ormConfig({
190
- contract: './src/prisma/contract.prisma',
220
+ contract: { path: './src/prisma/contract.prisma', requiredCapabilities: [...postgres18, ...postgresDriver] },
191
221
  extensions: [pgvector],
192
222
  db: { connection: process.env['DATABASE_URL']! },
193
223
  }),
@@ -210,6 +240,28 @@ If you reference `pgvector.*` without registering the descriptor in the config,
210
240
 
211
241
  For canonical worked examples covering single and multi-extension setups, read `examples/prisma-8-demo/prisma.config.ts`, `examples/multi-extension-monorepo/app/prisma.config.ts` and `examples/prisma-8-postgis-demo/prisma.config.ts`.
212
242
 
243
+ ## Workflow — Raw columns (a type no column type covers)
244
+
245
+ The concept: ``Raw(sql`<type>`)`` declares a column whose type Prisma does not model, such as `tsvector`, `ltree`, `circle` or a domain of the user's own. Migrations write the text as given, and `db verify` compares it with the type the database reports, exactly. Values are typed `unknown`, read the same flat and through includes, and write back as read. On Postgres the ORM reads each value as the text the database prints for it. On SQLite a value keeps the shape of its storage class: a number, a string, a `Uint8Array` for a BLOB, or null. The ORM offers no filters or ordering on raw values. Raw columns exist on Postgres and SQLite.
246
+
247
+ ```prisma
248
+ model Category {
249
+ id Int @id
250
+ search Raw(sql`tsvector`)
251
+ area Raw(sql`circle`) @default(sql`'<(0,0),1>'::circle`)
252
+ net Raw(sql`cidr`)?
253
+ tags Raw(sql`"MyTag"[]`)
254
+ }
255
+ ```
256
+
257
+ In the TypeScript builder, use ``field.column(type.Raw(sql`tsvector`))`` in the callback overload, or ``field.column(rawColumn(sql`tsvector`))`` with `rawColumn` from the adapter's column types and `sql` from the contract builder. A quoted string, `Raw("tsvector")`, is refused with ``Expected sql`...`; write sql`tsvector` ``.
258
+
259
+ - Write the type as the database catalog prints it: `integer`, not `int4`; `character varying(10)`, not `varchar(10)`. Another form reports a type mismatch in `db verify`, and the finding names the text to write.
260
+ - A raw column's default is a `sql` expression. A literal default is refused at emit (`` Expected sql`...` ``).
261
+ - The text is one type name: words and double-quoted names separated by single spaces, the first optionally after one schema name and a dot, each optionally followed by parentheses of letters, digits, underscores, commas, spaces and a minus sign before a digit, and at most one trailing `[]`. `geometry(Point,4326)`, `double precision` and `app.email` (a domain whose schema is not on the `search_path`) are fine; quotes of other kinds, `$` and operators are refused.
262
+ - A type whose name needs double quotes is written with them inside the literal: ``Raw(sql`"MyType"`)``.
263
+ - Changing the text changes the column's type: `migration plan` writes `ALTER COLUMN ... TYPE`. If the database has no cast between the two types, name the field with `--convert` and write the conversion. The generated call is `alterColumnType({ ..., type: "text", raw: true })`; keep `raw: true` when editing it, since a raw type is checked as written.
264
+
213
265
  ## Workflow — Polymorphism (`@@discriminator` / `@@base`)
214
266
 
215
267
  The concept (SQL targets): one base model declares the discriminator field; each variant model declares its base + discriminator value. The variant chooses STI vs MTI by **whether it sets `@@map(...)`**: no `@@map` means the variant inherits the base's table (single-table inheritance); `@@map("variant_table")` means the variant gets its own table joined 1:1 by primary key (multi-table inheritance).
@@ -240,7 +292,11 @@ model Feature {
240
292
  }
241
293
  ```
242
294
 
243
- Verify the polymorphism syntax against the interpreter tests if in doubt: `packages/2-sql/2-authoring/contract-psl/test/interpreter.polymorphism.test.ts`.
295
+ An STI variant's relations put their foreign keys on the base table. Its `@@unique`, `@unique` and `@@index` without `where:` are refused, because on the shared table they would also cover the other variants' rows; scope the index to the variant instead, as in ``@@index([severity], unique: true, where: sql`type = 'bug'`)``. Without `where:`, only a plain `@@index` that backs one of the variant's own relations is accepted: the index its foreign key creates anyway, or the one its `index:` argument names. A unique is always refused, so a one-to-one relation from a single-table variant is not supported yet. A variant `@@index` with `where:` becomes a partial index on the base table; before, it was dropped from the contract. A variant relation is refused when another model of the table maps one of its columns without the same relation, or when its column has a `@default`, which every row of the table gets: give the variant's field its own column with `@map`, or remove the default. `@@check` on an STI variant is refused; declare it on the base.
296
+
297
+ A variant's base can be in another namespace: write `@@base(ns.Model, "value")`. Such a variant must set `@@map(...)`, because a variant that shares its base's table has to be in the base's namespace.
298
+
299
+ Verify the polymorphism syntax against the interpreter tests if in doubt: `packages/2-sql-family/2-authoring/contract-psl/test/interpreter.polymorphism.test.ts`.
244
300
 
245
301
  Mongo PSL takes the same `@@discriminator(field)` / `@@base(Base, "value")` attributes (the Mongo interpreter implements both; `examples/mongo-demo/src/contract.prisma` declares `Post` with `@@discriminator(kind)` and `Article` / `Tutorial` variants via `@@base(Post, "article")`). Variants share the base's collection — there is no `@@map` on a Mongo variant, since there is no second table to join. The TS builder's `discriminator` option on the model is the programmatic equivalent.
246
302
 
@@ -248,7 +304,7 @@ Querying the variants is a runtime concern — see `references/queries.md`.
248
304
 
249
305
  ## Workflow — Value objects (composite types)
250
306
 
251
- The concept: `type Foo { ... }` blocks declare value-object shapes. The interpreter lowers them to `valueObjects` in the contract domain and stores them as `jsonb` columns. Nested value-object references are supported.
307
+ The concept: `type Foo { ... }` blocks declare value-object shapes. The interpreter lowers them to storage value objects, at `storage.namespaces.<ns>.entries.valueObject`, and stores them as `jsonb` columns; a domain field refers to one by coordinate. Nested value-object references are supported.
252
308
 
253
309
  ```prisma
254
310
  type Address {
@@ -259,13 +315,15 @@ type Address {
259
315
  }
260
316
 
261
317
  model User {
262
- id String @id @default(uuid())
318
+ id String @id @onCreate(uuid())
263
319
  email String
264
320
  address Address?
265
321
  }
266
322
  ```
267
323
 
268
- Emitted `contract.json` carries `domain.namespaces.<ns>.valueObjects.Address` with its field descriptors, and the `address` column lands as `codecId: "pg/jsonb@1"` / `nativeType: "jsonb"` in `storage`.
324
+ Emitted `contract.json` carries the value object in storage, at `storage.namespaces.<ns>.entries.valueObject.Address` with its field descriptors, and the domain field `address` refers to it by coordinate: `{ "kind": "valueObject", "plane": "storage", "namespaceId": "public", "entityKind": "valueObject", "entityName": "Address" }`. The `address` column lands as `codecId: "pg/jsonb@1"` / `dataType: "pg/jsonb"`. Because the value object is in storage, renaming, adding or removing one of its fields changes the storage hash, and `prisma migration plan` writes a migration for it.
325
+
326
+ On Postgres, a managed table gets a derived check on each value object column, `<table>_<column>_shape_<hash>`: the value must be an object (an array of them for a list) with every required member, each of its JSON type, and no other key. A nullable column also accepts `NULL`. On SQL, a polymorphic base's discriminator column refers to a value set `<Base>.<field>` holding the variants' values, and Postgres derives a check from it, as for an enum.
269
327
 
270
328
  Canonical worked example: `examples/prisma-8-demo/src/prisma/contract.prisma`.
271
329
 
@@ -281,12 +339,18 @@ enum user_type {
281
339
  }
282
340
 
283
341
  model User {
284
- id String @id @default(uuid())
342
+ id String @id @onCreate(uuid())
285
343
  kind user_type
286
344
  }
287
345
  ```
288
346
 
289
- **Waiving enforcement (`@noCheck`).** A field can decline the generated CHECK constraints for its column: bare `@noCheck` waives every kind the column's shape derives; `@noCheck(membership)` and `@noCheck(elementNotNull)` waive one kind (`membership` is the enum value-set check; `elementNotNull` is the no-NULL-elements check every list column gets). The TS authoring equivalent is `.noCheck(...)` on the field builder. Declared types do not change: the field still types as the enum union, and a list still types with non-null elements — once enforcement is waived, runtime values may diverge from what the types claim. That divergence is the author's accepted risk, and it is scoped to the kinds actually waived: waiving `membership` stops the database rejecting out-of-set values, waiving `elementNotNull` stops it rejecting NULL elements. A list that waives only `membership` still rejects NULL elements. `contract infer` emits `@noCheck(elementNotNull)` automatically for list columns whose source database does not carry the generated check.
347
+ **Reading members at runtime (`db.enums`).** `db.enums.<namespace>.<Enum>` on Postgres, and `db.enums.<Enum>` on SQLite and Mongo, holds each member as a query returns it: a `pg/int8@1` member written `Low = "1"` is `1n`, a date or timestamp member is the `Date` or Temporal value its codec reads, and a float member written `"NaN"` is `NaN`. So `db.enums.public.Level.members.Low === row.level` holds wherever `===` applies. `has(value)`, `nameOf(value)` and `ordinalOf(value)` find a value equal to a member: a string, number or bigint must be the member itself, and an object such as a `Date` must be of the member's kind and stored as the member is, so a date equal to a member matches although it is a different object. Text a codec would normalize, such as an upper-case uuid, is no member. Each read of a mutable member, such as a `Date` or a `Uint8Array`, returns a fresh copy, so changing it does not change the enum; a Temporal member is immutable and is the same value on every read. An enum's members are decoded when the enum is first read, so a client builds without `Temporal` even when its contract has a Temporal enum. `contract.d.ts` types each member as that same value. The rule behind this: the value a codec reads from the contract's stored form equals the value a query returns for it. The stored form itself can differ from the text the database prints, such as ISO 8601 for a timestamp.
348
+
349
+ **Codecs an enum cannot use.** An enum compares values with its members, so a codec whose values cannot be compared for equality, or whose values read back never equal a member as the contract stores it, is refused, in TypeScript with `CONTRACT.ENUM_INVALID` and in PSL with `PSL_EXTENSION_INVALID_VALUE` at the `@@type`. The message says why and what to use instead. On Postgres: `pg/json@1`, `pg/jsonb@1`, `pg/bytea@1` and `pg/tsquery@1` (use a text enum). The text date and time codecs read their values in ISO 8601, so an enum can use them.
350
+
351
+ **Mongo enums.** A Mongo contract's collection validator lists each enum's members in their stored JSON forms, so an enum needs a codec whose BSON type JSON holds: string, int, double, bool, object or array, with finite numbers for doubles. PSL and TypeScript contracts derive the same validator. An enum over `mongo/int64@1`, `mongo/date@1` or `mongo/objectId@1` is refused: with `PSL_EXTENSION_INVALID_VALUE` in PSL, and with `CONTRACT.ENUM_INVALID` by `defineContract`.
352
+
353
+ **Generated checks cannot be waived.** On a managed table every enum column gets a membership check, and every list column with non-null elements gets a no-NULL-elements check. A list whose elements may be null is written `String?[]` (TS: `.many({ elementsNullable: true })`) and gets no element check. `contract infer` writes `String?[]` for a list column whose database has no element check, and a Prisma 7 schema's lists are read as `String?[]`.
290
354
 
291
355
  Canonical worked example: `examples/prisma-8-demo/src/prisma/contract.prisma`.
292
356
 
@@ -300,16 +364,16 @@ model Order {
300
364
  total Decimal
301
365
 
302
366
  // name: is a prefix — the physical constraint becomes order_total_positive_<8-hex hash>.
303
- @@check(expression: "total > 0", name: "order_total_positive")
367
+ @@check(expression: sql`total > 0`, name: "order_total_positive")
304
368
  }
305
369
  ```
306
370
 
307
- `expression` is the raw predicate — the text that goes inside `CHECK (...)` — and it is never parsed, so get it right; Prisma 8 does not validate SQL syntax. Exactly one of `name:` or `map:` is required, and they're mutually exclusive:
371
+ `expression` is the raw predicate — the text that goes inside `CHECK (...)`, written as a `sql` literal (a quoted string is refused) — and it is never parsed, so get it right; Prisma 8 does not validate SQL syntax. Exactly one of `name:` or `map:` is required, and they're mutually exclusive:
308
372
 
309
373
  - **`name:`** — declaring a new rule. Prisma 8 picks the physical constraint name and future plans compare by that name, so Postgres's own reprint of your predicate (which rarely matches what you typed byte-for-byte) never causes false drift.
310
374
  - **`map:`** — adopting a rule that already exists. Give the constraint's exact physical name and Prisma 8 compares the predicate byte-for-byte against what's live. This is the form `contract infer` writes for you (see *Workflow — Brownfield introspection* below) when it finds a hand-written check in the database. Every `map:` body warns at emit time (`PN_EXACT_NAME_BODY_COMPARISON`) — the warning fires on the text, not on who wrote it, so the check `contract infer` just wrote warns again on your next `contract emit` too. That is expected, not a defect: the comparison is still sound because both sides are Postgres's own reprint. Prefer `name:` for anything you're authoring fresh: your text and Postgres's reprint of it rarely match character-for-character, and a byte comparison reports that as drift even when both mean exactly the same thing. Reserve `map:` for adopting what's already there, where both sides are the database's own reprint and so do match.
311
375
 
312
- A model can carry any number of `@@check` attributes. The TS builder mirrors this with `check({ expression, name })` / `check({ expression, map })` on a model's `.sql({ checks: [...] })`, next to `index()`.
376
+ A model can carry any number of `@@check` attributes. The TS builder mirrors this with `check({ expression, name })` / `check({ expression, map })` on a model's `.sql({ checks: [...] })`, next to `index()`; `expression` is a `sql` value, as in ``check({ expression: sql`total > 0`, name: 'order_total_positive' })``. The `sql` tag, from the same contract-builder module, may interpolate other `sql` values: ``sql`${owner} AND deleted_at IS NULL` ``.
313
377
 
314
378
  Check constraints need the target's `checkConstraint` capability. Postgres has it; SQLite does not. `@@check` on a SQLite contract is rejected at authoring time; `check()` on a SQLite contract isn't caught until migration DDL is rendered, but either way you get a refusal, never a silently-dropped constraint.
315
379
 
@@ -320,7 +384,7 @@ The concept: wrap models in a `namespace <name> { ... }` block to place them in
320
384
  ```prisma
321
385
  namespace public {
322
386
  model Profile {
323
- id String @id @default(uuid())
387
+ id String @id @onCreate(uuid())
324
388
  username String
325
389
  userId String @unique
326
390
  @@map("profile")
@@ -330,6 +394,46 @@ namespace public {
330
394
 
331
395
  Canonical worked example: `examples/supabase/src/contract.prisma`.
332
396
 
397
+ ## Workflow — Mixins (shared members)
398
+
399
+ The concept: a mixin is a named set of members for one kind of block. Declare it with the block's keyword followed by `mixin`, and include it in a block with `+<Name>`. The emitted contract is the same as if the mixin's members were written at the position of the inclusion.
400
+
401
+ ```prisma
402
+ model mixin Timestamps {
403
+ createdAt DateTime @default(now())
404
+ updatedAt DateTime @onCreate(now()) @onUpdate(now())
405
+ @@index([createdAt])
406
+ }
407
+
408
+ enum mixin BaseRoles {
409
+ ADMIN = "admin"
410
+ USER = "user"
411
+ }
412
+
413
+ model User {
414
+ id Int @id
415
+ +Timestamps
416
+ email String
417
+ }
418
+
419
+ enum Role {
420
+ @@type("pg/text@1")
421
+ +BaseRoles
422
+ GUEST = "guest"
423
+ }
424
+ ```
425
+
426
+ `User` has the fields `id`, `createdAt`, `updatedAt`, `email`, in that order, and the index on `createdAt`. `Role` has the members `ADMIN`, `USER`, `GUEST`.
427
+
428
+ Rules:
429
+
430
+ - **One keyword per mixin.** A `model mixin` can be included only in models, a `type mixin` only in composite types, an `enum mixin` only in enums, and a mixin for a block an extension defines (for example `policy_select mixin`) only in blocks of that keyword.
431
+ - **A member provided twice is an error.** A field name or an enum member that the block already has, from its own body or from another mixin, is reported and the earlier one is kept. Including the same mixin twice in one block is also an error.
432
+ - **A mixin's attributes can name only its own fields.** `@@index([createdAt])` inside `Timestamps` works because `createdAt` is a field of the mixin. An attribute that needs a field of the including model belongs in that model; a model's own attributes can name the fields a mixin provides, as in `@@id([tenantId, id])`.
433
+ - **A mixin cannot include a mixin.**
434
+ - **Names follow namespaces.** A mixin declared in `namespace auth { ... }` is included from another namespace as `+auth.Timestamps`. The types of its fields are looked up from the mixin's namespace, not from the including block's.
435
+ - **A mixin is not a type.** It cannot be used as a field type, and it produces nothing in the contract unless a block includes it.
436
+
333
437
  ## Workflow — Cross-contract foreign keys
334
438
 
335
439
  The concept: a relation field can reference a model in another contract space using the `<space>:<namespace>.<Model>` form. The contract also supports top-level named-type aliases in a `types {}` block, backed by the same bare type-position constructors used by fields. The `@db.X(args)` channel is removed: rewrite `@db.X` as `X` and `@db.X(args)` as `X(args)`; remaining uses fail with an actionable diagnostic naming the replacement.
@@ -341,7 +445,7 @@ types {
341
445
 
342
446
  namespace public {
343
447
  model Profile {
344
- id String @id @default(uuid())
448
+ id String @id @onCreate(uuid())
345
449
  username String
346
450
  userId AuthUserId @unique
347
451
  user supabase:auth.AuthUser @relation(fields: [userId], references: [id], onDelete: Cascade)
@@ -350,7 +454,7 @@ namespace public {
350
454
  }
351
455
  ```
352
456
 
353
- `supabase:auth.AuthUser` means: model `AuthUser` in namespace `auth` of contract space `supabase`. The target space is provided by a registered extension pack (here `@internal/extension-supabase/pack`).
457
+ `supabase:auth.AuthUser` means: model `AuthUser` in namespace `auth` of contract space `supabase`. The target space is provided by a registered extension pack (here `@prisma/orm-extension-supabase/pack`).
354
458
 
355
459
  Canonical worked example: `examples/supabase/src/contract.prisma`.
356
460
 
@@ -369,7 +473,7 @@ model AuditLog {
369
473
 
370
474
  A contract-level default can be set via `defaultControlPolicy` on `prismaContract(path, { defaultControlPolicy })`. See `references/migrations.md` for how control policies affect DDL planning.
371
475
 
372
- ## Workflow — `@internal/extension-supabase`
476
+ ## Workflow — `@prisma/orm-extension-supabase`
373
477
 
374
478
  The concept: the Supabase extension provides the `supabase` contract space (the `auth` / `storage` schemas as `external` tables, plus the platform roles) and its own role-first runtime factory. Its descriptor is the `pack` export, and it goes into the same `extensions` array as any other extension. See `examples/supabase` for the full working pattern.
375
479
 
@@ -377,21 +481,21 @@ The concept: the Supabase extension provides the `supabase` contract space (the
377
481
 
378
482
  ```typescript
379
483
  import { definePrismaConfig } from '@prisma/cli-engine';
380
- import supabasePack from '@internal/extension-supabase/pack';
381
- import { defineConfig as ormConfig } from '@internal/postgres/config';
484
+ import supabasePack from '@prisma/orm-extension-supabase/pack';
485
+ import { defineConfig as ormConfig, postgres18, postgresDriver } from '@prisma/orm-postgres/config';
382
486
 
383
487
  export default definePrismaConfig({
384
488
  orm: ormConfig({
385
- contract: './src/contract.prisma',
489
+ contract: { path: './src/contract.prisma', requiredCapabilities: [...postgres18, ...postgresDriver] },
386
490
  extensions: [supabasePack],
387
491
  migrations: { dir: 'migrations' },
388
492
  }),
389
493
  });
390
494
  ```
391
495
 
392
- `db.ts` does **not** use the stock `postgres()` factory — a Supabase app builds its client with the `supabase()` factory from `@internal/extension-supabase/runtime` (role-first: `asUser(jwt)` / `asAnon()` / `asServiceRole()`, JWT validation, RLS). That runtime — and RLS policy authoring (`policy_select` / `@@rls`) — is covered by **`references/supabase.md`**; load it for anything past the config wiring.
496
+ `db.ts` does **not** use the stock `postgres()` factory — a Supabase app builds its client with the `supabase()` factory from `@prisma/orm-extension-supabase/runtime` (role-first: `asUser(jwt)` / `asAnon()` / `asServiceRole()`, JWT validation, RLS). That runtime — and RLS policy authoring (`policy_select` / `@@rls`) — is covered by **`references/supabase.md`**; load it for anything past the config wiring.
393
497
 
394
- Export subpaths: `@internal/extension-supabase/pack`, `@internal/extension-supabase/runtime`, `@internal/extension-supabase/contract`. Canonical worked example: `examples/supabase`.
498
+ Export subpaths: `@prisma/orm-extension-supabase/pack`, `@prisma/orm-extension-supabase/runtime`, `@prisma/orm-extension-supabase/contract`. Canonical worked example: `examples/supabase`.
395
499
 
396
500
  ## Workflow — Brownfield introspection
397
501
 
@@ -408,26 +512,28 @@ Infer captures indexes at full fidelity — expression, partial (`where:`), uniq
408
512
 
409
513
  1. **Forgetting to re-emit after an edit.** `contract.json` and `contract.d.ts` go stale; downstream typecheck and `migration plan` see the old shape. Re-emit, or install the Vite plugin (`references/build.md`).
410
514
  2. **Editing the emitted artefacts.** `contract.json` and `contract.d.ts` are emitted; edits there round-trip away on the next emit. Edit the source.
411
- 3. **Wrong factory/import path for the TS builder.** `defineContract`, `field`, `model`, `rel` come from `@internal/postgres/contract-builder` (or `@internal/mongo/contract-builder`). Outside the callback overload, the available field constructors are `field.column(...)`, `field.generated(...)`, `field.namedType(...)`.
412
- 4. **Reaching into internal packages from user code.** User-authored files (`prisma.config.ts`, `contract.ts`, `db.ts`, control clients) import only from `@internal/<target>/<subpath>` and `@internal/extension-<name>/<subpath>`. Imports from `@internal/cli/*`, `@internal/family-*`, `@internal/target-*`, `@internal/adapter-*`, `@internal/driver-*`, or `@internal/sql-contract-*` are framework-internal — the façade composes them for you. If a façade subpath you need is missing for your target, see *What Prisma 8 doesn't do yet* and route to `references/feedback.md`. The canonical worked examples are `examples/multi-extension-monorepo/app/prisma.config.ts` and `examples/prisma-8-postgis-demo/prisma.config.ts`.
413
- 5. **Confusing the config `extensions` with the TS builder's `extensions`.** Same packs, two surfaces, one field name but two shapes: `ormConfig({ extensions: [pgvector] })` (array of *control* descriptors from `@internal/extension-<name>/control`) versus `defineContract({ extensions: { pgvector } })` (record of *pack* descriptors from `@internal/extension-<name>/pack`).
515
+ 3. **Wrong factory/import path for the TS builder.** `defineContract`, `field`, `model`, `rel` come from `@prisma/orm-postgres/contract-builder` (or the `contract-builder` entry of the SQLite, MySQL, MariaDB or Mongo package). Every database package's `contract-builder` exports `gen` (`.onCreate(gen.uuid())`). The Postgres, SQLite and Mongo package also export `type` (`field.column(type.TimestamptzTemporal())` on Postgres); on MySQL and MariaDB, outside the callback overload, the available field constructors are `field.column(...)` and `field.namedType(...)`.
516
+ 4. **Reaching into internal packages from user code.** User-authored files (`prisma.config.ts`, `contract.ts`, `db.ts`, control clients) import only from `@prisma/orm-<target>/<subpath>` and `@prisma/orm-extension-<name>/<subpath>`. Imports from the platform packages (`@prisma/orm-framework`, `@prisma/orm-family-*`, `@prisma/orm-target-*`, `@prisma/orm-toolchain`) are framework wiring — the database package composes them for you. The application lists them in `package.json` beside its database package, so it holds one copy of each (a monorepo whose applications are on different Prisma versions can still get two; see [ADR 329](https://github.com/prisma/orm/blob/main/docs/architecture%20docs/adrs/ADR%20329%20-%20An%20application%20lists%20the%20platform%20packages%20and%20our%20packages%20name%20each%20other%20as%20peers.md#consequences)), but user code never imports them. If a database package subpath you need is missing for your target, see *What Prisma 8 doesn't do yet* and route to `references/feedback.md`. The canonical worked examples are `examples/multi-extension-monorepo/app/prisma.config.ts` and `examples/prisma-8-postgis-demo/prisma.config.ts`.
517
+ 5. **Confusing the config `extensions` with the TS builder's `extensions`.** Same packs, two surfaces, one field name but two shapes: `ormConfig({ extensions: [pgvector] })` (array of *control* descriptors from `@prisma/orm-extension-<name>/control`) versus `defineContract({ extensions: { pgvector } })` (record of *pack* descriptors from `@prisma/orm-extension-<name>/pack`).
414
518
  6. **Writing a flat `prisma.config.ts`.** `export default defineConfig({ contract, extensions })` from the target config alone is the pre-rc.4 shape and fails with `CONFIG.VERSION_MARKER_MISSING`. Wrap it: `definePrismaConfig({ orm: ormConfig({...}) })`.
415
- 7. **Renaming a field and expecting the planner to detect it.** Prisma 8 has no in-contract rename hint; the planner sees a destructive drop+add. Hand-edit `migration.ts` after `migration plan` (see `references/migrations.md`), or use the keep-then-drop two-migration pattern.
519
+ 7. **Renaming a model or field and expecting the planner to detect it.** The contract does not record renames, so the planner sees a destructive drop+add. State the rename on the command line with `--rename old:new` on `migration plan` or `db update` (see `references/migrations.md`); the planner then renames instead of dropping. Do not invent a rename attribute in the contract source.
520
+ 8. **Quoting a type-constructor argument.** A type constructor's argument is a value, read as an attribute argument is. Write a length, precision or scale as a plain whole number: `Varchar(255)`, `NumericString(10, 2)`, `String(storage: varchar, length: 255)`. `Varchar("255")` is refused with `Expected a number; write 255`, and on Postgres `Varchar(255.0)` is refused too, because a number with a fraction is not a 32-bit integer.
416
521
 
417
522
  ## What Prisma 8 doesn't do yet
418
523
 
419
- - **In-contract rename hint.** No `@@rename(old: ..., new: ...)` or similar. Use the workarounds in *Common Pitfalls* #7. To request first-class rename, file via `references/feedback.md`.
420
- - **Model validations.** No declarative `@validates(...)` surface. Validate in application code (arktype). To request declarative validations in the contract, file via `references/feedback.md`.
421
- - **Lifecycle callbacks** (`beforeSave`, `afterCreate`, etc.). Not supported. Use middleware (`references/runtime.md`) or app code. To request lifecycle callbacks, file via `references/feedback.md`.
422
- - **Soft delete / `paranoid: true`.** No built-in soft-delete column. Add a nullable `deletedAt DateTime?` and filter explicitly in queries (or in middleware). To request built-in soft delete, file via `references/feedback.md`.
524
+ - **In-contract rename hint.** No `@@rename(old: ..., new: ...)` or similar; renames are stated with `--rename` on the command line, as in *Common Pitfalls* #7.
525
+ - **Model validations.** No declarative `@validates(...)` surface. Validate in application code (arktype). The maintainers decided it stays out of the core; an extension may provide it (prisma/orm ADR 293).
526
+ - **Lifecycle callbacks** (`beforeSave`, `afterCreate`, etc.). Not supported. Use middleware (`references/runtime.md`) or app code. The maintainers decided it stays out of the core; an extension may provide it (prisma/orm ADR 293).
527
+ - **Soft delete / `paranoid: true`.** No built-in soft-delete column. Add a nullable `deletedAt DateTime?` and filter explicitly in queries (or in middleware). The maintainers decided it stays out of the core; an extension may provide it (prisma/orm ADR 293).
423
528
  - **Scopes / default filters.** No ActiveRecord-style scopes. Compose query helpers yourself. To request scopes, file via `references/feedback.md`.
529
+ - **Derived back-references.** A model has a relation back only when it declares the field itself (`posts Post[]`); nothing adds it for you, and it is optional. The maintainers decided this (prisma/orm ADR 319). `prisma contract infer` writes both sides when it reads an existing database.
424
530
  - **Implicit Prisma-ORM many-to-many.** List navigation on both sides without an explicit join model is rejected. Author the join model explicitly. To request implicit M2M, file via `references/feedback.md`.
425
531
 
426
532
  ## Reference
427
533
 
428
534
  - Run `pnpm prisma contract --help` for the live command surface.
429
- - PSL feature surface and what the interpreter accepts: `packages/2-sql/2-authoring/contract-psl/README.md`.
430
- - TS builder surface and the callback-helper vocabulary: `packages/2-sql/2-authoring/contract-ts/README.md`.
535
+ - PSL feature surface and what the interpreter accepts: `packages/2-sql-family/2-authoring/contract-psl/README.md`.
536
+ - TS builder surface and the callback-helper vocabulary: `packages/2-sql-family/2-authoring/contract-ts/README.md`.
431
537
  - Layouts (where `contract.prisma`, `contract.json`, `contract.d.ts`, and `migrations/` live):
432
538
  - **App layout** (`src/prisma/...` + `migrations/app/...`) — what `examples/prisma-8-demo` demonstrates; the canonical shape consuming applications use.
433
539
  - **Contract-space-package layout** (`src/contract.{prisma,ts}` directly, `migrations/<timestamp>_<slug>/` without a space-id segment) — for extensions and aggregate-root packages, documented in `.cursor/rules/contract-space-package-layout.mdc` and ADR 212.
@@ -435,12 +541,12 @@ Infer captures indexes at full fidelity — expression, partial (`where:`), uniq
435
541
  ## Checklist
436
542
 
437
543
  - [ ] Read `prisma.config.ts` and identified the contract source (path string ending in `.prisma` or `.ts`) and the installed `extensions: [...]`.
438
- - [ ] All user-authored imports resolve to `@internal/<target>/<subpath>` (e.g. `@internal/postgres/config`) or `@internal/extension-<name>/<subpath>`. No imports from `@internal/cli/*`, `@internal/family-*`, `@internal/target-*`, `@internal/adapter-*`, `@internal/driver-*`, or `@internal/sql-contract-*` in user files.
544
+ - [ ] Every Prisma ORM import in a user-authored file resolves to `@prisma/orm-<target>/<subpath>` (e.g. `@prisma/orm-postgres/config`) or to `@prisma/orm-extension-<name>` or one of its subpaths, apart from `definePrismaConfig` in `prisma.config.ts`, which comes from `@prisma/cli-engine`. No imports from `@prisma/orm-framework`, `@prisma/orm-family-*`, `@prisma/orm-target-*` or `@prisma/orm-toolchain` in user files.
439
545
  - [ ] Edited the contract source (`contract.prisma` or `contract.ts`), not an emitted artefact.
440
- - [ ] For new extension namespaces: added the package, imported its control descriptor (`@internal/extension-<name>/control`), added it to `extensions: [...]` in `ormConfig({...})` (and the matching pack descriptor to `defineContract({extensions: {...}})` if using the TS builder).
546
+ - [ ] For new extension namespaces: added the package, imported its control descriptor (`@prisma/orm-extension-<name>/control`, or `/pack` for a package with no `/control` entry, such as Supabase), added it to `extensions: [...]` in `ormConfig({...})` (and the matching pack descriptor to `defineContract({extensions: {...}})` if using the TS builder).
441
547
  - [ ] `prisma.config.ts` is the envelope form — `definePrismaConfig({ orm: ormConfig({...}) })` — not a flat `defineConfig({...})`.
442
- - [ ] For renames: hand-edited `migration.ts` after `migration plan` (or used the keep-then-drop two-migration pattern) — Prisma 8 has no rename hint today.
548
+ - [ ] For renames: passed `--rename old:new` to `migration plan` or `db update` (or hand-edited `migration.ts` where statements do not cover the rename).
443
549
  - [ ] Ran `pnpm prisma contract emit` after the edit (or let the Vite plugin re-emit on save).
444
550
  - [ ] Confirmed `contract.json` and `contract.d.ts` updated next to the source.
445
551
  - [ ] Did **not** hand-edit `contract.json` / `contract.d.ts`.
446
- - [ ] Did **not** confabulate a missing feature (validations, callbacks, soft delete, scopes, in-contract rename hint) — referred the user to *What Prisma 8 doesn't do yet* + `references/feedback.md`.
552
+ - [ ] Did **not** confabulate a missing feature (validations, callbacks, soft delete, scopes, a rename attribute in the contract source) — referred the user to *What Prisma 8 doesn't do yet* + `references/feedback.md`.