@prisma/orm-mysql 0.0.0-stage → 8.0.0-rc.21-dev.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +44 -2
- package/dist/adapter.d.mts +1 -0
- package/dist/adapter.mjs +2 -0
- package/dist/adapter__adapter.d.mts +1 -0
- package/dist/adapter__adapter.mjs +2 -0
- package/dist/adapter__codec-types.d.mts +1 -0
- package/dist/adapter__codec-types.mjs +2 -0
- package/dist/adapter__control.d.mts +3 -0
- package/dist/adapter__control.mjs +3 -0
- package/dist/adapter__runtime.d.mts +3 -0
- package/dist/adapter__runtime.mjs +3 -0
- package/dist/builder.d.mts +1 -0
- package/dist/builder.mjs +2 -0
- package/dist/builder__runtime.d.mts +1 -0
- package/dist/builder__runtime.mjs +2 -0
- package/dist/builder__types.d.mts +1 -0
- package/dist/builder__types.mjs +2 -0
- package/dist/components.d.mts +1 -0
- package/dist/components.mjs +2 -0
- package/dist/components__authoring.d.mts +1 -0
- package/dist/components__authoring.mjs +2 -0
- package/dist/components__codec.d.mts +1 -0
- package/dist/components__codec.mjs +2 -0
- package/dist/components__components.d.mts +1 -0
- package/dist/components__components.mjs +2 -0
- package/dist/components__control.d.mts +1 -0
- package/dist/components__control.mjs +2 -0
- package/dist/components__emission.d.mts +1 -0
- package/dist/components__emission.mjs +2 -0
- package/dist/components__execution.d.mts +1 -0
- package/dist/components__execution.mjs +2 -0
- package/dist/components__ir.d.mts +1 -0
- package/dist/components__ir.mjs +2 -0
- package/dist/components__psl-ast.d.mts +1 -0
- package/dist/components__psl-ast.mjs +2 -0
- package/dist/components__runtime.d.mts +1 -0
- package/dist/components__runtime.mjs +2 -0
- package/dist/components__utils.d.mts +1 -0
- package/dist/components__utils.mjs +2 -0
- package/dist/config.d.mts +22 -0
- package/dist/config.d.mts.map +1 -0
- package/dist/config.mjs +41 -0
- package/dist/config.mjs.map +1 -0
- package/dist/contract-builder.d.mts +192 -0
- package/dist/contract-builder.d.mts.map +1 -0
- package/dist/contract-builder.mjs +37 -0
- package/dist/contract-builder.mjs.map +1 -0
- package/dist/contract.d.mts +1 -0
- package/dist/contract.mjs +2 -0
- package/dist/contract__apply-specifier-default-control-policy.d.mts +1 -0
- package/dist/contract__apply-specifier-default-control-policy.mjs +2 -0
- package/dist/contract__contract-validation-error.d.mts +1 -0
- package/dist/contract__contract-validation-error.mjs +2 -0
- package/dist/contract__default-namespace.d.mts +1 -0
- package/dist/contract__default-namespace.mjs +2 -0
- package/dist/contract__enum-accessor.d.mts +1 -0
- package/dist/contract__enum-accessor.mjs +2 -0
- package/dist/contract__hashing-utils.d.mts +1 -0
- package/dist/contract__hashing-utils.mjs +2 -0
- package/dist/contract__hashing.d.mts +1 -0
- package/dist/contract__hashing.mjs +2 -0
- package/dist/contract__is-plain-record.d.mts +1 -0
- package/dist/contract__is-plain-record.mjs +2 -0
- package/dist/contract__resolve-domain-model.d.mts +1 -0
- package/dist/contract__resolve-domain-model.mjs +2 -0
- package/dist/contract__types.d.mts +1 -0
- package/dist/contract__types.mjs +2 -0
- package/dist/contract__validate-domain.d.mts +1 -0
- package/dist/contract__validate-domain.mjs +2 -0
- package/dist/contract__validate-once.d.mts +1 -0
- package/dist/contract__validate-once.mjs +2 -0
- package/dist/contract__validate-storage.d.mts +1 -0
- package/dist/contract__validate-storage.mjs +2 -0
- package/dist/control.d.mts +12 -0
- package/dist/control.d.mts.map +1 -0
- package/dist/control.mjs +22 -0
- package/dist/control.mjs.map +1 -0
- package/dist/driver.d.mts +1 -0
- package/dist/driver.mjs +2 -0
- package/dist/driver__control.d.mts +3 -0
- package/dist/driver__control.mjs +3 -0
- package/dist/driver__runtime.d.mts +3 -0
- package/dist/driver__runtime.mjs +3 -0
- package/dist/family-contract.d.mts +1 -0
- package/dist/family-contract.mjs +2 -0
- package/dist/family-contract__authored-check-naming.d.mts +1 -0
- package/dist/family-contract__authored-check-naming.mjs +2 -0
- package/dist/family-contract__canonicalization-hooks.d.mts +1 -0
- package/dist/family-contract__canonicalization-hooks.mjs +2 -0
- package/dist/family-contract__check-expressions.d.mts +1 -0
- package/dist/family-contract__check-expressions.mjs +2 -0
- package/dist/family-contract__codec-json-type.d.mts +1 -0
- package/dist/family-contract__codec-json-type.mjs +2 -0
- package/dist/family-contract__contract-view.d.mts +1 -0
- package/dist/family-contract__contract-view.mjs +2 -0
- package/dist/family-contract__data-type-support.d.mts +1 -0
- package/dist/family-contract__data-type-support.mjs +2 -0
- package/dist/family-contract__data-type.d.mts +1 -0
- package/dist/family-contract__data-type.mjs +2 -0
- package/dist/family-contract__entity-handle-lowering-hook.d.mts +1 -0
- package/dist/family-contract__entity-handle-lowering-hook.mjs +2 -0
- package/dist/family-contract__entity-kinds.d.mts +1 -0
- package/dist/family-contract__entity-kinds.mjs +2 -0
- package/dist/family-contract__factories.d.mts +1 -0
- package/dist/family-contract__factories.mjs +2 -0
- package/dist/family-contract__foreign-key-materialization.d.mts +1 -0
- package/dist/family-contract__foreign-key-materialization.mjs +2 -0
- package/dist/family-contract__generated-id-column-aliases.d.mts +1 -0
- package/dist/family-contract__generated-id-column-aliases.mjs +2 -0
- package/dist/family-contract__index-naming.d.mts +1 -0
- package/dist/family-contract__index-naming.mjs +2 -0
- package/dist/family-contract__index-type-validation.d.mts +1 -0
- package/dist/family-contract__index-type-validation.mjs +2 -0
- package/dist/family-contract__index-types.d.mts +1 -0
- package/dist/family-contract__index-types.mjs +2 -0
- package/dist/family-contract__referential-action-sql.d.mts +1 -0
- package/dist/family-contract__referential-action-sql.mjs +2 -0
- package/dist/family-contract__resolve-storage-table.d.mts +1 -0
- package/dist/family-contract__resolve-storage-table.mjs +2 -0
- package/dist/family-contract__sql-expression.d.mts +1 -0
- package/dist/family-contract__sql-expression.mjs +2 -0
- package/dist/family-contract__types.d.mts +1 -0
- package/dist/family-contract__types.mjs +2 -0
- package/dist/family-contract__validators.d.mts +1 -0
- package/dist/family-contract__validators.mjs +2 -0
- package/dist/family-contract__value-set-derivation-hook.d.mts +1 -0
- package/dist/family-contract__value-set-derivation-hook.mjs +2 -0
- package/dist/family-runtime.d.mts +1 -0
- package/dist/family-runtime.mjs +2 -0
- package/dist/family-runtime__internal__prepared-query.d.mts +1 -0
- package/dist/family-runtime__internal__prepared-query.mjs +2 -0
- package/dist/family__control-adapter.d.mts +1 -0
- package/dist/family__control-adapter.mjs +2 -0
- package/dist/family__control.d.mts +3 -0
- package/dist/family__control.mjs +3 -0
- package/dist/family__diff.d.mts +1 -0
- package/dist/family__diff.mjs +2 -0
- package/dist/family__ir.d.mts +1 -0
- package/dist/family__ir.mjs +2 -0
- package/dist/family__migration.d.mts +1 -0
- package/dist/family__migration.mjs +2 -0
- package/dist/family__pack.d.mts +3 -0
- package/dist/family__pack.mjs +3 -0
- package/dist/family__psl-build.d.mts +1 -0
- package/dist/family__psl-build.mjs +2 -0
- package/dist/family__psl-infer.d.mts +1 -0
- package/dist/family__psl-infer.mjs +2 -0
- package/dist/family__runtime.d.mts +3 -0
- package/dist/family__runtime.mjs +3 -0
- package/dist/family__verify.d.mts +1 -0
- package/dist/family__verify.mjs +2 -0
- package/dist/migration-tools__aggregate.d.mts +1 -0
- package/dist/migration-tools__aggregate.mjs +2 -0
- package/dist/migration-tools__contract-snapshot-store.d.mts +1 -0
- package/dist/migration-tools__contract-snapshot-store.mjs +2 -0
- package/dist/migration-tools__hash.d.mts +1 -0
- package/dist/migration-tools__hash.mjs +2 -0
- package/dist/migration-tools__io.d.mts +1 -0
- package/dist/migration-tools__io.mjs +2 -0
- package/dist/migration-tools__spaces.d.mts +1 -0
- package/dist/migration-tools__spaces.mjs +2 -0
- package/dist/migration.d.mts +1 -0
- package/dist/migration.mjs +2 -0
- package/dist/mysql-static-Dv4HuJDi-CoURZL0Y.mjs +83 -0
- package/dist/mysql-static-Dv4HuJDi-CoURZL0Y.mjs.map +1 -0
- package/dist/mysql-uiFioAtk-BuXtMcWO.d.mts +100 -0
- package/dist/mysql-uiFioAtk-BuXtMcWO.d.mts.map +1 -0
- package/dist/orm-client.d.mts +1 -0
- package/dist/orm-client.mjs +2 -0
- package/dist/relational-core.d.mts +1 -0
- package/dist/relational-core.mjs +2 -0
- package/dist/relational-core__aggregate-descriptor-registry.d.mts +1 -0
- package/dist/relational-core__aggregate-descriptor-registry.mjs +2 -0
- package/dist/relational-core__ast.d.mts +1 -0
- package/dist/relational-core__ast.mjs +2 -0
- package/dist/relational-core__codec-descriptor-registry.d.mts +1 -0
- package/dist/relational-core__codec-descriptor-registry.mjs +2 -0
- package/dist/relational-core__collection-methods.d.mts +1 -0
- package/dist/relational-core__collection-methods.mjs +2 -0
- package/dist/relational-core__contract-free.d.mts +1 -0
- package/dist/relational-core__contract-free.mjs +2 -0
- package/dist/relational-core__expression.d.mts +1 -0
- package/dist/relational-core__expression.mjs +2 -0
- package/dist/relational-core__functions.d.mts +1 -0
- package/dist/relational-core__functions.mjs +2 -0
- package/dist/relational-core__index-reference.d.mts +1 -0
- package/dist/relational-core__index-reference.mjs +2 -0
- package/dist/relational-core__middleware.d.mts +1 -0
- package/dist/relational-core__middleware.mjs +2 -0
- package/dist/relational-core__plan.d.mts +1 -0
- package/dist/relational-core__plan.mjs +2 -0
- package/dist/relational-core__query-lane-context.d.mts +1 -0
- package/dist/relational-core__query-lane-context.mjs +2 -0
- package/dist/relational-core__types.d.mts +1 -0
- package/dist/relational-core__types.mjs +2 -0
- package/dist/runtime.d.mts +24 -0
- package/dist/runtime.d.mts.map +1 -0
- package/dist/runtime.mjs +266 -0
- package/dist/runtime.mjs.map +1 -0
- package/dist/schema-ir__types.d.mts +1 -0
- package/dist/schema-ir__types.mjs +2 -0
- package/dist/static.d.mts +25 -0
- package/dist/static.d.mts.map +1 -0
- package/dist/static.mjs +2 -0
- package/dist/target__codec-descriptor.d.mts +1 -0
- package/dist/target__codec-descriptor.mjs +2 -0
- package/dist/target__codec-ids.d.mts +1 -0
- package/dist/target__codec-ids.mjs +2 -0
- package/dist/target__codec-types.d.mts +1 -0
- package/dist/target__codec-types.mjs +2 -0
- package/dist/target__codecs.d.mts +1 -0
- package/dist/target__codecs.mjs +2 -0
- package/dist/target__contract-free.d.mts +1 -0
- package/dist/target__contract-free.mjs +2 -0
- package/dist/target__control-tables.d.mts +1 -0
- package/dist/target__control-tables.mjs +2 -0
- package/dist/target__control.d.mts +3 -0
- package/dist/target__control.mjs +3 -0
- package/dist/target__data-types.d.mts +1 -0
- package/dist/target__data-types.mjs +2 -0
- package/dist/target__ddl.d.mts +1 -0
- package/dist/target__ddl.mjs +2 -0
- package/dist/target__default-normalizer.d.mts +1 -0
- package/dist/target__default-normalizer.mjs +2 -0
- package/dist/target__errors.d.mts +1 -0
- package/dist/target__errors.mjs +2 -0
- package/dist/target__marker-lock.d.mts +1 -0
- package/dist/target__marker-lock.mjs +2 -0
- package/dist/target__migration.d.mts +1 -0
- package/dist/target__migration.mjs +2 -0
- package/dist/target__pack.d.mts +3 -0
- package/dist/target__pack.mjs +3 -0
- package/dist/target__runtime.d.mts +3 -0
- package/dist/target__runtime.mjs +3 -0
- package/dist/target__sql-utils.d.mts +1 -0
- package/dist/target__sql-utils.mjs +2 -0
- package/dist/utils.d.mts +1 -0
- package/dist/utils.mjs +2 -0
- package/dist/utils__abortable.d.mts +1 -0
- package/dist/utils__abortable.mjs +2 -0
- package/dist/utils__array-equal.d.mts +1 -0
- package/dist/utils__array-equal.mjs +2 -0
- package/dist/utils__assertions.d.mts +1 -0
- package/dist/utils__assertions.mjs +2 -0
- package/dist/utils__canonical-stringify.d.mts +1 -0
- package/dist/utils__canonical-stringify.mjs +2 -0
- package/dist/utils__casts.d.mts +1 -0
- package/dist/utils__casts.mjs +2 -0
- package/dist/utils__defined.d.mts +1 -0
- package/dist/utils__defined.mjs +2 -0
- package/dist/utils__hash-content.d.mts +1 -0
- package/dist/utils__hash-content.mjs +2 -0
- package/dist/utils__internal-error.d.mts +1 -0
- package/dist/utils__internal-error.mjs +2 -0
- package/dist/utils__json.d.mts +1 -0
- package/dist/utils__json.mjs +2 -0
- package/dist/utils__promise.d.mts +1 -0
- package/dist/utils__promise.mjs +2 -0
- package/dist/utils__redact-db-url.d.mts +1 -0
- package/dist/utils__redact-db-url.mjs +2 -0
- package/dist/utils__result.d.mts +1 -0
- package/dist/utils__result.mjs +2 -0
- package/dist/utils__simplify-deep.d.mts +1 -0
- package/dist/utils__simplify-deep.mjs +2 -0
- package/dist/utils__structured-error.d.mts +1 -0
- package/dist/utils__structured-error.mjs +2 -0
- package/dist/utils__suppress-idle-connection-errors.d.mts +1 -0
- package/dist/utils__suppress-idle-connection-errors.mjs +2 -0
- package/dist/utils__text.d.mts +1 -0
- package/dist/utils__text.mjs +2 -0
- package/dist/utils__types.d.mts +1 -0
- package/dist/utils__types.mjs +2 -0
- package/dist/vite-plugin-contract-emit.d.mts +1 -0
- package/dist/vite-plugin-contract-emit.mjs +2 -0
- package/package.json +175 -3
- package/skills/prisma-8/SKILL.md +100 -0
- package/skills/prisma-8/references/build.md +142 -0
- package/skills/prisma-8/references/contract.md +548 -0
- package/skills/prisma-8/references/debug.md +150 -0
- package/skills/prisma-8/references/feedback.md +251 -0
- package/skills/prisma-8/references/migration-model.md +179 -0
- package/skills/prisma-8/references/migration-review.md +211 -0
- package/skills/prisma-8/references/migrations.md +622 -0
- package/skills/prisma-8/references/queries-mongo.md +238 -0
- package/skills/prisma-8/references/queries-postgres.md +710 -0
- package/skills/prisma-8/references/queries.md +253 -0
- package/skills/prisma-8/references/quickstart.md +317 -0
- package/skills/prisma-8/references/runtime.md +463 -0
- package/skills/prisma-8/references/supabase.md +234 -0
- package/skills/prisma-8/references/upgrade-app.md +102 -0
- package/skills/prisma-8/references/upgrade-extension.md +108 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.10-to-0.11/instructions.md +56 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.11-to-0.12/instructions.md +381 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.11-to-0.12/re-emit-closed-mongo-contracts.ts +202 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.11-to-0.12/re-emit-domain-namespaced-contracts.ts +201 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.11-to-0.12/re-emit-postgres-public-default.ts +198 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.11-to-0.12/strip-migration-labels-hints.ts +340 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.12-to-0.13/instructions.md +339 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.12-to-0.13/re-emit-mti-variant-link-columns.ts +229 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.13-to-0.14/instructions.md +543 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.13-to-0.14/migration-op-factories-to-methods.ts +290 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.13-to-0.14/uuid-preset-rename.ts +43 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.14-to-0.15/instructions.md +359 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.15-to-0.16/instructions.md +173 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.16-to-0.17/instructions.md +805 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.16-to-0.17/strip-sha256-hash-prefixes.ts +382 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.17-to-8.0.0-rc.1/instructions.md +72 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.7-to-0.8/instructions.md +8 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.8-to-0.9/instructions.md +36 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.8-to-0.9/strip-inline-contracts.ts +226 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.9-to-0.10/instructions.md +86 -0
- package/skills/prisma-8/upgrading/app/upgrades/0.9-to-0.10/stamp-storage-types-kind.ts +360 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.1-to-8.0.0-rc.2/instructions.md +588 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.10-to-8.0.0-rc.11/instructions.md +34 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/instructions.md +639 -0
- 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
- 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
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/instructions.md +332 -0
- 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
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.13-to-8.0.0-rc.14/instructions.md +489 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.14-to-8.0.0-rc.15/instructions.md +1368 -0
- 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
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.15-to-8.0.0-rc.16/instructions.md +108 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.16-to-8.0.0-rc.17/instructions.md +755 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.17-to-8.0.0-rc.18/instructions.md +973 -0
- 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
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/instructions.md +1862 -0
- 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
- 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
- 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
- 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
- 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
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/instructions.md +513 -0
- 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
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.2-to-8.0.0-rc.3/instructions.md +5 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.20-to-8.0.0-rc.21/instructions.md +802 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.3-to-8.0.0-rc.4/instructions.md +158 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.4-to-8.0.0-rc.5/instructions.md +42 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.5-to-8.0.0-rc.6/instructions.md +157 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.6-to-8.0.0-rc.7/instructions.md +33 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.7-to-8.0.0-rc.8/instructions.md +36 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.8-to-8.0.0-rc.9/instructions.md +63 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.9-to-8.0.0-rc.10/instructions.md +84 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.10-to-0.11/instructions.md +276 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.11-to-0.12/instructions.md +738 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.11-to-0.12/migrate-contract-testing-imports.ts +97 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.11-to-0.12/regenerate-extension-public-baseline.ts +223 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.11-to-0.12/strip-migration-labels-hints.ts +340 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.12-to-0.13/instructions.md +266 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.13-to-0.14/instructions.md +522 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.13-to-0.14/migration-op-factories-to-methods.ts +290 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.13-to-0.14/uuid-preset-rename.ts +43 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.14-to-0.15/instructions.md +803 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.15-to-0.16/instructions.md +219 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.16-to-0.17/instructions.md +731 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.16-to-0.17/strip-sha256-hash-prefixes.ts +382 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.17-to-8.0.0-rc.1/instructions.md +194 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.7-to-0.8/instructions.md +8 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.8-to-0.9/instructions.md +57 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.8-to-0.9/strip-inline-contracts.ts +226 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.9-to-0.10/instructions.md +150 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.9-to-0.10/stamp-storage-types-kind.ts +360 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.1-to-8.0.0-rc.2/instructions.md +746 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.10-to-8.0.0-rc.11/instructions.md +34 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/instructions.md +857 -0
- 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
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/instructions.md +504 -0
- 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
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.13-to-8.0.0-rc.14/instructions.md +143 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.14-to-8.0.0-rc.15/instructions.md +2168 -0
- 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
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.15-to-8.0.0-rc.16/instructions.md +223 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.16-to-8.0.0-rc.17/instructions.md +583 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.17-to-8.0.0-rc.18/instructions.md +1008 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/instructions.md +2186 -0
- 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
- 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
- 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
- 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
- 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
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/instructions.md +381 -0
- 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
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.2-to-8.0.0-rc.3/instructions.md +5 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.20-to-8.0.0-rc.21/instructions.md +570 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.3-to-8.0.0-rc.4/instructions.md +137 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.4-to-8.0.0-rc.5/instructions.md +129 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.5-to-8.0.0-rc.6/instructions.md +102 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.6-to-8.0.0-rc.7/instructions.md +33 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.7-to-8.0.0-rc.8/instructions.md +35 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.8-to-8.0.0-rc.9/instructions.md +86 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.9-to-8.0.0-rc.10/instructions.md +63 -0
package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/instructions.md
ADDED
|
@@ -0,0 +1,2186 @@
|
|
|
1
|
+
---
|
|
2
|
+
from: "8.0.0-rc.18"
|
|
3
|
+
to: "8.0.0-rc.19"
|
|
4
|
+
changes:
|
|
5
|
+
- id: client-takes-contract-value
|
|
6
|
+
summary: |
|
|
7
|
+
Every client and static entry takes the contract only as a value, `{ contract }`. The `contractJson` option is removed, so `postgres<Contract>({ contractJson, url })` no longer compiles, and the client infers its contract type from the value, so the call needs no type argument. Turn the emitted JSON into a typed value once with `contractFromJson<Contract>(contractJson)` from the facade's `/static` entry (`@prisma/orm-postgres/static`, `@prisma/orm-sqlite/static`, `@prisma/orm-mongo/static`; Supabase uses the Postgres one), export it from the module that creates the client, and pass `{ contract }`. This applies to `postgres()`, `postgresServerless()`, `sqlite()`, `supabase()`, `mongo()`, `postgresStatic()`, `sqliteStatic()`, `mongoStatic()` and `mongoQuery()`. Extension packages that build a client, static entry or `mongoQuery` in their code, examples or tests move the same way. The colocated script moves source files; move test files by hand.
|
|
8
|
+
detection:
|
|
9
|
+
glob: "**/*.{ts,tsx,mts,cts}"
|
|
10
|
+
matches:
|
|
11
|
+
- '(?<![\w$.])(?:postgres|postgresServerless|sqlite|supabase|mongo|postgresStatic|sqliteStatic|mongoStatic|mongoQuery)(?:<[^<>()]*(?:<[^<>()]*>[^<>()]*)*>)?\(\s*\{(?:(?:[^{}]|\{[^{}]*\})*?,)?\s*contractJson\s*[,}:]'
|
|
12
|
+
- '(?<![\s\S])(?:(?!import\s+[\w$]+\s*(?:,\s*\{[^{}]*\}\s*)?from\s*[''"]@prisma/orm-(?:(?:postgres|sqlite|mongo)/(?:runtime|serverless|static|query-builder)|extension-supabase/runtime)[''"])[\s\S])*import\s+([\w$]+)\s*(?:,\s*\{[^{}]*\}\s*)?from\s*[''"]@prisma/orm-(?:(?:postgres|sqlite|mongo)/(?:runtime|serverless|static|query-builder)|extension-supabase/runtime)[''"][\s\S]*(?<![\w$.])\1(?:<[^<>()]*(?:<[^<>()]*>[^<>()]*)*>)?\(\s*\{(?:(?:[^{}]|\{[^{}]*\})*?,)?\s*contractJson\s*[,}:]'
|
|
13
|
+
- '(?<![\s\S])(?:(?!import\s*(?:[\w$]+\s*,\s*)?\{[^{}]*\b(?:default|supabase|mongoQuery|postgresStatic|sqliteStatic|mongoStatic)\s+as\s+[\w$]+[^{}]*\}\s*from\s*[''"]@prisma/orm-(?:(?:postgres|sqlite|mongo)/(?:runtime|serverless|static|query-builder)|extension-supabase/runtime)[''"])[\s\S])*import\s*(?:[\w$]+\s*,\s*)?\{[^{}]*\b(?:default|supabase|mongoQuery|postgresStatic|sqliteStatic|mongoStatic)\s+as\s+([\w$]+)[^{}]*\}\s*from\s*[''"]@prisma/orm-(?:(?:postgres|sqlite|mongo)/(?:runtime|serverless|static|query-builder)|extension-supabase/runtime)[''"][\s\S]*(?<![\w$.])\1(?:<[^<>()]*(?:<[^<>()]*>[^<>()]*)*>)?\(\s*\{(?:(?:[^{}]|\{[^{}]*\})*?,)?\s*contractJson\s*[,}:]'
|
|
14
|
+
script: ./scripts/client-takes-contract-value/contract-from-json.ts
|
|
15
|
+
- id: collections-on-the-client
|
|
16
|
+
summary: |
|
|
17
|
+
Not a breaking change. Every SQL client takes your custom collection classes as an option, `collections`, and uses them on `db.orm`, on the ORM of every transaction (`tx.orm`), on every connection a serverless client opens, and on every Supabase role-bound client: `postgres({ contract, url, collections: { Post: PostCollection } })`, then `db.orm.public.Post.published()`. Extension code, examples and tests that build their own ORM client with `orm({ runtime, context, collections })` to reach custom classes still work; replace them with the option and use the client's ORM. The detection matches a call to `orm({ ... })`, or to `orm` imported under another name, that passes `collections`.
|
|
18
|
+
detection:
|
|
19
|
+
glob: "**/*.{ts,tsx,mts,cts}"
|
|
20
|
+
matches:
|
|
21
|
+
- '(?<![\w$.])orm\s*(?:<[^<>()]*(?:<[^<>()]*>[^<>()]*)*>)?\(\s*\{(?:(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*?,)?\s*collections\s*[,}:]'
|
|
22
|
+
- '(?<![\s\S])(?:(?!import\s*\{[^{}]*\borm\s+as\s+[\w$]+[^{}]*\}\s*from\s*[''\"][^''\"]+[''\"])[\s\S])*import\s*\{[^{}]*\borm\s+as\s+([\w$]+)[^{}]*\}\s*from\s*[''\"][^''\"]+[''\"][\s\S]*(?<![\w$.])\1\s*(?:<[^<>()]*(?:<[^<>()]*>[^<>()]*)*>)?\(\s*\{(?:(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*?,)?\s*collections\s*[,}:]'
|
|
23
|
+
- id: client-query-and-to-sql
|
|
24
|
+
summary: |
|
|
25
|
+
Additive for code that only uses these types. Every SQL client gets `query(plan)` and `execute(plan)`, with the types a transaction's have, and `toSql(plan)`, which returns `{ sql, params }` with no database. A serverless connection gets `query` and `execute` too; the serverless client, `postgresStatic()`, `sqliteStatic()` and every transaction get `toSql`. `postgres()`, `postgresServerless()`, `sqlite()` and `supabase()` take `mode: 'strict' | 'permissive'`. `supabase()` creates its pool on the first query instead of when it is called. Extension code, examples and tests can move from `db.runtime().query(plan)` to `db.query(plan)`; code that builds its own object of one of the changed types, such as a test double, must add the new members. The detection matches a file that imports one of the changed types from a Prisma package, calls `runtime().query(` or `runtime().execute(`, or reads the renamed error details or the old message texts.
|
|
26
|
+
detection:
|
|
27
|
+
glob: "**/*.{ts,tsx,mts,cts}"
|
|
28
|
+
matches:
|
|
29
|
+
- 'import\s*(?:type\s*)?(?:[\w$]+\s*,\s*)?\{[^}]*(?<![\w$])(?:PostgresClient|PostgresServerlessClient|PostgresServerlessConnection|PostgresStaticContext|PostgresStaticMembers|SqliteClient|SqliteStaticContext|RoleBoundDb|ServiceRoleDb|SupabaseInternalDb|PostgresTransactionContext|SqliteTransactionContext)(?![\w$])[^}]*\}\s*from\s*[''"]@prisma/orm-'
|
|
30
|
+
- '\.runtime\(\)\s*\.(?:query|execute)\('
|
|
31
|
+
- '(?<![\w$])(?:runtimeTarget|runtimeStorageHash)\s*:|\.(?:runtimeTarget|runtimeStorageHash)\b|[''"](?:runtimeTarget|runtimeStorageHash)[''"]'
|
|
32
|
+
- 'Ad-hoc execute received a bind-site slot|Plan target does not match runtime target|Plan storage hash does not match runtime contract'
|
|
33
|
+
- id: transaction-query-members
|
|
34
|
+
summary: |
|
|
35
|
+
Additive for code that only uses these types: a transaction now offers the client's query members (`sql`, `orm`, `raw`, `prepare`, `query`, `execute`) on every SQL client, a Supabase role-bound client gains `prepare`, and SQLite's `db.orm` gains `fragment`. Code that builds its own object of one of the changed types must add the new members. Changed: `PostgresTransactionContext` (adds `raw` and `prepare`), `SqliteTransactionContext` (adds `raw` and `prepare`; `orm` is now `SqliteOrm`), `RoleBoundDb` (adds `prepare`; `transaction` passes a `SupabaseTransactionContext`). New: `PostgresQueryMembers` and `SqliteQueryMembers` (the query members a client and its transactions share), `SupabaseTransactionContext`, `SqliteOrm`, and from the ORM client `OrmClientRootMembers` and `PrepareMember`. The detection matches a file that imports one of the changed types that 8.0.0-rc.18 had, or `SqliteClient`, whose `orm` changed, from a Prisma package.
|
|
36
|
+
detection:
|
|
37
|
+
glob: "**/*.{ts,tsx,mts,cts}"
|
|
38
|
+
matches:
|
|
39
|
+
- 'import\s*(?:type\s*)?(?:[\w$]+\s*,\s*)?\{[^}]*(?<![\w$])(?:PostgresTransactionContext|SqliteTransactionContext|SqliteClient|RoleBoundDb)(?![\w$])[^}]*\}\s*from\s*[''"]@prisma/orm-'
|
|
40
|
+
- id: runtime-activity-is-activity
|
|
41
|
+
summary: |
|
|
42
|
+
`RuntimeActivity` is renamed `Activity`, with no alias. It is the type of the `activity` parameter of `activityStarted`, `activityEnded` and `activityFinalized`.
|
|
43
|
+
detection:
|
|
44
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
45
|
+
matches:
|
|
46
|
+
- '\bRuntimeActivity\b'
|
|
47
|
+
- id: activity-includes-client-activities
|
|
48
|
+
summary: |
|
|
49
|
+
`Activity` is `StatementActivity | TransactionActivity | ClientActivity`, and `ActivityEndedResult` includes `ClientActivityEnded`, in every program. A client activity's kind contains a hyphen, such as `orm-call`. A hook that narrows by ruling out `'transaction'` and then reads statement fields no longer compiles. Narrow by the kind you handle, such as `if (result.kind !== 'statement') return;`, and ignore kinds you do not know.
|
|
50
|
+
detection:
|
|
51
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
52
|
+
matches:
|
|
53
|
+
- '\bif\s*\(\s*[\w$.]+\.kind\s*===\s*[''"]transaction[''"]\s*\)\s*(?:\{\s*)?(?:return|continue)\b'
|
|
54
|
+
- id: start-a-client-activity
|
|
55
|
+
summary: |
|
|
56
|
+
An extension can start an activity of its own kind with `startActivityOn(queryable, { kind, contentHash, annotations? })`, where `contentHash` is a function returning a promise of the digest, for example `() => planContentHashOn(queryable, plan)`; middleware read it with `activity.contentHash()`, which computes it once per activity and only when asked. The extension sends statements through the returned handle and must end every handle with `end({ outcome, result? })`, in a `finally`; an open handle keeps `close()` waiting. A middleware can supply the activity's result through `intercept.onActivity(activity, ctx)`. Registering the kind in `ClientActivityRegistry` types the handle's `intercepted.result` and `end({ result })`; in middleware hooks the result stays `unknown`.
|
|
57
|
+
- id: runtime-connections-carry-an-activity-source
|
|
58
|
+
summary: |
|
|
59
|
+
The SQL runtime's queryables start client activities through an `activitySource` member, keyed by a symbol so the public queryable types do not show it, which `startActivityOn` and `planContentHashOn` read. A connection-like object that a `SqlRuntimeBase` subclass builds over a raw connection adds `[activitySource]: this.connectionActivitySource(connection, () => session)`, and `ActivitySourceTarget` to the object's declared type, so activities can start on it. The public `RuntimeConnection` type does not require it.
|
|
60
|
+
detection:
|
|
61
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
62
|
+
matches:
|
|
63
|
+
- '(?<![\s\S])(?![\s\S]*\[activitySource\])[\s\S]*\[transactionStart\]\s*:'
|
|
64
|
+
- id: begin-transaction-on-takes-a-parent
|
|
65
|
+
summary: |
|
|
66
|
+
`SqlRuntimeBase.beginTransactionOn(connection, owner)` takes a third argument, `parent`: the activity the transaction starts beneath, or `undefined`. Pass `undefined` where you began a transaction before.
|
|
67
|
+
detection:
|
|
68
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
69
|
+
matches:
|
|
70
|
+
- '\bbeginTransactionOn\s*\(\s*[^,()]+,\s*[^,()]+\)'
|
|
71
|
+
- id: transaction-activity-takes-a-parent
|
|
72
|
+
summary: |
|
|
73
|
+
`startTransactionActivity` requires `parent` (the activity the transaction starts beneath, or `undefined`). An `ActivityParent` has `acceptsChildren()`, and its `adopt(child)` returns an `ActivityChildSlot` (`statementFailed()`, `ended(own)`, `transactionAcceptsChildren()`) instead of an end callback; `ActivityParent.activity` is an `ActivityBase`. A transaction stops accepting children with `stopAcceptingChildren()`, and adopting beneath a parent that no longer accepts children throws `RUNTIME.ACTIVITY_NOT_ACCEPTING_CHILDREN` instead of an internal error.
|
|
74
|
+
detection:
|
|
75
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
76
|
+
matches:
|
|
77
|
+
- '\bstartTransactionActivity\s*\(\s*\{(?![^{}]*\bparent\b)'
|
|
78
|
+
- '(?<![\s\S])(?![\s\S]*\bActivityChildSlot\b)(?=[\s\S]*\bActivityParent\b)[\s\S]*\badopt\s*\('
|
|
79
|
+
- id: orm-runtime-objects-carry-an-activity-source
|
|
80
|
+
summary: |
|
|
81
|
+
The ORM reaches activities only through `startActivityOn` on the queryable it holds, and every ORM terminal method on a queryable without an `activitySource` member fails with `ORM.ACTIVITY_SOURCE_MISSING` (see `queryable-carries-the-activity-source`). `db.runtime()` passed straight to `orm()` carries one. A facade, such as `postgres()`, that builds its own ORM runtime object, such as one that looks up its runtime on every call, adds `[activitySource]: delegatingActivitySource(() => runtime)` from `@prisma/orm-family-sql/runtime`, for the runtime and for the context of `db.transaction(fn)`. Where the facade's statements run through sessions of its own, such as role sessions, give an activity source whose statements go the same way.
|
|
82
|
+
detection:
|
|
83
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
84
|
+
matches:
|
|
85
|
+
- '(?<![\s\S])(?![\s\S]*\[activitySource\])[\s\S]*(?<![\w$.])orm\s*(?:<[^>()]*>)?\(\s*\{(?:[^{}]|\{[^{}]*\})*?\bruntime\s*:\s*\{'
|
|
86
|
+
- id: orm-annotations-on-the-call
|
|
87
|
+
summary: |
|
|
88
|
+
Every SQL ORM terminal method runs as one `orm-call` client activity, and the annotations a `configure` callback records live on that activity. The statements the call sends carry only the reserved keys the ORM sets, so a middleware that reads an ORM annotation from a statement plan (`handle.read(plan)` or `plan.meta.annotations`) finds nothing. Read it from the call: in `activityStarted(activity)` or `intercept.onActivity(activity)`, `if (activity.kind === 'orm-call') handle.read(activity)`. A middleware can answer the call through `intercept.onActivity`; the value must have the shape the terminal returns, or the ORM rejects with `ORM.INTERCEPTED_RESULT_INVALID`. The detection matches a file with a middleware hook, not a MongoDB one, that reads an annotation from something other than the activity, or reads `meta.annotations`.
|
|
89
|
+
detection:
|
|
90
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
91
|
+
matches:
|
|
92
|
+
- '(?<![\s\S])(?![\s\S]*(?:familyId:\s*[''"]mongo[''"]|\bMongoMiddleware\b))(?=[\s\S]*\b(?:beforeEncode|beforeCompile|onQuery|onExecute|onRow|activityStarted)\b)[\s\S]*\.read\(\s*(?!activity\b)[\w$]+(?:\.[\w$]+)*\s*\)'
|
|
93
|
+
- '(?<![\s\S])(?![\s\S]*(?:familyId:\s*[''"]mongo[''"]|\bMongoMiddleware\b))(?=[\s\S]*\b(?:beforeEncode|beforeCompile|onQuery|onExecute|onRow|activityStarted)\b)[\s\S]*\bmeta\.annotations\b'
|
|
94
|
+
- id: cache-store-holds-cached-values
|
|
95
|
+
summary: |
|
|
96
|
+
A cache store for `@internal/middleware-cache` holds `CachedValue`, `{ kind: 'statement-rows', rows } | { kind: 'call-result', result }`, not `CachedRows`; `CacheStore` and `CacheEntry` default their value type to `CachedValue`, and `createCacheMiddleware` accepts only a `CacheStore<TMeta, CachedValue>`. Type a custom store with `CachedValue`, and make `get` give back a value equivalent to the one `set` was given, `kind` included. An ORM call's result holds decoded values such as `Date`, `bigint`, Temporal values and extension class instances, so a store that serializes needs a serializer that rebuilds them; JSON does not. `createInMemoryCacheStore` takes only the meta type now and always holds `CachedValue`: drop its second type argument. The detection matches a file that names `CachedRows`, or imports from the cache package and names `CacheStore` or `CacheEntry` but not `CachedValue`, or passes `createInMemoryCacheStore` a second type argument.
|
|
97
|
+
detection:
|
|
98
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
99
|
+
matches:
|
|
100
|
+
- '\bCachedRows\b'
|
|
101
|
+
- 'createInMemoryCacheStore<[^>(]*,'
|
|
102
|
+
- '(?<![\s\S])(?![\s\S]*\bCachedValue\b)(?=[\s\S]*[''"](?:@prisma/orm-extension-middleware-cache|@internal/middleware-cache)[''"])[\s\S]*(?<![\w$])(?:CacheStore|CacheEntry)(?![\w$])'
|
|
103
|
+
- id: queryable-carries-the-activity-source
|
|
104
|
+
summary: |
|
|
105
|
+
The SQL ORM starts its `orm-call` activity on the queryable it was given, through the queryable's `activitySource` member, and sends every statement through the activity's handle. A wrapper that copies a runtime, connection or transaction to intercept its `query` and `execute` (for example to record plans) also copies the `[activitySource]` member, so ORM statements bypass the wrapper. Wrap the activity source too: return a source whose `startActivity` wraps each handle the same way, including the transaction its `transaction()` returns. A custom queryable passed to the ORM must carry an activity source: without one, every terminal method fails with `ORM.ACTIVITY_SOURCE_MISSING` (streaming terminals throw when called, the others reject). A test stub can use `delegatingActivitySource(() => realRuntime)`, or a source whose handles send their statements to the stub.
|
|
106
|
+
detection:
|
|
107
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
108
|
+
matches:
|
|
109
|
+
- '\.\.\.\s*[\w$.]+(?:\(\))?\s*,(?:[^{};\[\]]|\{(?:[^{}]|\{[^{}]*\})*\})*?(?<![\w$.])(?:async\s+)?(?:query|execute)\s*(?:[:(<])'
|
|
110
|
+
- id: aggregate-operation-using-reserved
|
|
111
|
+
summary: |
|
|
112
|
+
Every ORM collection has a `using` member, so `orm()` refuses a contributed aggregate operation named `using` with `ORM.AGGREGATE_OPERATION_RESERVED`, as it refuses `with` and `fragment`. An extension that contributes an aggregate operation named `using` renames it. The detection matches a file that names an aggregate operation `using`.
|
|
113
|
+
detection:
|
|
114
|
+
glob: "**/*.{ts,mts,cts}"
|
|
115
|
+
matches:
|
|
116
|
+
- '\boperation\s*:\s*[''"`]using[''"`]'
|
|
117
|
+
- id: codecs-read-wire-and-data-type-values
|
|
118
|
+
summary: |
|
|
119
|
+
A codec implements `toWire`, `fromWire`, `toDataTypeValue` and `fromDataTypeValue` instead of `encode`, `decode`, `encodeJson` and `decodeJson`. Its constructor names its data type and parameters (`super(descriptor, dataType, params)`), and it builds the value it hands over with `this.dataTypeValueOf(json)`. A Mongo codec made with `mongoCodec()` takes the same four options in place of `encode`, `decode`, `encodeJson` and `decodeJson`, and a required `dataType`.
|
|
120
|
+
detection:
|
|
121
|
+
glob: "**/*.{ts,mts,cts}"
|
|
122
|
+
matches:
|
|
123
|
+
- '\b(?:encodeJson|decodeJson)\s*\('
|
|
124
|
+
- '\basync\s+(?:encode|decode)\s*\('
|
|
125
|
+
- '\b(?:encode|decode)\s*:\s*(?:async\s*)?\('
|
|
126
|
+
- '\b(?:encodeJson|decodeJson)\s*:'
|
|
127
|
+
- id: data-types-own-parameter-limits
|
|
128
|
+
summary: |
|
|
129
|
+
Every data type declares a `read` function, which reads and checks each stored value under the column's parameters. It replaces the `toCanonicalForm` hook of a data type or codec descriptor, and limits a parameter sets, such as a vector's length or a geometry's SRID, move from the codec to the data type. The detection matches `toCanonicalForm`, and a `sqlDataType`, `mongoDataType` or `dataType` call whose options have no `read` or are passed as a variable.
|
|
130
|
+
detection:
|
|
131
|
+
glob: "**/*.{ts,mts,cts}"
|
|
132
|
+
matches:
|
|
133
|
+
- '\btoCanonicalForm\b'
|
|
134
|
+
- '(?<![\w$.])(?:sqlDataType|mongoDataType|dataType)\(\s*[^,()]+,\s*\{(?!(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\bread\b)'
|
|
135
|
+
- '(?<![\w$.])(?:sqlDataType|mongoDataType|dataType)\(\s*[^,()]+,\s*(?!\{)[\w$]+\s*\)'
|
|
136
|
+
- id: json-helpers-renamed
|
|
137
|
+
summary: |
|
|
138
|
+
The JSON helpers in `@prisma/orm-framework/components/codec` are renamed from `decodeJson*` to `readJson*` (`readJsonString`, `readJsonMatching`, `readJsonInteger`, `readJsonIntegerText`, `readJsonFloat`, `readJsonBoolean`), and `encodeJsonFloat` to `floatToJson`. `ToCanonicalForm` and `canonicalFormOf` are removed.
|
|
139
|
+
detection:
|
|
140
|
+
glob: "**/*.{ts,mts,cts}"
|
|
141
|
+
matches:
|
|
142
|
+
- '\b(?:decodeJson(?:String|Matching|Integer|IntegerText|Float|Boolean)|encodeJsonFloat|canonicalFormOf|ToCanonicalForm)\b'
|
|
143
|
+
- id: stored-form-helpers-renamed
|
|
144
|
+
summary: |
|
|
145
|
+
The SQL helpers that read or write a value's stored text say "stored" instead of "canonical": `canonicalDateTime` is `dateTimeStoredText`, `CanonicalDateTimeOptions` is `DateTimeStoredTextOptions`, `canonicalNumeralText` is `storedNumeralText`, `sqlTextFromCanonical` is `sqlTextFromStored`, and `canonicalSqlText` is `storedSqlText`.
|
|
146
|
+
detection:
|
|
147
|
+
glob: "**/*.{ts,mts,cts}"
|
|
148
|
+
matches:
|
|
149
|
+
- '\b(?:canonicalDateTime|CanonicalDateTimeOptions|canonicalNumeralText|sqlTextFromCanonical|canonicalSqlText)\b'
|
|
150
|
+
- id: projections-read-by-from-wire
|
|
151
|
+
summary: |
|
|
152
|
+
An include and an aggregate read a column's JSON projection with the codec's `fromWire`, as a row is read, so a descriptor's `jsonProjection` writes the value the driver returns for a row, often `CAST(x AS text)`, instead of the codec's JSON form.
|
|
153
|
+
detection:
|
|
154
|
+
glob: "**/*.{ts,mts,cts}"
|
|
155
|
+
matches:
|
|
156
|
+
- '\bjsonProjection\s*\('
|
|
157
|
+
- id: empty-result-json-renamed-empty-result-wire
|
|
158
|
+
summary: |
|
|
159
|
+
An aggregate descriptor's `emptyResultJson` is renamed `emptyResultWire`, and holds the value the driver would return, which the result codec reads with `fromWire`.
|
|
160
|
+
detection:
|
|
161
|
+
glob: "**/*.{ts,mts,cts}"
|
|
162
|
+
matches:
|
|
163
|
+
- '\bemptyResultJson\b'
|
|
164
|
+
- id: target-codec-adapters-take-a-factory
|
|
165
|
+
summary: |
|
|
166
|
+
`postgresCodec` (`@prisma/orm-postgres/target/codec-descriptor`) and `sqliteCodec` (`@prisma/orm-sqlite/target/codec-descriptor`) require a `factory` option, and it receives the option's `dataType` between the descriptor and the column's parameters: `factory: (descriptor, dataType, params) => () => new MyCodec(descriptor, dataType, params)`. Before, `factory` was optional and took `(descriptor, params)`, and a call without it built the family template's codec. A family template names no data type, so it builds no codec of its own. `sqliteCodec` no longer takes `renderTypes`. The detection matches a call without `factory`, a `factory` whose second parameter is not the data type, and `renderTypes: false`.
|
|
167
|
+
detection:
|
|
168
|
+
glob: "**/*.{ts,mts,cts}"
|
|
169
|
+
matches:
|
|
170
|
+
- '\b(?:postgresCodec|sqliteCodec)\(\s*[\w$.]+\s*,\s*\{(?!(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\bfactory\b)'
|
|
171
|
+
- '\b(?:postgresCodec|sqliteCodec)\(\s*[\w$.]+\s*,\s*\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*?\bfactory\s*:\s*(?:\(\s*(?:[\w$]+\s*(?::\s*[^,()]+)?)?\)|\(\s*[\w$]+\s*(?::\s*[^,()]+)?,(?!\s*_?dataType\b)\s*[^,()]+\)|(?!\()[\w$]+)\s*=>'
|
|
172
|
+
- '\brenderTypes\s*:\s*false\b'
|
|
173
|
+
- id: family-codec-templates-render-no-literals
|
|
174
|
+
summary: |
|
|
175
|
+
`postgresCodec` and `sqliteCodec` now throw an `InternalError` when the family codec template they adapt declares `renderValueLiteral`. Earlier versions copied the template's renderer. A family template renders no literal, because only the target knows the form its data type stores a value in. Remove `renderValueLiteral` from the template and pass it in the adapter's options instead; the framework exports `renderTsLiteral`, `floatNumberLiteral`, `decimalTextNumberLiteral` and `decimalTextBigintLiteral` from `@internal/framework-components/codec` for the common stored forms.
|
|
176
|
+
detection:
|
|
177
|
+
glob: "**/*.{ts,mts,cts}"
|
|
178
|
+
matches:
|
|
179
|
+
- '(?<![\s\S])(?=[\s\S]*\bextends\s+CodecDescriptorTemplateImpl\b)(?=[\s\S]*\brenderValueLiteral\s*\()'
|
|
180
|
+
- id: enum-block-written-values
|
|
181
|
+
summary: |
|
|
182
|
+
A parsed PSL extension block now records each literal entry as it is written in `writtenValues`, a `WrittenScalar` by key, in place of `numberTexts`, which held only the source text of number entries. `AuthoringEntityContext.readWrittenNumber` is replaced by `readWrittenValueForCodec`, which takes a `WrittenScalar` as `written` in place of the number's `text`, and reads any written value, not only a number, by the cast rule. A refused `WrittenValueReading` now carries the diagnostic `code` with its `message`. `enumMemberValue()` yields a tagged member as its `WrittenScalar` in place of `null`.
|
|
183
|
+
detection:
|
|
184
|
+
glob: "**/*.{ts,mts,cts}"
|
|
185
|
+
matches:
|
|
186
|
+
- '\b(?:numberTexts|readWrittenNumber|WrittenValueReading)\b'
|
|
187
|
+
- id: type-lookups-one-framework-type
|
|
188
|
+
summary: |
|
|
189
|
+
`SqlTypeLookups` (from `@prisma/orm-family-sql/contract/data-type`) and `MongoTypeLookups` (from `@prisma/orm-family-mongo/contract/data-type`) are removed. Use `TypeLookups` from `@prisma/orm-framework/components/codec`, the same pair of `codecLookup` and `dataTypeLookup`.
|
|
190
|
+
detection:
|
|
191
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
192
|
+
matches:
|
|
193
|
+
- '\b(?:SqlTypeLookups|MongoTypeLookups)\b'
|
|
194
|
+
- id: type-name-normalisers-removed
|
|
195
|
+
summary: |
|
|
196
|
+
`normalizeSchemaNativeType` (from `@prisma/orm-postgres/target/native-type-normalizer` and `@prisma/orm-postgres/adapter/control`) and `normalizeSqliteNativeType` (from `@prisma/orm-sqlite/adapter/control`) are removed. Columns are compared by their data type and its parameters, so no type name needs normalising.
|
|
197
|
+
detection:
|
|
198
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
199
|
+
matches:
|
|
200
|
+
- '\b(?:normalizeSchemaNativeType|normalizeSqliteNativeType)\b'
|
|
201
|
+
- id: introspected-type-text
|
|
202
|
+
summary: |
|
|
203
|
+
In `@prisma/orm-postgres/target/native-type-normalizer`, `introspectedNativeType` is renamed `introspectedTypeText` and `IntrospectedNativeType` is renamed `IntrospectedTypeText`; its result holds `typeText` (the type the database reports) and `many`, and no `resolvedNativeType`. `CatalogColumnType.dataType` is renamed `informationSchemaType`.
|
|
204
|
+
detection:
|
|
205
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
206
|
+
matches:
|
|
207
|
+
- '\b(?:introspectedNativeType|IntrospectedNativeType|CatalogColumnType)\b'
|
|
208
|
+
- id: schema-ir-column-type-text
|
|
209
|
+
summary: |
|
|
210
|
+
`SqlColumnIR` and `SqlColumnIRInput` (`@prisma/orm-family-sql/schema-ir/types`): `nativeType` is renamed `typeText`, and `resolvedNativeType` and `codecBaseNativeType` are removed. `dataType` is removed: a column's type is its `storedType` and `storedTypeParams`, and nothing compares `typeText`. A column built by hand compares equal to another only when it has `storedType` and `storedTypeParams`.
|
|
211
|
+
detection:
|
|
212
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
213
|
+
matches:
|
|
214
|
+
- '\b(?:resolvedNativeType|codecBaseNativeType)\b'
|
|
215
|
+
- '(?<![\s\S])(?=[\s\S]*(?:\bSqlColumnIR|\bSqlTableIR|\bSqlSchemaIR|schema-ir))[\s\S]*\bnativeType\b'
|
|
216
|
+
- id: default-resolver-takes-the-column
|
|
217
|
+
summary: |
|
|
218
|
+
A `DefaultResolver` (`@prisma/orm-family-sql/family/control`) receives the column, `{ typeText, many }`, as its second argument instead of the resolved type name. `parsePostgresDefault(raw, nativeType?)` (`@prisma/orm-postgres/target/default-normalizer`, `@prisma/orm-postgres/adapter/control`) is replaced by `readPostgresDefault(raw, many)` from `@prisma/orm-postgres/target/default-normalizer`, which takes whether the column is a list and returns a `PostgresReportedDefault`, `{ kind: 'function', expression } | { kind: 'null' } | { kind: 'literal', literal }`, instead of a `ColumnDefault` or `undefined`. `parseSqliteDefault(raw, nativeType?)` (`@prisma/orm-sqlite/target/default-normalizer`, `@prisma/orm-sqlite/adapter/control`) is replaced the same way by `readSqliteDefault(raw, declaredType)`, which returns a `SqliteReportedDefault`. The optional `normalizeDefault` member of `SqlControlAdapter`, which nothing called, and its type `DefaultNormalizer` are removed.
|
|
219
|
+
detection:
|
|
220
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
221
|
+
matches:
|
|
222
|
+
- '\b(?:parsePostgresDefault|parseSqliteDefault|DefaultNormalizer|normalizeDefault)\b'
|
|
223
|
+
- '(?<![\s\S])(?![\s\S]*\.(?:many|typeText)\b)[\s\S]*\bDefaultResolver\b'
|
|
224
|
+
- id: alter-type-postcheck-by-data-type
|
|
225
|
+
summary: |
|
|
226
|
+
In `@prisma/orm-postgres/target/planner-sql-checks`, `buildExpectedFormatType` and `alterTypeCheckText` are removed. `alterTypeCheck(type, dataTypes, where)` returns how the `ALTER COLUMN TYPE` postcheck recognises the new type, a `ColumnTypeCheck`: `{ kind: 'catalog-text', text }`, the text `format_type` prints, or for an enum `{ kind: 'identity', typeName, many }`, checked with `to_regtype` whatever schema the enum is in. The `checkType` field of `AlterColumnTypeCall` (`@prisma/orm-postgres/target/op-factory-call`) is now a `ColumnTypeCheck` instead of a string. `AddColumnCall`, `AddRequiredColumnToEmptyTableCall` and `AddColumnWithTemporaryDefaultCall` gain a `checkType` of `ColumnTypeCheck | undefined`, `undefined` when no data type of the stack reads the column's type.
|
|
227
|
+
detection:
|
|
228
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
229
|
+
matches:
|
|
230
|
+
- '\b(?:buildExpectedFormatType|alterTypeCheckText)\b'
|
|
231
|
+
- id: control-adapters-take-declared-data-types
|
|
232
|
+
summary: |
|
|
233
|
+
`PostgresControlAdapter` (`@prisma/orm-postgres/adapter/control`) and `SqliteControlAdapter` (`@prisma/orm-sqlite/adapter/control`) take the stack's declared data types as a new last constructor argument, because introspection resolves each column's reported type over them. Pass the target's `postgresDataTypes` or `sqliteDataTypes` (from `/target/data-types`), or, when the stack has extensions, the stack's types: `stack.declaredDataTypes.map(({ type }) => type)`. Code that leaves it out fails to compile, and untyped JavaScript fails at the first introspection.
|
|
234
|
+
detection:
|
|
235
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs}"
|
|
236
|
+
matches:
|
|
237
|
+
- '\bnew\s+(?:Postgres|Sqlite)ControlAdapter\s*\('
|
|
238
|
+
- id: resolved-sql-type-carries-the-data-type
|
|
239
|
+
summary: |
|
|
240
|
+
`resolveReportedSqlType` and `resolveWrittenSqlTypes` (`@prisma/orm-family-sql/contract/data-type`) return the data type they found in `dataType`, a `SqlDataType`, instead of its id. Read `resolved.dataType.id` where you read `resolved.dataType`.
|
|
241
|
+
detection:
|
|
242
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
243
|
+
matches:
|
|
244
|
+
- '(?<![\s\S])(?=[\s\S]*\bresolve(?:ReportedSqlType|WrittenSqlTypes)\b)[\s\S]*\.dataType\b(?!\s*\.)'
|
|
245
|
+
- id: value-arguments-name-a-data-type
|
|
246
|
+
summary: |
|
|
247
|
+
A type constructor's argument that is a value is declared `{ kind: 'value', dataType }`, naming the data type the argument's value belongs to, such as `pg/int4` for a Postgres length, precision, scale or SRID. The argument kinds `string`, `boolean` and `stringArray` are removed, and a type constructor's `number` argument becomes a `value` argument. Drop `integer`, `minimum` and `maximum`: the data type's parameter schema checks the value. Assembly refuses a type constructor argument of any other kind, `option` and `object` included. A field preset keeps its `number`, `option` and `object` arguments, so a match inside a field preset needs no change.
|
|
248
|
+
detection:
|
|
249
|
+
glob: "**/*.{ts,mts,cts}"
|
|
250
|
+
matches:
|
|
251
|
+
- 'kind:\s*[''"](?:number|string|boolean|stringArray)[''"](?=[^}]*\b(?:name|integer|minimum|maximum|optional)\s*:)'
|
|
252
|
+
- '\b(?:name|integer|minimum|maximum|optional)\s*:[^{}]*\bkind:\s*[''"](?:number|string|boolean|stringArray)[''"]'
|
|
253
|
+
- '\{\s*kind:\s*[''"](?:number|string|boolean|stringArray)[''"]\s*\}'
|
|
254
|
+
- id: value-argument-types-in-typescript
|
|
255
|
+
summary: |
|
|
256
|
+
The TypeScript builder types a `value` argument through `__dataTypeArguments`, a map a pack declares in its type from each data type it registers to `{ argument, parameter }`: the TypeScript value an author passes, and the type parameter it gives. A pack that registers a data type its own type constructors take must declare it, or the argument types as `never`. The TypeScript builder reads value arguments only with the data types and authoring entries the composed packs register, so every data type an argument takes must be registered, with a writable `authoring.dataTypes` entry, by some pack in the stack: the family, the target or an extension. An extension whose arguments take a target's data type, such as `pg/int4`, registers nothing; registering it again is refused as a duplicate.
|
|
257
|
+
- id: psl-and-print-helpers-take-data-types
|
|
258
|
+
summary: |
|
|
259
|
+
`mapPslHelperArgs` and `instantiatePslFieldPreset` take the stack's `dataTypes`, and `parsePslPositionalArgs` is removed. The new `writtenTypeArguments` writes a call's arguments as literals of their data types. `sql.String` is no longer in the SQL family pack: a SQL target contributes it with `sqlTargetTypeConstructors({ sizeType })` from `family/pack`, and `temporalCodecPresetWithPrecision` takes `sizeType` too. `temporalCodecPresetWithPrecision` and `temporalStringAuthoringPresets` move from `family/control` to `family/pack`, so a target pack does not load the family's control entry point. `assembleAuthoringDataTypes` moves from `components/control` to `components/authoring`, beside `assembleDataTypeSupport`, which builds a `DataTypeSupport` from a list of components and checks their value arguments.
|
|
260
|
+
detection:
|
|
261
|
+
glob: "**/*.{ts,mts,cts}"
|
|
262
|
+
matches:
|
|
263
|
+
- '\bparsePslPositionalArgs\b|\b(?:mapPslHelperArgs|instantiatePslFieldPreset)\(\s*\{(?![^{}]*\bdataTypes\b)'
|
|
264
|
+
- 'import\s*(?:type\s*)?\{[^}]*\b(?:assembleAuthoringDataTypes|temporalCodecPresetWithPrecision|temporalStringAuthoringPresets)\b[^}]*\}\s*from\s*[''"][^''"]*/(?:components|family|family-sql)/control[''"]'
|
|
265
|
+
- id: composed-helpers-take-no-data-type-lookup
|
|
266
|
+
summary: |
|
|
267
|
+
`createComposedAuthoringHelpers` no longer takes `dataTypeLookup`. It builds its data types from the family, target and extension packs it is given, with `assembleDataTypeSupport`. Remove the option. Every data type an argument takes must be registered, with an `authoring.dataTypes` entry, by some pack in the stack; an extension whose arguments take a target's data type, such as `pg/int4`, registers nothing.
|
|
268
|
+
detection:
|
|
269
|
+
glob: "**/*.{ts,mts,cts}"
|
|
270
|
+
matches:
|
|
271
|
+
- 'createComposedAuthoringHelpers\(\{[^}]*\bdataTypeLookup\b'
|
|
272
|
+
- id: helper-codec-invariants
|
|
273
|
+
summary: |
|
|
274
|
+
`enforceDataTypeInvariants` is renamed `enforceHelperCodecInvariants`, and `DataTypeInvariantInput` is renamed `HelperCodecInvariantInput`. It now checks only type constructors and field presets against the stack's codecs, and takes `lookup`, `helpers` (formerly `constructors`) and `codecDescriptorFor`. `declaredTypes`, `codecs` and `authoringEntries` are removed: `assembleDataTypeSupport` checks data types, their entries, casts and written forms, through `enforceDataTypeAssemblyInvariants`.
|
|
275
|
+
detection:
|
|
276
|
+
glob: "**/*.{ts,mts,cts}"
|
|
277
|
+
matches:
|
|
278
|
+
- 'enforceDataTypeInvariants|DataTypeInvariantInput'
|
|
279
|
+
- id: default-functions-lower-to-database-defaults-only
|
|
280
|
+
summary: |
|
|
281
|
+
A default function in `controlMutationDefaults.defaultFunctionRegistry` can no longer lower to a client generator: `LoweredDefaultValue` has only its `{ kind: 'storage' }` arm. A function that generated a value in the client, such as `slugid()`, becomes a generator function: contribute a `GeneratorFunctionContribution` in `generatorFunctions` on the pack ref and the control descriptor, with a binding for each codec it fills, and keep the generator descriptor. Users then write `@onCreate(slugid())` instead of `@default(slugid())`. The detection matches files that lower a default function to a generator.
|
|
282
|
+
detection:
|
|
283
|
+
glob: "**/*.{ts,mts,cts}"
|
|
284
|
+
matches:
|
|
285
|
+
- "kind:\\s*'execution'"
|
|
286
|
+
- id: applicable-codec-ids-and-build-phases-removed
|
|
287
|
+
summary: |
|
|
288
|
+
`MutationDefaultGeneratorDescriptor.applicableCodecIds` and `buildPhases` are removed. A binding of a generator function declares the codecs it fills and the arguments `contract print` writes for each generator it produces. Delete the removed fields. The detection matches files that set them.
|
|
289
|
+
detection:
|
|
290
|
+
glob: "**/*.{ts,mts,cts}"
|
|
291
|
+
matches:
|
|
292
|
+
- 'applicableCodecIds\s*:'
|
|
293
|
+
- 'buildPhases\s*:'
|
|
294
|
+
- id: sql-family-registers-identifier-generators
|
|
295
|
+
summary: |
|
|
296
|
+
The SQL family now registers the identifier generators `uuidv4`, `uuidv7`, `cuid2`, `ulid`, `nanoid` and `ksuid`. A target, adapter or extension that registers one of them in `generatorDescriptors` must stop: two components that register one generator fail with `CONTRACT.PACK_CONTRIBUTION_INVALID`. An extension that binds `uuid` or another identifier function to its own codec keeps the binding and drops the registration. `builtinGeneratorRegistryMetadata` from `@prisma/orm-framework/ids` is removed; delete its use. The detection matches files that register the built-in identifier generators.
|
|
297
|
+
detection:
|
|
298
|
+
glob: "**/*.{ts,mts,cts}"
|
|
299
|
+
matches:
|
|
300
|
+
- 'builtinGeneratorRegistryMetadata'
|
|
301
|
+
- "\\{\\s*id:\\s*['\"](?:uuidv4|uuidv7|cuid2|ulid|nanoid|ksuid)['\"]\\s*\\}"
|
|
302
|
+
- id: sql-target-declares-integer-argument-generators
|
|
303
|
+
summary: |
|
|
304
|
+
A SQL target declares the generator functions its columns take, in `generatorFunctions` on both its pack ref and its control descriptor, which 8.0.0-rc.18 did not have. The arguments of `uuid`, `cuid` and `nanoid` are values of the target's integer data type, which only the target knows, so the target spreads `sqlIntegerArgumentGeneratorFunctions({ integer })` from `@prisma/orm-family-sql/family/pack`, and binds the identifier functions to its text codecs with `idGeneratorFunctionBindings`. Without the first, composing a stack fails with `CONTRACT.PACK_CONTRIBUTION_INVALID`: `"sql" binds generator function "uuid", which no component declares.` The detection matches a SQL target descriptor that does not name `sqlIntegerArgumentGeneratorFunctions`; check the file that builds the target's `generatorFunctions`.
|
|
305
|
+
detection:
|
|
306
|
+
glob: "**/*.{ts,mts,cts}"
|
|
307
|
+
matches:
|
|
308
|
+
- '(?<![\s\S])(?![\s\S]*\bsqlIntegerArgumentGeneratorFunctions\b)(?=[\s\S]*\bfamilyId:\s*[''"]sql[''"])[\s\S]*\bkind:\s*[''"]target[''"]'
|
|
309
|
+
- id: generator-signature-from-data-types
|
|
310
|
+
summary: |
|
|
311
|
+
The `signature` of a default function in a `defaultFunctionRegistry` entry may now be a function of the stack's data types that returns the `FuncCallSig`, as may the `signature` of a `GeneratorFunctionContribution`. Code that reads an entry's `signature` as a `FuncCallSig`, such as `funcCall(name, entry.signature as FuncCallSig)`, builds the call with `defaultFunctionCall(name, entry, dataTypes)` from `@prisma/orm-family-sql/contract-psl/attribute-specs` instead. A plain object still works. The detection matches a file that names `defaultFunctionRegistry` and reads a `signature`.
|
|
312
|
+
detection:
|
|
313
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs}"
|
|
314
|
+
matches:
|
|
315
|
+
- '(?<![\s\S])(?=[\s\S]*\bdefaultFunctionRegistry\b)[\s\S]*\.signature\b'
|
|
316
|
+
- id: generator-function-field-length
|
|
317
|
+
summary: |
|
|
318
|
+
Nothing to change in code written against 8.0.0-rc.18, which has no generator function registry. A binding you write for `default-functions-lower-to-database-defaults-only` receives the column as `GeneratorFunctionField` (`@prisma/orm-framework/components/components`), whose `length` is the column's length in its data type's normal form, so a bare `Char` gives 1, or `undefined` for a column with no length or one whose database does not limit it, such as SQLite's. The built-in identifier bindings refuse a column shorter than what they write, and a binding of your own can read `length` to do the same. Code that calls `resolve` or `callFor` on a generator function registry passes it; for a SQL column, `sqlCodecColumnLength(dataTypes, codecId, typeParams)` from `@prisma/orm-family-sql/contract/data-type` computes it.
|
|
319
|
+
- id: build-contract-definition-takes-lookups
|
|
320
|
+
summary: |
|
|
321
|
+
`buildContractDefinition` (`@prisma/orm-family-sql/contract-ts/contract-builder`) now requires `codecLookup` and `dataTypeLookup`, the same lookups `buildSqlContractFromDefinition` takes, so that each `.onCreate(...)` and `.onUpdate(...)` call is checked against its column's length. Pass them in the definition. The detection matches files that call `buildContractDefinition`.
|
|
322
|
+
detection:
|
|
323
|
+
glob: "**/*.{ts,mts,cts}"
|
|
324
|
+
matches:
|
|
325
|
+
- '\bbuildContractDefinition\('
|
|
326
|
+
- id: arg-binding-spec-label
|
|
327
|
+
summary: |
|
|
328
|
+
`ArgBindingSpec` (`@prisma/orm-framework/psl-parser`), the second argument of `interpretArgs`, names its callee with `label`, the whole phrase such as `Attribute "rel"`, instead of `name`. `funcCall(name, signature, { label })` takes the phrase its binding diagnostics use; without it they say `Attribute "<name>"` as before.
|
|
329
|
+
detection:
|
|
330
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs}"
|
|
331
|
+
matches:
|
|
332
|
+
- '\binterpretArgs\s*\('
|
|
333
|
+
- '\bArgBindingSpec\b'
|
|
334
|
+
- id: one-of-refuses-data-type-value
|
|
335
|
+
summary: |
|
|
336
|
+
`oneOf` (`@prisma/orm-framework/psl-parser`) throws an `InternalError` when one of its arms is a `dataTypeValue`. Give the value its own parameter, or use it as a parameter of a `funcCall` arm.
|
|
337
|
+
detection:
|
|
338
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs}"
|
|
339
|
+
matches:
|
|
340
|
+
- '\boneOf\([^;]*\bdataTypeValue\('
|
|
341
|
+
- id: text-data-types
|
|
342
|
+
summary: |
|
|
343
|
+
A component's authoring contributions may name `textDataTypes`, the data types whose values are text; a SQL target names its own. A SQL `@@discriminator` field must be stored in one of them. An extension that adds a text type names it there to make it a discriminator.
|
|
344
|
+
- id: typescript-contract-pack-type-slots
|
|
345
|
+
summary: |
|
|
346
|
+
A contract built with `defineContract` reads its types from the packs in it. A third-party SQL pack is typed fully for such a contract only when it declares what an emitted `contract.d.ts` would get from its codecs and descriptors: `__queryOperationTypes` for its query operations, `__parameterizedOutputTypes` for codecs whose output type depends on their type parameters, literal-typed `types.aggregateDescriptors` for its aggregates, and exports from its `/pack` entry for the types an application's exported contract names. Nothing breaks for a pack that does none of this; its operations, refined output types and aggregates are missing from a `defineContract` contract's types, as before. The detection matches SQL pack metadata that declares codec types.
|
|
347
|
+
detection:
|
|
348
|
+
glob: "**/*.{ts,mts,cts}"
|
|
349
|
+
matches:
|
|
350
|
+
- '__codecTypes\?:'
|
|
351
|
+
- id: parameterized-output-types-declared-once
|
|
352
|
+
summary: |
|
|
353
|
+
A codec whose output type depends only on its column's type parameters, such as `Vector<3>` for `vector(3)`, declares that type once, as a type function the pack exports, and no longer implements `renderOutputType`. The emitted `contract.d.ts` applies the type function, and so does a contract built with `defineContract`. A pack must name the function twice: in its codec types' metadata as `types.codecTypes.parameterizedOutputTypes`, an import spec like `types.codecTypes.import`, which the emitter reads, and in its pack metadata's type as `__parameterizedOutputTypes`, which `defineContract` reads; if one is missing, that path types the column by the codec's plain output type without an error. `ParameterizedOutputTypesFunction` comes from `@prisma/orm-framework/contract/types`. A `renderOutputType` that writes such a type still works for the emitted file but is ignored by `defineContract`; remove it, with the `typeImports` entry it needed, once the type function exists. Keep `renderOutputType` only for a type no type function can compute, such as an arktype schema's text. The detection matches codec descriptors that implement `renderOutputType`.
|
|
354
|
+
detection:
|
|
355
|
+
glob: "**/*.{ts,mts,cts}"
|
|
356
|
+
matches:
|
|
357
|
+
- 'renderOutputType\('
|
|
358
|
+
- 'renderOutputType:'
|
|
359
|
+
- id: psl-interpreter-contract-capabilities
|
|
360
|
+
summary: |
|
|
361
|
+
`interpretPslDocumentToSqlContract` now writes the enabled capabilities it is given in `capabilities` into the contract it returns, joined with the target's and the extensions', so a contract read from PSL carries its adapter's capabilities as one built with `defineContract` does. Before, it used them only to check the schema and left them out of the contract. Code that called it directly and compared the contract's `capabilities` to the target's and extensions' alone now also sees the ones it passed in. The detection matches calls of the interpreter.
|
|
362
|
+
detection:
|
|
363
|
+
glob: "**/*.{ts,mts,cts}"
|
|
364
|
+
matches:
|
|
365
|
+
- 'interpretPslDocumentToSqlContract\('
|
|
366
|
+
- id: field-types-expression-removed
|
|
367
|
+
summary: |
|
|
368
|
+
Nothing to change in code written against 8.0.0-rc.18: the `fieldTypesExpression` hook of `EmissionSpi` was added and removed between 8.0.0-rc.18 and 8.0.0-rc.19. The emitter writes `FieldOutputTypes` and `FieldInputTypes` for every family as `FieldTypesFromDomain` applied to the emitted contract, and declares `FieldTypeOverrides` and `ParameterizedOutputTypeFunctions` itself.
|
|
369
|
+
- id: field-types-generic-moved
|
|
370
|
+
summary: |
|
|
371
|
+
Nothing to change in code written against 8.0.0-rc.18, which has no `FieldTypesFromDomain`. Code written against a development build after it imports `FieldTypesFromDomain` and `ValueTypeSide` from `@prisma/orm-framework/contract/types` instead of the SQL family contract types entry. The generic types value object and union fields itself, from the namespace's `valueObjects`. Its arguments are `FieldTypesFromDomain<DomainNamespaces, CodecTypes, ParameterizedOutputs, Overrides, Side>`, where `Overrides` is one map keyed like the domain, `[namespace]['models' | 'valueObjects'][owner][field]`, each entry `{ output?, input? }`; `ValueObjectTypesFromDomain` takes the same map. A storage type map can type one entry with `StoredValueType` from the same entry. `ColumnTypesFromStorage` stays in the SQL family.
|
|
372
|
+
- id: resolve-field-value-set-renamed
|
|
373
|
+
summary: |
|
|
374
|
+
`EmissionSpi.resolveFieldValueSet` is renamed `resolveStorageValueSet`. The framework emitter now reads a field's value set itself when the field references a domain enum (`valueSet.plane` is `'domain'`), for model and value object fields alike, and no longer calls the hook for those fields. It calls `resolveStorageValueSet` only for other model fields, whose values the family keeps in its storage, such as a SQL column's value set. Rename the hook in a family emitter, and drop any handling of domain enum references from it. The detection matches implementations of the old hook.
|
|
375
|
+
detection:
|
|
376
|
+
glob: "**/*.{ts,mts,cts}"
|
|
377
|
+
matches:
|
|
378
|
+
- '\bresolveFieldValueSet\s*[(:?]'
|
|
379
|
+
- id: mongo-parameterized-output-types
|
|
380
|
+
summary: |
|
|
381
|
+
A Mongo-family pack whose codec output type depends only on a field's type parameters, such as `Vector<3>` for a vector of length 3, declares it once as a type function, as SQL packs do: export a `ParameterizedOutputTypesForTypeParams` interface extending `ParameterizedOutputTypesFunction` from its `codec-types` entry, name it in `types.codecTypes.parameterizedOutputTypes` where the codec types import is declared, and add `__parameterizedOutputTypes` to the pack metadata's type. `renderOutputType` is no longer used for such codecs: Mongo's vector codec no longer implements it, and a Mongo `defineContract` contract ignores it. Export the types the pack metadata names from its `/pack` entry, so an application that exports a contract can build declarations. The detection matches files that import a Mongo package and implement `renderOutputType`.
|
|
382
|
+
detection:
|
|
383
|
+
glob: "**/*.{ts,mts,cts}"
|
|
384
|
+
matches:
|
|
385
|
+
- '(?<![\s\S])(?=[\s\S]*@prisma/orm-(mongo|family-mongo|target-mongo)\b)[\s\S]*renderOutputType'
|
|
386
|
+
- id: mongo-model-storage-fields
|
|
387
|
+
summary: |
|
|
388
|
+
A MongoDB model's `fields` are keyed by field name, and `model.storage.fields` records the key each field is stored under: `MongoModelStorage` gains a required `fields: Record<string, { field: string }>`, with an entry for every field. `on.localFields`, `on.targetFields` and `discriminator.field` name fields; indexes, validators and execution default refs name stored names. Code that read `model.fields` keys as document keys reads stored names through the helpers `@internal/mongo-contract` exports: `ownStoredNamesOf`, `ownStoredNameOf`, `ownFieldStoredAs`, `hasOwnFieldStoredAs`, `ownEmbedStoredNamesOf`, `ownDocumentIdFieldOf`, `storedNamesOf`, `modelAndBasesOf`, `valueObjectStoredNamesOf` and `mongoModelsOf`, and at the type level `OwnStoredNameOf` and `OwnFieldStoredAs`. An embed relation is stored under its `storage.relations` entry, or its own name. A hand-built MongoDB contract or model storage type adds `fields`.
|
|
389
|
+
detection:
|
|
390
|
+
glob: "**/*.{ts,mts,cts,tsx,json}"
|
|
391
|
+
matches:
|
|
392
|
+
- 'MongoModelStorage|MongoModelDefinition'
|
|
393
|
+
- '"storage"\s*:\s*\{\s*(?:"collection"\s*:\s*"[^"]*"\s*)?\}'
|
|
394
|
+
- '(?<![\w$])storage\s*:\s*\{\s*(?:readonly\s+)?collection\s*:\s*[''"][^''"]*[''"]\s*;?\s*\}'
|
|
395
|
+
- id: mongo-validator-derivation-moves-to-mongo-contract
|
|
396
|
+
summary: |
|
|
397
|
+
The `FieldValueSets` type moves from `@internal/mongo-contract-psl` (`@prisma/orm-family-mongo/contract-psl`) to `@internal/mongo-contract` (`@prisma/orm-family-mongo/contract`). Extensions that author Mongo contracts through `defineContract(...)` or PSL need no change.
|
|
398
|
+
detection:
|
|
399
|
+
glob: "**/*.{ts,mts,cts}"
|
|
400
|
+
matches:
|
|
401
|
+
- 'import[^;]*\bFieldValueSets\b[^;]*from\s*[''"](?:@internal/mongo-contract-psl|@prisma/orm-family-mongo/contract-psl)[''"]'
|
|
402
|
+
- id: mongo-derive-json-schema-replaced-by-derive-collection-validators
|
|
403
|
+
summary: |
|
|
404
|
+
`deriveJsonSchema` and `derivePolymorphicJsonSchema` are removed. Call `deriveCollectionValidators` from `@internal/mongo-contract` (`@prisma/orm-family-mongo/contract`) instead. It returns the validator of each collection, keyed by collection name, and it is the validator a contract emits, including embedded models and variants.
|
|
405
|
+
detection:
|
|
406
|
+
glob: "**/*.{ts,mts,cts}"
|
|
407
|
+
matches:
|
|
408
|
+
- '\bderive(?:Polymorphic)?JsonSchema\b'
|
|
409
|
+
- id: psl-nocheck-removed
|
|
410
|
+
summary: |
|
|
411
|
+
The PSL attribute `@noCheck` no longer exists, and writing it in an extension's contract source is an unknown-attribute error. A list that allows null elements is now written `T?[]`. Replace `T[] @noCheck(elementNotNull)` with `T?[]`, delete `@noCheck(membership)`, and replace a bare `@noCheck` with both. Then re-emit the extension's bundled contract. The detection matches PSL files that use the attribute.
|
|
412
|
+
detection:
|
|
413
|
+
glob: "**/*.prisma"
|
|
414
|
+
matches:
|
|
415
|
+
- '@noCheck\b'
|
|
416
|
+
- id: ts-nocheck-method-removed
|
|
417
|
+
summary: |
|
|
418
|
+
The TypeScript field builder no longer has a `noCheck()` method. Replace `.many().noCheck('elementNotNull')` with `.many({ elementsNullable: true })`, delete `.noCheck('membership')`, and replace a bare `.noCheck()` with both. Then re-emit the extension's bundled contract. The detection matches TypeScript files that call the method.
|
|
419
|
+
detection:
|
|
420
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
421
|
+
matches:
|
|
422
|
+
- '\.noCheck\('
|
|
423
|
+
- id: stored-contracts-drop-nocheck
|
|
424
|
+
summary: |
|
|
425
|
+
A stored SQL contract that has a `noCheck` key on a column no longer loads. Run `scripts/remove-nocheck/remove-nocheck.ts` from the extension's package root. It removes the key from every stored contract the extension ships, its migration snapshots included, writes each PostgreSQL default in the form this release stores, and rewrites the hashes and references that change. Then re-emit the bundled contract.
|
|
426
|
+
detection:
|
|
427
|
+
glob: "**/*.json"
|
|
428
|
+
matches:
|
|
429
|
+
- '"noCheck"\s*:'
|
|
430
|
+
script: ./scripts/remove-nocheck/remove-nocheck.ts
|
|
431
|
+
- id: sqlite-contracts-name-datetime-and-json-data-types
|
|
432
|
+
summary: |
|
|
433
|
+
An extension that ships a SQLite contract space: a column whose codec is `sqlite/datetime@1` or `sqlite/json@1` names its own data type (`sqlite/datetime`, `sqlite/json`) instead of `sqlite/text`, and a datetime default or enum value is stored with exactly three fraction digits. The CLI refuses the old form. Run `scripts/data-type-values/data-type-values.ts` from the extension's package root, as the section of this name below describes. It rewrites the contract and its migration snapshots and their hashes. The storage hash changes, so tell the applications that use the extension to run `prisma db sign` after they upgrade.
|
|
434
|
+
detection:
|
|
435
|
+
glob: "**/*.json"
|
|
436
|
+
matches:
|
|
437
|
+
- '"codecId"\s*:\s*"sqlite/(?:datetime|json)@1"\s*,\s*"dataType"\s*:\s*"sqlite/text"'
|
|
438
|
+
script: ./scripts/data-type-values/data-type-values.ts
|
|
439
|
+
- id: mongo-contracts-record-stored-field-names
|
|
440
|
+
summary: |
|
|
441
|
+
An extension that ships a MongoDB contract space: a MongoDB contract records each field's stored name in `model.storage.fields`, and a contract without it is refused with `CONTRACT.VALIDATION_FAILED`. Re-emit the bundled contract, then run `scripts/mongo-field-storage-names/mongo-field-storage-names.ts` from the extension's package root to rewrite the migration snapshots, as the section of this name below describes. Storage hashes do not change.
|
|
442
|
+
detection:
|
|
443
|
+
glob: "**/*.json"
|
|
444
|
+
matches:
|
|
445
|
+
- '"storage"\s*:\s*\{\s*(?:"collection"\s*:\s*"[^"]*"\s*)?\}'
|
|
446
|
+
- '"storage"\s*:\s*\{\s*"collection"\s*:\s*"[^"]*"\s*,\s*"relations"'
|
|
447
|
+
script: ./scripts/mongo-field-storage-names/mongo-field-storage-names.ts
|
|
448
|
+
- id: date-time-interval-and-bytes-defaults-use-tags
|
|
449
|
+
summary: |
|
|
450
|
+
In the PSL source of an extension's contract, a date, time, interval or bytes default is written with its type's tag instead of a quoted string, such as `@default(timestamptz`2024-01-01T00:00:00Z`)` or `@default(bytea`\x0102`)`. `contract emit` refuses the quoted form and names the tag to write. The section of this name below lists every tag. The detection matches Prisma 8 schema files with a quoted default that looks like a date or an interval, or that sits on a date, time, interval or bytes column. It skips a quoted time such as `"12:30"` on a column whose type is a type alias, because a `String` default can look the same; `contract emit` names such a default.
|
|
451
|
+
detection:
|
|
452
|
+
glob: "**/*.prisma"
|
|
453
|
+
matches:
|
|
454
|
+
- '(?<![\s\S])\s*// *use +(?:prisma-8|prisma-next) *(?!\S)[\s\S]*@default\(\s*"(?:[+-]?\d{4,6}-\d{2}-\d{2}|-?P(?:\d|T\d)|[+-]?infinity")'
|
|
455
|
+
- '(?<![\s\S])\s*// *use +(?:prisma-8|prisma-next) *(?!\S)[\s\S]*\b(?:DateTime|Date|Time|Timetz|Timestamp|Timestamptz|Interval)\b[^\n]*@default\(\s*"'
|
|
456
|
+
- '(?<![\s\S])\s*// *use +(?:prisma-8|prisma-next) *(?!\S)[\s\S]*\bBytes\??[^\n]*@default\(\s*"'
|
|
457
|
+
- id: postgres-defaults-stored-in-another-spelling
|
|
458
|
+
summary: |
|
|
459
|
+
An extension that ships a PostgreSQL contract space: the CLI refuses a contract that an earlier release emitted when it stores a default in another spelling than its column's parameters give, for example `"1.5"` on `numeric(10,2)`. Run `scripts/remove-nocheck/remove-nocheck.ts` from the extension's package root (`stored-contracts-drop-nocheck`): it writes each stored default in the new form, migration snapshots included. Then re-emit the bundled contract. If the storage hash changes, tell the applications that use the extension to run `prisma db sign` after they upgrade.
|
|
460
|
+
script: ./scripts/remove-nocheck/remove-nocheck.ts
|
|
461
|
+
- id: client-functions-move-from-default-to-on-create
|
|
462
|
+
summary: |
|
|
463
|
+
In the PSL source of an extension's contract, `@default(uuid())`, `@default(cuid(2))`, `@default(ulid())` and `@default(nanoid())` are refused with `PSL_GENERATOR_IN_DEFAULT`; write `@onCreate(...)` instead. `scripts/default-generators-to-on-create/rewrite-default-generators.mjs` rewrites the files it is given. The contract does not change. The detection matches Prisma 8 schema files, those with the `// use prisma-8` directive, that write one of these functions in `@default`.
|
|
464
|
+
detection:
|
|
465
|
+
glob: "**/*.prisma"
|
|
466
|
+
matches:
|
|
467
|
+
- '(?<![\s\S])\s*// *use +(?:prisma-8|prisma-next) *(?!\S)[\s\S]*@default\(\s*(?:uuid|cuid|ulid|nanoid)\s*\('
|
|
468
|
+
script: ./scripts/default-generators-to-on-create/rewrite-default-generators.mjs
|
|
469
|
+
- id: setdefault-operation-class-derived
|
|
470
|
+
summary: |
|
|
471
|
+
On PostgreSQL, `this.setDefault` in `migration.ts` no longer takes `operationClass`. The operation is widening when the migration's start contract gives the column a default, and additive otherwise. `migration plan` no longer writes `operationClass` into the call. A `migration.ts` that passes it no longer type-checks; delete the option.
|
|
472
|
+
detection:
|
|
473
|
+
glob: "**/migration.ts"
|
|
474
|
+
matches:
|
|
475
|
+
- '\bsetDefault\(\{(?:(?!\bthis\.|\brawSql\s*\()[\s\S])*?\boperationClass\s*:'
|
|
476
|
+
- id: setdefault-has-no-postcheck
|
|
477
|
+
summary: |
|
|
478
|
+
On PostgreSQL, a `setDefault` operation no longer checks afterwards that the column has a default, so the runner no longer skips it when the column already has a different default. A package planned by 8.0.0-rc.15 or a later release before this one whose `migration.ts` has a hand-written `setDefault` that changes an existing default still carries the old check in `ops.json`; write its `ops.json` again before you apply it.
|
|
479
|
+
detection:
|
|
480
|
+
glob: "**/ops.json"
|
|
481
|
+
matches:
|
|
482
|
+
- 'verify column \\"(?:[^"\\]|\\.)*?\\" has a default'
|
|
483
|
+
- id: postgres-postcheck-create-table
|
|
484
|
+
summary: |
|
|
485
|
+
On PostgreSQL, the check that runs after `createTable` checks that the relation is a table, not a view, sequence or index of the same name. An `ops.json` written before this change keeps its old check, which the runner can find already true for an object of the same name with another definition, and then skip the operation. Run `migration.ts` again for each migration that is not applied yet.
|
|
486
|
+
detection:
|
|
487
|
+
glob: "**/ops.json"
|
|
488
|
+
matches:
|
|
489
|
+
- '"description": "create table \\"(?:[^"\\]|\\.)*?\\""(?:(?!"postcheck")[\s\S])*?"postcheck": \[\s*\{\s*"description": "verify table \\"(?:[^"\\]|\\.)*?\\" exists",\s*"sql": "SELECT \(?to_regclass\('
|
|
490
|
+
- id: postgres-postcheck-add-column
|
|
491
|
+
summary: |
|
|
492
|
+
On PostgreSQL, the check that runs after `addColumn` checks the column's type, and that it is NOT NULL when the column is declared NOT NULL. An `ops.json` written before this change keeps its old check, which the runner can find already true for an object of the same name with another definition, and then skip the operation. Run `migration.ts` again for each migration that is not applied yet.
|
|
493
|
+
detection:
|
|
494
|
+
glob: "**/ops.json"
|
|
495
|
+
matches:
|
|
496
|
+
- '"description": "verify column \\"(?:[^"\\]|\\.)*?\\" exists",[^{}]*\}\s*\]'
|
|
497
|
+
- id: postgres-postcheck-add-column-with-temporary-default
|
|
498
|
+
summary: |
|
|
499
|
+
On PostgreSQL, the check that runs after `addColumnWithTemporaryDefault` checks the column's type. An `ops.json` written before this change keeps its old check, which the runner can find already true for an object of the same name with another definition, and then skip the operation. Run `migration.ts` again for each migration that is not applied yet.
|
|
500
|
+
detection:
|
|
501
|
+
glob: "**/ops.json"
|
|
502
|
+
matches:
|
|
503
|
+
- 'has no default after temporary default removal",[^{}]*\}\s*\]'
|
|
504
|
+
- id: postgres-postcheck-add-required-column-to-empty-table
|
|
505
|
+
summary: |
|
|
506
|
+
On PostgreSQL, the check that runs after `addRequiredColumnToEmptyTable` checks the column's type. An `ops.json` written before this change keeps its old check, which the runner can find already true for an object of the same name with another definition, and then skip the operation. Run `migration.ts` again for each migration that is not applied yet.
|
|
507
|
+
detection:
|
|
508
|
+
glob: "**/ops.json"
|
|
509
|
+
matches:
|
|
510
|
+
- '"description": "verify column \\"(?:[^"\\]|\\.)*?\\" exists",[^{}]*\},\s*\{\s*"description": "verify column \\"(?:[^"\\]|\\.)*?\\" is NOT NULL",[^{}]*\}\s*\]'
|
|
511
|
+
- id: postgres-postcheck-create-index
|
|
512
|
+
summary: |
|
|
513
|
+
On PostgreSQL, the check that runs after `createIndex` checks that the relation is an index on the planned table, with the planned uniqueness, access method and columns in order, and with an expression and a predicate only where the call has them. An `ops.json` written before this change keeps its old check, which the runner can find already true for an object of the same name with another definition, and then skip the operation. Run `migration.ts` again for each migration that is not applied yet.
|
|
514
|
+
detection:
|
|
515
|
+
glob: "**/ops.json"
|
|
516
|
+
matches:
|
|
517
|
+
- '"description": "create index \\"(?:[^"\\]|\\.)*?\\"",(?:(?!"postcheck")[\s\S])*?"postcheck": \[\s*\{\s*"description": "verify index \\"(?:[^"\\]|\\.)*?\\" exists",'
|
|
518
|
+
- id: postgres-postcheck-rename-index
|
|
519
|
+
summary: |
|
|
520
|
+
On PostgreSQL, the check that runs after `renameIndex` also checks that no index has the old name any more. An `ops.json` written before this change keeps its old check, which the runner can find already true for an object of the same name with another definition, and then skip the operation. Run `migration.ts` again for each migration that is not applied yet.
|
|
521
|
+
detection:
|
|
522
|
+
glob: "**/ops.json"
|
|
523
|
+
matches:
|
|
524
|
+
- '"description": "rename index \\"(?:[^"\\]|\\.)*?\\" to \\"(?:[^"\\]|\\.)*?\\"",(?:(?!"postcheck")[\s\S])*?"postcheck": \[\s*\{\s*"description": "verify index \\"(?:[^"\\]|\\.)*?\\" exists",[^{}]*\}\s*\]'
|
|
525
|
+
- id: postgres-postcheck-add-primary-key
|
|
526
|
+
summary: |
|
|
527
|
+
On PostgreSQL, the check that runs after `addPrimaryKey` checks that the constraint is a primary key on the planned columns in order. An `ops.json` written before this change keeps its old check, which the runner can find already true for an object of the same name with another definition, and then skip the operation. Run `migration.ts` again for each migration that is not applied yet.
|
|
528
|
+
detection:
|
|
529
|
+
glob: "**/ops.json"
|
|
530
|
+
matches:
|
|
531
|
+
- '"description": "verify primary key \\"(?:[^"\\]|\\.)*?\\" exists"'
|
|
532
|
+
- id: postgres-postcheck-add-unique
|
|
533
|
+
summary: |
|
|
534
|
+
On PostgreSQL, the check that runs after `addUnique` checks that the constraint is a unique constraint on the planned columns in order. An `ops.json` written before this change keeps its old check, which the runner can find already true for an object of the same name with another definition, and then skip the operation. Run `migration.ts` again for each migration that is not applied yet.
|
|
535
|
+
detection:
|
|
536
|
+
glob: "**/ops.json"
|
|
537
|
+
matches:
|
|
538
|
+
- '"description": "add unique constraint \\"(?:[^"\\]|\\.)*?\\"",(?:(?!"postcheck")[\s\S])*?"postcheck": \[\s*\{\s*"description": "verify constraint \\"(?:[^"\\]|\\.)*?\\" exists",'
|
|
539
|
+
- id: postgres-postcheck-add-foreign-key
|
|
540
|
+
summary: |
|
|
541
|
+
On PostgreSQL, the check that runs after `addForeignKey` checks the constraint's columns, referenced table and columns in order, and its delete and update actions. An `ops.json` written before this change keeps its old check, which the runner can find already true for an object of the same name with another definition, and then skip the operation. Run `migration.ts` again for each migration that is not applied yet.
|
|
542
|
+
detection:
|
|
543
|
+
glob: "**/ops.json"
|
|
544
|
+
matches:
|
|
545
|
+
- '"description": "verify FK \\"(?:[^"\\]|\\.)*?\\" exists"'
|
|
546
|
+
- id: postgres-postcheck-add-check-constraint
|
|
547
|
+
summary: |
|
|
548
|
+
On PostgreSQL, the check that runs after `addCheckConstraint` checks that the constraint is a check constraint. An `ops.json` written before this change keeps its old check, which the runner can find already true for an object of the same name with another definition, and then skip the operation. Run `migration.ts` again for each migration that is not applied yet.
|
|
549
|
+
detection:
|
|
550
|
+
glob: "**/ops.json"
|
|
551
|
+
matches:
|
|
552
|
+
- '"description": "add check constraint \\"(?:[^"\\]|\\.)*?\\"",(?:(?!"postcheck")[\s\S])*?"postcheck": \[\s*\{\s*"description": "verify constraint \\"(?:[^"\\]|\\.)*?\\" exists",'
|
|
553
|
+
- id: postgres-postcheck-rename-constraint
|
|
554
|
+
summary: |
|
|
555
|
+
On PostgreSQL, the check that runs after `renameConstraint` also checks that no constraint has the old name any more. An `ops.json` written before this change keeps its old check, which the runner can find already true for an object of the same name with another definition, and then skip the operation. Run `migration.ts` again for each migration that is not applied yet.
|
|
556
|
+
detection:
|
|
557
|
+
glob: "**/ops.json"
|
|
558
|
+
matches:
|
|
559
|
+
- '"description": "rename (?:primary key|unique constraint|foreign key|check constraint) \\"(?:[^"\\]|\\.)*?\\" to \\"(?:[^"\\]|\\.)*?\\"",(?:(?!"postcheck")[\s\S])*?"postcheck": \[\s*\{\s*"description": "verify constraint \\"(?:[^"\\]|\\.)*?\\" exists",[^{}]*\}\s*\]'
|
|
560
|
+
- id: postgres-postcheck-create-rls-policy
|
|
561
|
+
summary: |
|
|
562
|
+
On PostgreSQL, the check that runs after `createRlsPolicy` checks the policy's command, roles and whether it is permissive. An `ops.json` written before this change keeps its old check, which the runner can find already true for an object of the same name with another definition, and then skip the operation. Run `migration.ts` again for each migration that is not applied yet.
|
|
563
|
+
detection:
|
|
564
|
+
glob: "**/ops.json"
|
|
565
|
+
matches:
|
|
566
|
+
- '"description": "create RLS policy \\"(?:[^"\\]|\\.)*?\\"",(?:(?!"postcheck")[\s\S])*?"postcheck": \[\s*\{\s*"description": "verify RLS policy \\"(?:[^"\\]|\\.)*?\\" exists",'
|
|
567
|
+
- id: postgres-postcheck-rename-rls-policy
|
|
568
|
+
summary: |
|
|
569
|
+
On PostgreSQL, the check that runs after `renameRlsPolicy` also checks that no policy has the old name any more; its precheck now also refuses a policy that already has the new name. An `ops.json` written before this change keeps its old check, which the runner can find already true for an object of the same name with another definition, and then skip the operation. Run `migration.ts` again for each migration that is not applied yet.
|
|
570
|
+
detection:
|
|
571
|
+
glob: "**/ops.json"
|
|
572
|
+
matches:
|
|
573
|
+
- '"description": "rename RLS policy \\"(?:[^"\\]|\\.)*?\\" to \\"(?:[^"\\]|\\.)*?\\"",(?:(?!"postcheck")[\s\S])*?"postcheck": \[\s*\{\s*"description": "verify RLS policy \\"(?:[^"\\]|\\.)*?\\" exists",[^{}]*\}\s*\]'
|
|
574
|
+
- id: postgres-postcheck-autoincrement-default
|
|
575
|
+
summary: |
|
|
576
|
+
On PostgreSQL, the check that runs after `setDefault` with `autoincrement()` also checks that the column owns the sequence of the planned name and that the sequence has the column's integer width. An `ops.json` written before this change keeps its old check, which the runner can find already true for an object of the same name with another definition, and then skip the operation. Run `migration.ts` again for each migration that is not applied yet.
|
|
577
|
+
detection:
|
|
578
|
+
glob: "**/ops.json"
|
|
579
|
+
matches:
|
|
580
|
+
- 'takes its default from an attached sequence",[^{}]*\}\s*\]'
|
|
581
|
+
- id: postgres-alter-column-type-unchanged-refused
|
|
582
|
+
summary: |
|
|
583
|
+
On PostgreSQL, `this.alterColumnType` with `using` now refuses, with `MIGRATION.ALTER_COLUMN_TYPE_USING_WITHOUT_TYPE_CHANGE`, a column the start contract, after the earlier renames in the migration, already gives the new type. Its check compares only the type, so the runner skipped the conversion. Write the conversion as a `dataTransform`.
|
|
584
|
+
detection:
|
|
585
|
+
glob: "**/migration.ts"
|
|
586
|
+
matches:
|
|
587
|
+
- '\balterColumnType\(\{(?:(?!\bthis\.)[\s\S])*?\busing\s*:'
|
|
588
|
+
- id: postgres-autoincrement-sequence-follows-column-type
|
|
589
|
+
summary: |
|
|
590
|
+
On PostgreSQL, changing the integer type of an `autoincrement()` column now also changes the sequence the column owns to the new width, and checks both afterwards. Before, a column widened from `int4` to `int8` kept an `integer` sequence, which stops at 2147483647. An `ops.json` written before this change has an `alterColumnType` without the sequence step, and an `alter type of "<column>"` step that does not name the new type; run `migration.ts` again for each migration that is not applied yet. For a database where such a migration is already applied, run `ALTER SEQUENCE … AS bigint` on the sequence `pg_get_serial_sequence` names yourself.
|
|
591
|
+
detection:
|
|
592
|
+
glob: "**/ops.json"
|
|
593
|
+
matches:
|
|
594
|
+
- '"description": "alter type of \\"(?:[^"\\]|\\.)*?\\"",(?:(?!"postcheck")[\s\S])*?"postcheck": \[\s*\{\s*"description": "verify column \\"(?:[^"\\]|\\.)*?\\" has type \\"(?:smallint|integer|bigint)\\""'
|
|
595
|
+
- id: sqlite-postchecks-check-full-definition
|
|
596
|
+
summary: |
|
|
597
|
+
On SQLite, the checks that let the runner skip an operation whose effect is already in place now check the whole definition. `createTable` checks every column's name, type, nullability and primary key position; `addColumn` checks the column's type and nullability; `createIndex` checks the index's table, ordered columns and uniqueness; `recreateTable` checks foreign key actions and `autoincrement()`. An `ops.json` written by an earlier release still carries the old checks; write it again before you apply it.
|
|
598
|
+
detection:
|
|
599
|
+
glob: "**/ops.json"
|
|
600
|
+
matches:
|
|
601
|
+
- '(?<![\s\S])(?![\s\S]*has exactly its columns)[\s\S]*"description":\s*"verify table \\"(?:[^"\\]|\\.)*\\" exists",\s*"sql":\s*"(?:[^"\\]|\\.)*sqlite_master'
|
|
602
|
+
- '(?<![\s\S])(?![\s\S]*\\" has type )[\s\S]*"description":\s*"verify column \\"(?:[^"\\]|\\.)*\\" exists",\s*"sql":\s*"(?:[^"\\]|\\.)*pragma_table_info'
|
|
603
|
+
- '(?<![\s\S])(?![\s\S]*\\" covers \()[\s\S]*"description":\s*"verify index \\"(?:[^"\\]|\\.)*\\" exists",\s*"sql":\s*"(?:[^"\\]|\\.)*sqlite_master'
|
|
604
|
+
- 'pragma_foreign_key_list\(''(?:[^''\\]|\\.)*''\) f WHERE f\.\\"table\\" = ''(?:[^''\\]|\\.)*'' GROUP BY'
|
|
605
|
+
- id: mongo-postchecks-check-full-definition
|
|
606
|
+
summary: |
|
|
607
|
+
On MongoDB, the checks that let the runner skip an operation whose effect is already in place now check the whole definition. `createIndex` checks every index option the planner tells indexes apart by, not only the keys and `unique: true`. `collMod` with a validator that is not only a `$jsonSchema` compares the whole validator. An `ops.json` written by an earlier release still carries the old checks; write it again before you apply it.
|
|
608
|
+
detection:
|
|
609
|
+
glob: "**/ops.json"
|
|
610
|
+
matches:
|
|
611
|
+
- '(?<![\s\S])(?![\s\S]*"field":\s*"sparse")[\s\S]*"description":\s*"index exists on '
|
|
612
|
+
- '(?<![\s\S])(?![\s\S]*"field":\s*"options\.validator)[\s\S]*"description":\s*"validator applied on '
|
|
613
|
+
- id: control-client-apply-takes-invocation
|
|
614
|
+
summary: |
|
|
615
|
+
`dbInit`, `dbUpdate` and `migrate` on a control client take a required `invocation` option: `{ cwd, configPath, dbGiven }`, where the commands an error's advice prints are run from, the `--config` they repeat, and whether they repeat `--db`. Pass `{ cwd: process.cwd(), configPath: undefined, dbGiven: false }` when nothing is run from a terminal. Their failures are now `CliStructuredError`s, so `DbInitFailure`, `DbUpdateFailure` and `MigrateFailure` are gone from `control-api`.
|
|
616
|
+
detection:
|
|
617
|
+
glob: "**/*.{ts,tsx,mts,cts}"
|
|
618
|
+
matches:
|
|
619
|
+
- '\.(?:dbInit|dbUpdate|migrate)\(\s*\{'
|
|
620
|
+
- '\b(?:DbInitFailure|DbUpdateFailure|MigrateFailure)(?:Code)?\b'
|
|
621
|
+
- id: runner-failures-report-own-codes
|
|
622
|
+
summary: |
|
|
623
|
+
A failed migration apply reports the runner's own code, such as `MIGRATION.SCHEMA_VERIFY_FAILED`, `MIGRATION.PRECHECK_FAILED`, `MIGRATION.POSTCHECK_FAILED` or `MIGRATION.EXECUTION_FAILED`, instead of `MIGRATION.RUNNER_FAILED` with `meta.runnerErrorCode`. `MIGRATION.RUNNER_FAILED` no longer exists. The facts move into typed `meta` keys: a failed schema check lists its issues in `meta.schemaIssues` (was `meta.issues`), and a failed check is `meta.failedCheck` (`operationId`, `phase`, `description`; was `operationId`, `phase`, `stepDescription`).
|
|
624
|
+
detection:
|
|
625
|
+
glob: "**/*.{ts,tsx,mts,cts,js,mjs,cjs,sh}"
|
|
626
|
+
matches:
|
|
627
|
+
- 'MIGRATION\.RUNNER_FAILED|\brunnerErrorCode\b'
|
|
628
|
+
---
|
|
629
|
+
|
|
630
|
+
# 8.0.0-rc.18 → 8.0.0-rc.19 — Extension author upgrade instructions
|
|
631
|
+
|
|
632
|
+
Run `client-takes-contract-value` first, on source files. An extension that ships a contract space then rewrites its stored contracts and contract source before it re-emits the bundled contract once; `Contract spaces an extension ships` lists the steps and their order. Make the other changes as their sections say.
|
|
633
|
+
|
|
634
|
+
## Clients
|
|
635
|
+
|
|
636
|
+
### `client-takes-contract-value`
|
|
637
|
+
|
|
638
|
+
A client, static entry or `mongoQuery()` no longer takes `contractJson`, and it needs no type argument. This applies to `postgres()`, `postgresServerless()`, `sqlite()`, `supabase()`, `mongo()`, `postgresStatic()`, `sqliteStatic()`, `mongoStatic()` and `mongoQuery()`. If your extension's code, examples or tests build one from emitted JSON, turn the JSON into a typed value with `contractFromJson<Contract>(json)` from the facade's `/static` entry (`@prisma/orm-postgres/static`, `@prisma/orm-sqlite/static`, `@prisma/orm-mongo/static`; Supabase uses the Postgres one) and pass `{ contract }`:
|
|
639
|
+
|
|
640
|
+
```ts
|
|
641
|
+
// Before
|
|
642
|
+
const db = postgres<Contract>({ contractJson, extensions: [myPack] });
|
|
643
|
+
|
|
644
|
+
// After
|
|
645
|
+
import { contractFromJson } from '@prisma/orm-postgres/static';
|
|
646
|
+
|
|
647
|
+
const db = postgres({ contract: contractFromJson<Contract>(contractJson), extensions: [myPack] });
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
A value is validated once however many clients use it, so build it once per module and share it. A contract written with `defineContract` is already a value: keep passing it as `{ contract }`.
|
|
651
|
+
|
|
652
|
+
`mongoQuery()` takes `{ contract }`, a value typed as the contract, and infers the type from it: `mongoQuery({ contract }).from('orders')`. A test that only needs the types can declare the value: `declare const contract: Contract;`.
|
|
653
|
+
|
|
654
|
+
#### Run the script
|
|
655
|
+
|
|
656
|
+
Run `node <path to this guide>/scripts/client-takes-contract-value/contract-from-json.ts <package root>`. The script reads source files with the TypeScript compiler from the package's `typescript`; if there is none, it changes nothing, says so and exits 1. It skips `node_modules`, `dist`, `build` and every directory whose name starts with a dot, such as `.git`, `.agents` or `.claude`; move a client in such a directory by hand. It moves each source file that passes `contractJson` to a client, static entry or `mongoQuery`: it adds the `contractFromJson` import, declares `export const contract = contractFromJson<Contract>(contractJson);` after the imports (`const contract` without `export` in a module with a default export, with a note), removes the type argument and passes `{ contract }`. Where the call's result is destructured with `contract` in it, as in a `migration.ts`, it removes `contract` from the destructuring. It prints each file it moved. It prints to stderr, with the reason, each file it did not move, and then exits 1: a test file, a file that already has another binding named `contract`, a file whose clients use different contracts, a file whose `contractJson` value uses a binding declared after the imports, a file whose `contractJson` value uses a parameter or local binding of the function that creates the client (pass `contract: contractFromJson<Contract>(<value>)` to that call instead), or a call it cannot read.
|
|
657
|
+
|
|
658
|
+
#### Then, by hand
|
|
659
|
+
|
|
660
|
+
1. **Tests.** Move each test that passes `contractJson` the same way: `postgres({ contract: contractFromJson<Contract>(contractJson) })`, or one `const contract = contractFromJson<Contract>(contractJson);` per file when several clients share it.
|
|
661
|
+
2. **Types.** The option types `PostgresOptionsWithContract`, `PostgresOptionsWithContractJson`, `PostgresServerlessOptionsWithContract`, `PostgresServerlessOptionsWithContractJson`, `SqliteOptionsWithContract`, `SqliteOptionsWithContractJson`, `MongoOptionsWithContract`, `MongoOptionsWithContractJson`, `SupabaseOptionsWithContract` and `SupabaseOptionsWithContractJson` are removed. Use `PostgresOptions<Contract>`, `PostgresServerlessOptions<Contract>`, `SqliteOptions<Contract>`, `MongoOptions<Contract>` or `SupabaseOptions<Contract>`.
|
|
662
|
+
3. **READMEs and JSDoc** that show a client called with `contractJson`: rewrite them to the new form.
|
|
663
|
+
|
|
664
|
+
### `collections-on-the-client`
|
|
665
|
+
|
|
666
|
+
This concerns extension packages whose code, examples or tests build a client and then an ORM by hand to reach custom collection classes. The client types (`PostgresClient`, `PostgresTransactionContext`, `PostgresServerlessClient`, `PostgresServerlessConnection`, `SqliteClient`, `SqliteTransactionContext`, `SupabaseDb`, `RoleBoundDb`, `ServiceRoleDb`) gained a second type parameter for the classes. It defaults to no classes, so existing references with one type argument keep their meaning.
|
|
667
|
+
|
|
668
|
+
`postgres()`, `postgresServerless()`, `sqlite()` and `supabase()` take an option, `collections`, with the same type `orm({ collections })` takes. The client types are inferred from it, and the classes reach every ORM the client offers:
|
|
669
|
+
|
|
670
|
+
```ts
|
|
671
|
+
// Before
|
|
672
|
+
import { orm } from '@prisma/orm-postgres/orm-client';
|
|
673
|
+
import { db } from './prisma/db';
|
|
674
|
+
|
|
675
|
+
export const posts = orm({
|
|
676
|
+
runtime: db.runtime(),
|
|
677
|
+
context: db.context,
|
|
678
|
+
collections: { Post: PostCollection },
|
|
679
|
+
}).public.Post;
|
|
680
|
+
|
|
681
|
+
// After, in the module that creates the client
|
|
682
|
+
export const db = postgres({ contract, url, collections: { Post: PostCollection } });
|
|
683
|
+
|
|
684
|
+
await db.orm.public.Post.published().all();
|
|
685
|
+
await db.transaction(async (tx) => tx.orm.public.Post.published().forUpdate().all());
|
|
686
|
+
```
|
|
687
|
+
|
|
688
|
+
1. Pass the classes as `collections` where the client is created. If the module that defines the classes imports the client's module, import only the `Contract` type there (`import type { Contract } from './contract.d'`), so the two modules do not import each other.
|
|
689
|
+
2. Delete the hand-built ORM client (for example a `createOrmClient(runtime)` helper) and every `orm({ runtime, context, collections })` that only existed to reach the classes. Use `db.orm` instead. On SQLite, `db.orm` is the model collections themselves: `db.orm.Post`.
|
|
690
|
+
3. A function that took a `runtime` only to build an ORM no longer needs it. Inside a transaction, pass `tx.orm`, which has the classes too.
|
|
691
|
+
4. On a serverless client, the classes are on every connection: `await using db = await postgres.connect({ url }); db.orm.public.Post.published()`.
|
|
692
|
+
5. On Supabase, the classes are on `asUser`, `asAnon` and `asServiceRole` clients. Supabase's internal `.supabase` ORM does not take them.
|
|
693
|
+
|
|
694
|
+
A type written with only the contract, such as `PostgresClient<Contract>`, still describes a client without classes and accepts a client created with them. To name a client with classes, give the second type parameter: `PostgresClient<Contract, { Post: typeof PostCollection }>`.
|
|
695
|
+
|
|
696
|
+
### `client-query-and-to-sql`
|
|
697
|
+
|
|
698
|
+
Every SQL client now runs a plan itself and renders the SQL a plan would send:
|
|
699
|
+
|
|
700
|
+
```ts
|
|
701
|
+
const plan = db.sql.public.post.select('id', 'title').limit(10).build();
|
|
702
|
+
console.log(db.toSql(plan)); // { sql: 'SELECT … LIMIT 10', params: [] }
|
|
703
|
+
for await (const row of db.query(plan)) console.log(row);
|
|
704
|
+
await db.execute(db.raw.sql`UPDATE post SET pinned = false`.affectedCount().build());
|
|
705
|
+
```
|
|
706
|
+
|
|
707
|
+
`db.query(plan)` and `db.execute(plan)` behave as `db.runtime().query(plan)` and `db.runtime().execute(plan)` do, and have the types `tx.query` and `tx.execute` have. Replace `db.runtime().query(` with `db.query(` and `db.runtime().execute(` with `db.execute(`. Keep `db.runtime()` where the code needs `connection()`, `close()` or `telemetry()`. On Supabase, call them on a role-bound client, as before.
|
|
708
|
+
|
|
709
|
+
`toSql(plan)` needs only the adapter and the contract, so it works with no database. `params` are the plan's values before codecs encode them. Middleware rewrites (`beforeCompile`) are not applied. A plan with `prepare` bind sites throws `RUNTIME.PREPARE_BIND_ON_ADHOC`, and a plan built for another contract throws `PLAN.HASH_MISMATCH`, as running it would.
|
|
710
|
+
|
|
711
|
+
The message of `RUNTIME.PREPARE_BIND_ON_ADHOC` changed; its code did not. Code that matches the old message text ("Ad-hoc execute received a bind-site slot") must match the code instead. The details of `PLAN.TARGET_MISMATCH` and `PLAN.HASH_MISMATCH` rename `runtimeTarget` to `contractTarget` and `runtimeStorageHash` to `contractStorageHash`, and their messages changed; match the codes.
|
|
712
|
+
|
|
713
|
+
`supabase()` no longer creates its `pg.Pool`, driver or runtimes when it is called. It creates them on the first query, so creating a client with a URL opens nothing. It is still `async` and still requires `jwtSecret` or `jwksUrl`. `close()` now ends only a pool the client created from `url`; a `pg.Pool` passed in with the `pg` option stays open, as with `postgres()`, and the caller ends it.
|
|
714
|
+
|
|
715
|
+
`postgres()`, `postgresServerless()`, `sqlite()` and `supabase()` take a new `mode` option, typed `RuntimeMode`. It is `'strict'` by default, which is how every client ran before. Under `'permissive'`, a `budgets()` violation whose severity is `'warn'` goes to `log.warn` and the query runs.
|
|
716
|
+
|
|
717
|
+
### `transaction-query-members`
|
|
718
|
+
|
|
719
|
+
Inside `db.transaction(async (tx) => …)`, `tx` now has the client's query members with the same types: `sql`, `orm` (with the client's custom collection classes), `raw`, `prepare`, `query`, `execute` and `toSql`. This holds for `postgres()`, every serverless connection, `sqlite()` and every Supabase role-bound client. A Supabase role-bound client gains `prepare`, and SQLite's `db.orm` gains `fragment`. A prepared statement runs on whatever it is given, so `ps.query(tx, params)` runs inside the transaction; `tx.prepare` lets code inside a transaction prepare without the outer client.
|
|
720
|
+
|
|
721
|
+
### Test doubles of client types
|
|
722
|
+
|
|
723
|
+
Code that only reads the client types needs no change for `client-query-and-to-sql` and `transaction-query-members`. Code that creates an object of one of them, for example a test double typed `PostgresClient<Contract>` or `PostgresTransactionContext<Contract>`, must add the new members:
|
|
724
|
+
|
|
725
|
+
| Type | New or changed members |
|
|
726
|
+
| --- | --- |
|
|
727
|
+
| `PostgresClient`, `PostgresServerlessConnection` (`@prisma/orm-postgres/runtime`, `/serverless`) | `query`, `execute`, `toSql` |
|
|
728
|
+
| `PostgresServerlessClient`, `PostgresStaticContext`, `PostgresStaticMembers` | `toSql` |
|
|
729
|
+
| `PostgresQueryMembers` | new: the query members a client and its transactions share, including `query`, `execute` and `toSql`; `PostgresClient`, `PostgresServerlessConnection` and `PostgresTransactionContext` extend it |
|
|
730
|
+
| `PostgresTransactionContext` (`@prisma/orm-postgres/runtime`) | `raw`, `prepare`, `toSql` |
|
|
731
|
+
| `SqliteClient` (`@prisma/orm-sqlite/runtime`) | `query`, `execute`, `toSql`; `orm` is `SqliteOrm`, which adds `fragment` |
|
|
732
|
+
| `SqliteStaticContext` | `toSql` |
|
|
733
|
+
| `SqliteStaticMembers` (`@prisma/orm-sqlite/runtime`) | new: the static context plus `stack`, which `SqliteClient` now extends |
|
|
734
|
+
| `SqliteQueryMembers` | new: the query members a client and its transactions share, including `query`, `execute` and `toSql`; `SqliteClient` and `SqliteTransactionContext` extend it |
|
|
735
|
+
| `SqliteTransactionContext` (`@prisma/orm-sqlite/runtime`) | `raw`, `prepare`, `toSql`; `orm` is `SqliteOrm`, the namespace's models plus `fragment` |
|
|
736
|
+
| `RoleBoundDb` (`@prisma/orm-extension-supabase/runtime`) | `prepare`, `toSql`, and the two prepared-statement entry points a statement's `query` and `execute` call; `query` and `execute` take the plan type every SQL client shares; it extends `PostgresQueryMembers`; `transaction` passes a `SupabaseTransactionContext` instead of a plain `TransactionContext` |
|
|
737
|
+
| `ServiceRoleDb` (`@prisma/orm-extension-supabase/runtime`) | `toSql`; `query` and `execute` take the plan type every SQL client shares |
|
|
738
|
+
| `SupabaseTransactionContext` | new; has `toSql` |
|
|
739
|
+
| `SupabaseInternalDb` (the service role's `supabase` member) | `toSql`, over the Supabase contract |
|
|
740
|
+
| `OrmClientRootMembers` (ORM client) | newly exported: the members of the ORM client beside its namespaces, today `fragment` |
|
|
741
|
+
| `PrepareMember` (ORM client) | newly exported: the `prepare` member a client and its transactions offer |
|
|
742
|
+
|
|
743
|
+
A hand-built `RoleBoundDb`, such as a test double, must also implement the two prepared-statement entry points, keyed by the symbols `preparedStatementQuery` and `preparedStatementExecute`. Import them from `@prisma/orm-postgres/family-runtime/internal/prepared-query` (or `@prisma/orm-family-sql/runtime/internal/prepared-query`). Like every `internal/` entry, it can change without notice.
|
|
744
|
+
|
|
745
|
+
A callback typed to take a plain `TransactionContext` still compiles where a transaction context is passed, because each new context type extends it.
|
|
746
|
+
|
|
747
|
+
## Clients start their own activities, and ORM calls are activities
|
|
748
|
+
|
|
749
|
+
The runtime's middleware tree now has a third kind of activity: one a client starts for an act the runtime would not otherwise see. A client starts it with `startActivityOn(queryable, activity)` and sends statements through the returned handle. A middleware can supply such an activity's result through the new `intercept.onActivity` handler. Each SQL ORM terminal method is one such activity, of kind `orm-call`. Its statements, its own transaction (`handle.transaction()`) and the read-back after a nested write are its children, and the annotations a `configure` callback records are on the call.
|
|
750
|
+
|
|
751
|
+
### `runtime-activity-is-activity`
|
|
752
|
+
|
|
753
|
+
Replace every `RuntimeActivity` with `Activity`, imported from the same module. There is no alias:
|
|
754
|
+
|
|
755
|
+
```ts
|
|
756
|
+
// before
|
|
757
|
+
import type { RuntimeActivity } from '@prisma/orm-framework/components/runtime';
|
|
758
|
+
async activityStarted(activity: RuntimeActivity, ctx) {}
|
|
759
|
+
|
|
760
|
+
// after
|
|
761
|
+
import type { Activity } from '@prisma/orm-framework/components/runtime';
|
|
762
|
+
async activityStarted(activity: Activity, ctx) {}
|
|
763
|
+
```
|
|
764
|
+
|
|
765
|
+
### `activity-includes-client-activities`
|
|
766
|
+
|
|
767
|
+
`Activity` always includes `ClientActivity`, whose kind contains a hyphen. A hook that rules out `'transaction'` and then reads statement fields stops compiling. Test for the kind you handle instead:
|
|
768
|
+
|
|
769
|
+
```ts
|
|
770
|
+
// before
|
|
771
|
+
if (result.kind === 'transaction') return;
|
|
772
|
+
record(result.latencyMs);
|
|
773
|
+
|
|
774
|
+
// after
|
|
775
|
+
if (result.kind !== 'statement') return;
|
|
776
|
+
record(result.latencyMs);
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
A middleware that sees a kind it does not know should ignore it rather than fail.
|
|
780
|
+
|
|
781
|
+
### `start-a-client-activity`
|
|
782
|
+
|
|
783
|
+
An extension can start an activity for an act of its own, such as a report that sends several statements, so that middleware observe it, finalize it and can serve it from a cache.
|
|
784
|
+
|
|
785
|
+
**Dependencies.** `startActivityOn`, `planContentHashOn` and the types their signatures name, such as `StartActivity`, `ClientActivity`, `ClientActivityKind` and `ActivityInterceptResult`, are in `@prisma/orm-family-sql/runtime`. The registry, `ClientActivityRegistry`, is in `@prisma/orm-framework/components/runtime`, which also has the types. An application or extension that uses `postgres()` already depends on `@prisma/orm-postgres`, which re-exports both as `@prisma/orm-postgres/components/runtime` and `@prisma/orm-postgres/family-runtime`. Augment `ClientActivityRegistry` through the entry that exports it, `@prisma/orm-framework/components/runtime` or `@prisma/orm-postgres/components/runtime`. Augmenting it through `@prisma/orm-family-sql/runtime` or `@prisma/orm-postgres/family-runtime` registers nothing, and TypeScript reports no error.
|
|
786
|
+
|
|
787
|
+
**Register the kind.** A client kind contains a hyphen; a kind without one is rejected with `RUNTIME.ACTIVITY_KIND_RESERVED`. Registering the result type is optional. The file that augments the entry must also import from it, or TypeScript reports that the module cannot be found:
|
|
788
|
+
|
|
789
|
+
```ts
|
|
790
|
+
import type { ClientActivityResult } from '@prisma/orm-postgres/components/runtime';
|
|
791
|
+
|
|
792
|
+
declare module '@prisma/orm-postgres/components/runtime' {
|
|
793
|
+
interface ClientActivityRegistry {
|
|
794
|
+
'report-run': { result: { readonly emails: readonly string[] } };
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
export type ReportResult = ClientActivityResult<'report-run'>;
|
|
799
|
+
```
|
|
800
|
+
|
|
801
|
+
The registry types the handle side only: `call.intercepted.result` and `call.end({ result })`. In middleware hooks the result of a client activity is `unknown`, even after `result.kind === 'report-run'`, because the hook types must accept unregistered kinds; check or cast the value there.
|
|
802
|
+
|
|
803
|
+
**Start, use and end it.** Pass a function that derives the content hash from the plan with `planContentHashOn`. The runtime calls it only when a middleware calls `activity.contentHash()`, and once per activity. It equals the digest `ctx.contentHash(exec)` returns for the statement's execution plan only when `beforeCompile` gives the same result for the plan in both places, no `beforeEncode` hook changes the parameters, and the codecs encode deterministically. (For `planContentHashOn`, `beforeCompile` runs with the scope and parent of the queryable it is called on and with fresh state, so on the runtime itself it has no parent. For the statement, it runs beneath the handle, with the state its `activityStarted` hooks wrote.) A cache should key on the activity's own content hash and not rely on the two being equal. End every handle, in a `finally`, or `close()` waits for it forever:
|
|
804
|
+
|
|
805
|
+
```ts
|
|
806
|
+
import { planContentHashOn, startActivityOn } from '@prisma/orm-postgres/family-runtime';
|
|
807
|
+
import type { SqlQueryPlan } from '@prisma/orm-postgres/relational-core/plan';
|
|
808
|
+
import type { PostgresClient } from '@prisma/orm-postgres/runtime';
|
|
809
|
+
|
|
810
|
+
async function runReport(db: PostgresClient<Contract>, plan: SqlQueryPlan<{ email: string }>) {
|
|
811
|
+
const runtime = db.runtime();
|
|
812
|
+
const call = await startActivityOn(runtime, {
|
|
813
|
+
kind: 'report-run',
|
|
814
|
+
contentHash: () => planContentHashOn(runtime, plan),
|
|
815
|
+
});
|
|
816
|
+
let outcome: 'succeeded' | 'failed' = 'failed';
|
|
817
|
+
let result: { readonly emails: readonly string[] } | undefined;
|
|
818
|
+
try {
|
|
819
|
+
if (call.intercepted) {
|
|
820
|
+
outcome = 'succeeded';
|
|
821
|
+
return call.intercepted.result.emails;
|
|
822
|
+
}
|
|
823
|
+
const rows = await call.query(plan).toArray();
|
|
824
|
+
result = { emails: rows.map((row) => row.email) };
|
|
825
|
+
outcome = 'succeeded';
|
|
826
|
+
return result.emails;
|
|
827
|
+
} finally {
|
|
828
|
+
await call.end({ outcome, ...(result === undefined ? {} : { result }) });
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
```
|
|
832
|
+
|
|
833
|
+
Statements sent through `call` are the activity's children. `call.transaction()` starts a transaction beneath it, on a connection it owns; it is absent when the handle was opened under a transaction. `startActivity` on the handle nests another activity.
|
|
834
|
+
|
|
835
|
+
**Serve it from middleware.** `intercept.onActivity(activity: ClientActivity, ctx)` runs after `activityStarted`. The first handler that returns `{ result }` wins, and the handle's `intercepted` is set. The ended result carries `source: 'middleware'` when the client then ends without a result:
|
|
836
|
+
|
|
837
|
+
```ts
|
|
838
|
+
import type { SqlMiddleware } from '@prisma/orm-postgres/family-runtime';
|
|
839
|
+
|
|
840
|
+
const served = new Map<string, unknown>();
|
|
841
|
+
|
|
842
|
+
const reportCache: SqlMiddleware = {
|
|
843
|
+
name: 'report-cache',
|
|
844
|
+
familyId: 'sql',
|
|
845
|
+
intercept: {
|
|
846
|
+
async onActivity(activity) {
|
|
847
|
+
if (activity.kind !== 'report-run') return undefined;
|
|
848
|
+
const hit = served.get(await activity.contentHash());
|
|
849
|
+
return hit === undefined ? undefined : { result: hit };
|
|
850
|
+
},
|
|
851
|
+
},
|
|
852
|
+
async activityEnded(activity, result) {
|
|
853
|
+
if (activity.kind !== 'report-run' || result.kind !== 'report-run') return;
|
|
854
|
+
if (result.outcome === 'succeeded' && result.source === 'client' && result.result !== undefined) {
|
|
855
|
+
served.set(await activity.contentHash(), result.result);
|
|
856
|
+
}
|
|
857
|
+
},
|
|
858
|
+
};
|
|
859
|
+
```
|
|
860
|
+
|
|
861
|
+
### `orm-annotations-on-the-call`
|
|
862
|
+
|
|
863
|
+
The statements an ORM call sends carry only the reserved keys the ORM sets. A middleware that reads an ORM annotation from a statement plan (`handle.read(plan)` or `plan.meta.annotations`) finds nothing. Read it from the call, in `activityStarted(activity)` or `intercept.onActivity(activity)`:
|
|
864
|
+
|
|
865
|
+
```ts
|
|
866
|
+
const audit: SqlMiddleware = {
|
|
867
|
+
name: 'audit',
|
|
868
|
+
familyId: 'sql',
|
|
869
|
+
async activityStarted(activity) {
|
|
870
|
+
if (activity.kind !== 'orm-call') return;
|
|
871
|
+
const actor = auditAnnotation.read(activity);
|
|
872
|
+
if (actor) log(actor);
|
|
873
|
+
},
|
|
874
|
+
};
|
|
875
|
+
```
|
|
876
|
+
|
|
877
|
+
A middleware can answer the call through `intercept.onActivity`. The value must have the shape the terminal method returns, or the ORM rejects with `ORM.INTERCEPTED_RESULT_INVALID`.
|
|
878
|
+
|
|
879
|
+
### `cache-store-holds-cached-values`
|
|
880
|
+
|
|
881
|
+
A cache store for `@internal/middleware-cache` holds `CachedValue`, which is `{ kind: 'statement-rows', rows }` or `{ kind: 'call-result', result }`, instead of `CachedRows`. `CacheStore` and `CacheEntry` default their value type to `CachedValue`, and `createCacheMiddleware` accepts only a `CacheStore<TMeta, CachedValue>`:
|
|
882
|
+
|
|
883
|
+
```ts
|
|
884
|
+
import type { CachedValue, CacheStore } from '@internal/middleware-cache';
|
|
885
|
+
|
|
886
|
+
const store: CacheStore<unknown, CachedValue> = {
|
|
887
|
+
// get, set and unset as before; value is now { kind: 'statement-rows', rows } or { kind: 'call-result', result }
|
|
888
|
+
};
|
|
889
|
+
```
|
|
890
|
+
|
|
891
|
+
`get` must give back a value equivalent to the one `set` was given, `kind` included. An ORM call's result holds decoded values such as `Date`, `bigint`, Temporal values and extension class instances, so a store that serializes needs a serializer that rebuilds them; JSON does not. `createInMemoryCacheStore` takes only the meta type now and always holds `CachedValue`: drop its second type argument.
|
|
892
|
+
|
|
893
|
+
### Activity sources on connections, runtimes and queryables
|
|
894
|
+
|
|
895
|
+
Activities start through an `activitySource` member of a queryable. The member is keyed by a symbol, so the public queryable types do not show it, and `startActivityOn` and `planContentHashOn` read it. The SQL ORM starts its `orm-call` activity on the queryable it holds, through this member only, and sends every statement through the activity's handle. A terminal method on a queryable without an activity source fails with `ORM.ACTIVITY_SOURCE_MISSING`: streaming terminals throw when called, and the others reject.
|
|
896
|
+
|
|
897
|
+
#### `runtime-connections-carry-an-activity-source`
|
|
898
|
+
|
|
899
|
+
Inside a `SqlRuntimeBase` subclass, a connection-like object over a raw connection gets its activity members from the base class. Add `ActivitySourceTarget` to the object's declared type. The public `RuntimeConnection` type does not require the member.
|
|
900
|
+
|
|
901
|
+
```ts
|
|
902
|
+
const session: RoleSession & TransactionStartTarget & ActivitySourceTarget = {
|
|
903
|
+
[transactionStart]: createTransactionStart(),
|
|
904
|
+
[activitySource]: self.connectionActivitySource(conn, () => session),
|
|
905
|
+
// query, execute, transaction, release, destroy as before
|
|
906
|
+
};
|
|
907
|
+
```
|
|
908
|
+
|
|
909
|
+
`activitySource` and `ActivitySourceTarget` come from `@prisma/orm-family-sql/runtime`. `transactionStart`, `createTransactionStart` and `TransactionStartTarget` still come from `@prisma/orm-family-sql/runtime/internal/prepared-query`.
|
|
910
|
+
|
|
911
|
+
#### `orm-runtime-objects-carry-an-activity-source`
|
|
912
|
+
|
|
913
|
+
`db.runtime()` passed straight to `orm()` already carries an activity source. A facade, such as `postgres()`, that builds its own runtime object for the ORM, such as one that looks up its runtime on every call, gives it the member:
|
|
914
|
+
|
|
915
|
+
```ts
|
|
916
|
+
import { activitySource, delegatingActivitySource } from '@prisma/orm-family-sql/runtime';
|
|
917
|
+
import { orm } from '@prisma/orm-postgres/orm-client';
|
|
918
|
+
|
|
919
|
+
const client = orm({
|
|
920
|
+
runtime: {
|
|
921
|
+
query: (plan) => getRuntime().query(plan),
|
|
922
|
+
execute: (plan) => getRuntime().execute(plan),
|
|
923
|
+
connection: () => getRuntime().connection(),
|
|
924
|
+
[activitySource]: delegatingActivitySource(() => getRuntime()),
|
|
925
|
+
},
|
|
926
|
+
context,
|
|
927
|
+
});
|
|
928
|
+
```
|
|
929
|
+
|
|
930
|
+
Do the same for the ORM object inside `db.transaction(fn)`, with `delegatingActivitySource(() => txCtx)`. Do not add plain `startActivity` or `planContentHash` members instead: `findActivitySource` and `startActivityOn` read only the `activitySource` member, so an object with only the plain members starts no activity.
|
|
931
|
+
|
|
932
|
+
If the facade sends its statements through sessions of its own, such as role-bound sessions, the activity's statements and transaction must go through them too. Give an activity source that does so. The plain runtime's source would run the activity's statements without the session.
|
|
933
|
+
|
|
934
|
+
#### `queryable-carries-the-activity-source`
|
|
935
|
+
|
|
936
|
+
A wrapper that copies a runtime, connection or transaction to intercept its `query` and `execute`, for example to record plans, also copies the `[activitySource]` member, so ORM statements bypass the wrapper. Wrap the activity source too: return a source whose `startActivity` wraps each handle the same way, including the transaction its `transaction()` returns. A custom queryable passed to the ORM must carry an activity source. A test stub can use `delegatingActivitySource(() => realRuntime)`, or a source whose handles send their statements to the stub.
|
|
937
|
+
|
|
938
|
+
### Pass a parent when beginning or starting a transaction
|
|
939
|
+
|
|
940
|
+
#### `begin-transaction-on-takes-a-parent`
|
|
941
|
+
|
|
942
|
+
`SqlRuntimeBase.beginTransactionOn(connection, owner)` takes a third argument, `parent`: the activity the transaction starts beneath, or `undefined`. Pass `undefined` where you began a transaction before:
|
|
943
|
+
|
|
944
|
+
```ts
|
|
945
|
+
// before
|
|
946
|
+
return self.beginTransactionOn(conn, session);
|
|
947
|
+
// after
|
|
948
|
+
return self.beginTransactionOn(conn, session, undefined);
|
|
949
|
+
```
|
|
950
|
+
|
|
951
|
+
#### `transaction-activity-takes-a-parent`
|
|
952
|
+
|
|
953
|
+
`startTransactionActivity` requires `parent`:
|
|
954
|
+
|
|
955
|
+
```ts
|
|
956
|
+
// before
|
|
957
|
+
await startTransactionActivity({ middleware, context, holdFinishedChildren });
|
|
958
|
+
// after
|
|
959
|
+
await startTransactionActivity({ middleware, context, parent: undefined, holdFinishedChildren });
|
|
960
|
+
```
|
|
961
|
+
|
|
962
|
+
An `ActivityParent` you implement yourself has `acceptsChildren()`, and its `adopt(child)` returns an `ActivityChildSlot` (`statementFailed()`, `ended(own)`, `transactionAcceptsChildren()`) instead of an end callback. `ActivityParent.activity` is an `ActivityBase`. A transaction stops accepting children with `stopAcceptingChildren()`, and adopting beneath a parent that no longer accepts children throws `RUNTIME.ACTIVITY_NOT_ACCEPTING_CHILDREN` instead of an internal error. Most runtimes only pass the parent they were given to `streamStatement`, `executeStatement`, `startTransactionActivity` or `startClientActivity` and need no change.
|
|
963
|
+
|
|
964
|
+
## `aggregate-operation-using-reserved`
|
|
965
|
+
|
|
966
|
+
A collection's new `using` member holds the collection methods that packages contribute for the model. Aggregate operations become reducer methods on the same collection, so a contributed aggregate operation named `using` would collide with it. `orm()` refuses such an operation when the client is built, with `ORM.AGGREGATE_OPERATION_RESERVED`, as it refuses `with` and `fragment`. Rename the operation in the extension's aggregate descriptors, and in the operation types the extension's contracts reference.
|
|
967
|
+
|
|
968
|
+
## Codecs read wire values and data type values
|
|
969
|
+
|
|
970
|
+
### `codecs-read-wire-and-data-type-values`
|
|
971
|
+
|
|
972
|
+
A codec converts between three forms of a value: the application's value, the value the database driver sends and returns (the wire value), and the value a contract stores, now a `DataTypeValue` of the codec's data type. Four methods replace the old four:
|
|
973
|
+
|
|
974
|
+
| Before | After | Converts |
|
|
975
|
+
| --- | --- | --- |
|
|
976
|
+
| `encode(value, ctx)` | `toWire(value, ctx)` | application value to wire value |
|
|
977
|
+
| `decode(wire, ctx)` | `fromWire(wire, ctx)` | wire value to application value |
|
|
978
|
+
| `encodeJson(value)` | `toDataTypeValue(value)` | application value to stored value |
|
|
979
|
+
| `decodeJson(json)` | `fromDataTypeValue(value)` | stored value to application value |
|
|
980
|
+
|
|
981
|
+
`toDataTypeValue` returns a `DataTypeValue`, and `fromDataTypeValue` receives one; its `value` is the JSON the contract stores. The data type has already read that JSON with its `read` function under the column's parameters, so `fromDataTypeValue` does not check it again. A codec builds the value it hands over with `this.dataTypeValueOf(json)`, which calls the data type's `valueFrom` and so refuses JSON the type does not hold. To make that possible, the codec's constructor passes its data type and its parameters to `CodecImpl`:
|
|
982
|
+
|
|
983
|
+
```ts
|
|
984
|
+
// before
|
|
985
|
+
export class PgVectorCodec extends CodecImpl</* … */> {
|
|
986
|
+
constructor(descriptor: AnyCodecDescriptor, length: number) {
|
|
987
|
+
super(descriptor);
|
|
988
|
+
this.length = length;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
async encode(value: number[], _ctx: CodecCallContext): Promise<string> {
|
|
992
|
+
this.assertVector(value, 'RUNTIME.ENCODE_FAILED');
|
|
993
|
+
return `[${value.join(',')}]`;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
async decode(wire: string, _ctx: CodecCallContext): Promise<number[]> {
|
|
997
|
+
return parseVector(wire);
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
encodeJson(value: number[]): JsonValue {
|
|
1001
|
+
this.assertVector(value, 'RUNTIME.ENCODE_FAILED');
|
|
1002
|
+
return [...value];
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
decodeJson(json: JsonValue): number[] {
|
|
1006
|
+
if (!Array.isArray(json) || json.length !== this.length) return this.refuseJson(json);
|
|
1007
|
+
return json.map(Number);
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
// after
|
|
1012
|
+
import type { DataTypeValue } from '@prisma/orm-framework/components/codec';
|
|
1013
|
+
import { pgvectorVector } from './data-types';
|
|
1014
|
+
|
|
1015
|
+
export class PgVectorCodec extends CodecImpl</* … */> {
|
|
1016
|
+
constructor(descriptor: AnyCodecDescriptor, length: number) {
|
|
1017
|
+
super(descriptor, pgvectorVector, { length });
|
|
1018
|
+
this.length = length;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
async toWire(value: number[], _ctx: CodecCallContext): Promise<string> {
|
|
1022
|
+
this.assertVector(value, 'RUNTIME.ENCODE_FAILED');
|
|
1023
|
+
return `[${value.join(',')}]`;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
async fromWire(wire: string, _ctx: CodecCallContext): Promise<number[]> {
|
|
1027
|
+
return parseVector(wire);
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
fromDataTypeValue(value: DataTypeValue<readonly number[]>): number[] {
|
|
1031
|
+
return [...value.value];
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
toDataTypeValue(input: number[]): DataTypeValue {
|
|
1035
|
+
this.assertVector(input, 'RUNTIME.ENCODE_FAILED');
|
|
1036
|
+
return this.dataTypeValueOf([...input]);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
```
|
|
1040
|
+
|
|
1041
|
+
A codec without parameters passes only its data type: `super(descriptor, pgJsonb)`. A descriptor whose codec takes parameters passes them from `factory`:
|
|
1042
|
+
|
|
1043
|
+
```ts
|
|
1044
|
+
// before
|
|
1045
|
+
override factory(_params: GeometryParams) {
|
|
1046
|
+
return () => new PostgisGeometryCodec(this);
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
// after
|
|
1050
|
+
override factory(params: GeometryParams) {
|
|
1051
|
+
return () => new PostgisGeometryCodec(this, params ?? {});
|
|
1052
|
+
}
|
|
1053
|
+
```
|
|
1054
|
+
|
|
1055
|
+
`DataTypeValue`, `DataTypeReader` and `refuseJsonValue` are exported from `@prisma/orm-framework/components/codec`, beside `CodecImpl`.
|
|
1056
|
+
|
|
1057
|
+
A Mongo codec made with `mongoCodec()` from `@prisma/orm-family-mongo/codec` takes the four options under the new names, and names its data type in a required `dataType` option, with the column's parameters in an optional `params`. Its `toDataTypeValue` returns a `DataTypeValue` too, which it builds with `dataType.valueFrom(json, params)`. It may be left out when the application value is JSON, and `fromDataTypeValue` may be left out only when the application type is exactly `JsonValue`. Declare the data type with `mongoDataType` from `@prisma/orm-family-mongo/contract/data-type`, and register it in the pack's `dataTypes` beside the codec:
|
|
1058
|
+
|
|
1059
|
+
```ts
|
|
1060
|
+
// before
|
|
1061
|
+
import { Long } from 'bson';
|
|
1062
|
+
import { mongoCodec } from '@prisma/orm-family-mongo/codec';
|
|
1063
|
+
import { decodeJsonString } from '@prisma/orm-framework/components/codec';
|
|
1064
|
+
import type { JsonValue } from '@prisma/orm-framework/contract/types';
|
|
1065
|
+
|
|
1066
|
+
export const moneyCodec = mongoCodec({
|
|
1067
|
+
typeId: 'acme/money@1',
|
|
1068
|
+
encode: (value: bigint) => Long.fromBigInt(value),
|
|
1069
|
+
decode: (wire: Long) => wire.toBigInt(),
|
|
1070
|
+
encodeJson: (value: bigint) => value.toString(),
|
|
1071
|
+
decodeJson: (json: JsonValue) => BigInt(decodeJsonString('acme/money@1', json)),
|
|
1072
|
+
});
|
|
1073
|
+
|
|
1074
|
+
// after
|
|
1075
|
+
import { Long } from 'bson';
|
|
1076
|
+
import { mongoCodec } from '@prisma/orm-family-mongo/codec';
|
|
1077
|
+
import { mongoDataType } from '@prisma/orm-family-mongo/contract/data-type';
|
|
1078
|
+
import { type DataTypeValue, readJsonMatching } from '@prisma/orm-framework/components/codec';
|
|
1079
|
+
|
|
1080
|
+
export const acmeMoney = mongoDataType('acme/money', {
|
|
1081
|
+
bsonTypes: ['long'],
|
|
1082
|
+
read: (json) => readJsonMatching('acme/money', json, /^-?\d+$/, 'decimal integer text'),
|
|
1083
|
+
});
|
|
1084
|
+
|
|
1085
|
+
export const moneyCodec = mongoCodec({
|
|
1086
|
+
typeId: 'acme/money@1',
|
|
1087
|
+
dataType: acmeMoney,
|
|
1088
|
+
toWire: (value: bigint) => Long.fromBigInt(value),
|
|
1089
|
+
fromWire: (wire: Long) => wire.toBigInt(),
|
|
1090
|
+
toDataTypeValue: (value: bigint) => acmeMoney.valueFrom(value.toString(), {}),
|
|
1091
|
+
fromDataTypeValue: (value: DataTypeValue<string>) => BigInt(value.value),
|
|
1092
|
+
});
|
|
1093
|
+
```
|
|
1094
|
+
|
|
1095
|
+
### `data-types-own-parameter-limits`
|
|
1096
|
+
|
|
1097
|
+
A data type now reads every value a contract stores, with a `read` function that receives the JSON and the column's parameters. It returns the JSON when the type holds it and refuses it with `refuseJsonValue` when it does not. `read` is required: a data type that declared none before declares one now. It replaces `toCanonicalForm`, on the data type or on a codec descriptor, and the checks a codec made in `decodeJson` against its parameters move into it:
|
|
1098
|
+
|
|
1099
|
+
```ts
|
|
1100
|
+
// before
|
|
1101
|
+
export const pgvectorVector = sqlDataType('pgvector/vector', {
|
|
1102
|
+
params: pgvectorVectorParams,
|
|
1103
|
+
texts: [{ text: 'vector({length})', written: true, catalog: true }],
|
|
1104
|
+
toCanonicalForm: vectorCanonicalForm,
|
|
1105
|
+
});
|
|
1106
|
+
|
|
1107
|
+
// after
|
|
1108
|
+
const readVector: DataTypeReader = (json, params) => {
|
|
1109
|
+
const length = typeof params['length'] === 'number' ? params['length'] : undefined;
|
|
1110
|
+
const expected =
|
|
1111
|
+
length === undefined ? 'an array of finite numbers' : `an array of ${length} finite numbers`;
|
|
1112
|
+
if (!Array.isArray(json) || (length !== undefined && json.length !== length)) {
|
|
1113
|
+
return refuseJsonValue('pgvector/vector', expected, json);
|
|
1114
|
+
}
|
|
1115
|
+
if (!json.every(isFiniteNumber)) return refuseJsonValue('pgvector/vector', expected, json);
|
|
1116
|
+
return json;
|
|
1117
|
+
};
|
|
1118
|
+
|
|
1119
|
+
export const pgvectorVector = sqlDataType('pgvector/vector', {
|
|
1120
|
+
params: pgvectorVectorParams,
|
|
1121
|
+
read: readVector,
|
|
1122
|
+
texts: [{ text: 'vector({length})', written: true, catalog: true }],
|
|
1123
|
+
});
|
|
1124
|
+
```
|
|
1125
|
+
|
|
1126
|
+
A data type that had neither `toCanonicalForm` nor parameter checks gets a `read` that accepts the JSON it stores, as PostGIS's geometry now reads HEXEWKB text:
|
|
1127
|
+
|
|
1128
|
+
```ts
|
|
1129
|
+
// before
|
|
1130
|
+
export const postgisGeometry = sqlDataType('postgis/geometry', { params, texts });
|
|
1131
|
+
|
|
1132
|
+
// after
|
|
1133
|
+
const readGeometry: DataTypeReader = (json, params) => {
|
|
1134
|
+
const hex = readJsonMatching('postgis/geometry', json, HEX_TEXT, 'a HEXEWKB string');
|
|
1135
|
+
const srid = params['srid'];
|
|
1136
|
+
if (typeof srid !== 'number' || sridOf(hex) === srid) return json;
|
|
1137
|
+
return refuseJsonValue('postgis/geometry', `a HEXEWKB string of a geometry with SRID ${srid}`, json);
|
|
1138
|
+
};
|
|
1139
|
+
|
|
1140
|
+
export const postgisGeometry = sqlDataType('postgis/geometry', { params, texts, read: readGeometry });
|
|
1141
|
+
```
|
|
1142
|
+
|
|
1143
|
+
A parameter that limits values, such as a geometry column's SRID, is checked the same way, in the data type's `read`. A contract that stores a value the type refuses no longer loads, so a stored default that broke the limit is reported when the contract is read, not when a query runs.
|
|
1144
|
+
|
|
1145
|
+
### `json-helpers-renamed`
|
|
1146
|
+
|
|
1147
|
+
The helpers that read a value from JSON now say so, and the one that writes a float says what it returns. Rename each call:
|
|
1148
|
+
|
|
1149
|
+
| Before | After |
|
|
1150
|
+
| --- | --- |
|
|
1151
|
+
| `decodeJsonString` | `readJsonString` |
|
|
1152
|
+
| `decodeJsonMatching` | `readJsonMatching` |
|
|
1153
|
+
| `decodeJsonInteger` | `readJsonInteger` |
|
|
1154
|
+
| `decodeJsonIntegerText` | `readJsonIntegerText` |
|
|
1155
|
+
| `decodeJsonFloat` | `readJsonFloat` |
|
|
1156
|
+
| `decodeJsonBoolean` | `readJsonBoolean` |
|
|
1157
|
+
| `encodeJsonFloat` | `floatToJson` |
|
|
1158
|
+
|
|
1159
|
+
They take the same arguments. `ToCanonicalForm` and `canonicalFormOf` are removed; a data type's `read` (`data-types-own-parameter-limits`) does their work.
|
|
1160
|
+
|
|
1161
|
+
### `stored-form-helpers-renamed`
|
|
1162
|
+
|
|
1163
|
+
The text a contract stores for a value is its stored form, and the helpers that read or write it now say so. They are exported from `@prisma/orm-family-sql/contract/data-type-support` and `@prisma/orm-family-sql/contract/sql-expression` as before. Rename each use:
|
|
1164
|
+
|
|
1165
|
+
| Before | After |
|
|
1166
|
+
| --- | --- |
|
|
1167
|
+
| `canonicalDateTime` | `dateTimeStoredText` |
|
|
1168
|
+
| `CanonicalDateTimeOptions` | `DateTimeStoredTextOptions` |
|
|
1169
|
+
| `canonicalNumeralText` | `storedNumeralText` |
|
|
1170
|
+
| `sqlTextFromCanonical` | `sqlTextFromStored` |
|
|
1171
|
+
| `canonicalSqlText` | `storedSqlText` |
|
|
1172
|
+
|
|
1173
|
+
They take the same arguments and return the same values.
|
|
1174
|
+
|
|
1175
|
+
### `projections-read-by-from-wire`
|
|
1176
|
+
|
|
1177
|
+
An include and an aggregate now read each column of their JSON result with the codec's `fromWire`, as a plain read does. A descriptor's `jsonProjection` therefore writes the value the driver returns for an ordinary row, not the codec's stored JSON form. For a type the database prints as text, that is usually the text:
|
|
1178
|
+
|
|
1179
|
+
```ts
|
|
1180
|
+
// before
|
|
1181
|
+
protected override jsonProjection(expression: ProjectionExpr): ProjectionExpr {
|
|
1182
|
+
return FunctionCallExpr.of('array_to_json', [
|
|
1183
|
+
CastExpr.as(CastExpr.as(expression, 'real[]'), 'float8[]'),
|
|
1184
|
+
]);
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
// after
|
|
1188
|
+
protected override jsonProjection(expression: ProjectionExpr): ProjectionExpr {
|
|
1189
|
+
return CastExpr.as(expression, 'text');
|
|
1190
|
+
}
|
|
1191
|
+
```
|
|
1192
|
+
|
|
1193
|
+
A projection that returned the column unchanged may need the cast too: a JSON constructor given a `jsonb` document that is a string, or a PostGIS geometry, writes something other than the text a row carries.
|
|
1194
|
+
|
|
1195
|
+
### `empty-result-json-renamed-empty-result-wire`
|
|
1196
|
+
|
|
1197
|
+
An aggregate descriptor that declares a value for an empty input names it `emptyResultWire` instead of `emptyResultJson`. It holds the value the driver would return for that result, and the result codec reads it with `fromWire`. Only the name changes where the value was already what the driver returns:
|
|
1198
|
+
|
|
1199
|
+
```ts
|
|
1200
|
+
// before
|
|
1201
|
+
{ ...sumIntegers, nullable: false as const, emptyResultJson: '0' }
|
|
1202
|
+
|
|
1203
|
+
// after
|
|
1204
|
+
{ ...sumIntegers, nullable: false as const, emptyResultWire: '0' }
|
|
1205
|
+
```
|
|
1206
|
+
|
|
1207
|
+
## Family codec templates and enum blocks
|
|
1208
|
+
|
|
1209
|
+
### `target-codec-adapters-take-a-factory`
|
|
1210
|
+
|
|
1211
|
+
A family codec template names no data type, so it cannot build a codec: the codec's constructor needs the data type (`codecs-read-wire-and-data-type-values`). The target's adapter builds it, through a `factory` that every `postgresCodec` and `sqliteCodec` call now passes. The factory receives the adapted descriptor, the `dataType` the call names, and the column's parameters:
|
|
1212
|
+
|
|
1213
|
+
```ts
|
|
1214
|
+
// before
|
|
1215
|
+
import { postgresCodec } from '@prisma/orm-postgres/target/codec-descriptor';
|
|
1216
|
+
|
|
1217
|
+
export const myCharDescriptor = postgresCodec(myCharTemplate, {
|
|
1218
|
+
dataType: pgChar,
|
|
1219
|
+
jsonProjection: (expression) => expression,
|
|
1220
|
+
factory: (descriptor, params) => () => new MyCharCodec(descriptor, params.length),
|
|
1221
|
+
});
|
|
1222
|
+
export const myTextDescriptor = postgresCodec(myTextTemplate, {
|
|
1223
|
+
dataType: pgText,
|
|
1224
|
+
jsonProjection: (expression) => expression,
|
|
1225
|
+
});
|
|
1226
|
+
|
|
1227
|
+
// after
|
|
1228
|
+
import { postgresCodec } from '@prisma/orm-postgres/target/codec-descriptor';
|
|
1229
|
+
|
|
1230
|
+
export const myCharDescriptor = postgresCodec(myCharTemplate, {
|
|
1231
|
+
dataType: pgChar,
|
|
1232
|
+
jsonProjection: (expression) => expression,
|
|
1233
|
+
factory: (descriptor, dataType, params) => () => new MyCharCodec(descriptor, dataType, params),
|
|
1234
|
+
});
|
|
1235
|
+
export const myTextDescriptor = postgresCodec(myTextTemplate, {
|
|
1236
|
+
dataType: pgText,
|
|
1237
|
+
jsonProjection: (expression) => expression,
|
|
1238
|
+
factory: (descriptor, dataType) => () => new MyTextCodec(descriptor, dataType),
|
|
1239
|
+
});
|
|
1240
|
+
```
|
|
1241
|
+
|
|
1242
|
+
A call that passed no `factory` used the template's own codec; pass a factory that builds that codec class with the data type. `sqliteCodec` takes the same `factory`, and no longer takes `renderTypes: false`; delete the option.
|
|
1243
|
+
|
|
1244
|
+
### `family-codec-templates-render-no-literals`
|
|
1245
|
+
|
|
1246
|
+
```ts
|
|
1247
|
+
// before: the template renders, and postgresCodec copied it
|
|
1248
|
+
export class MyTextTemplate extends CodecDescriptorTemplateImpl<void> {
|
|
1249
|
+
override renderValueLiteral(value: JsonValue): string | undefined {
|
|
1250
|
+
return renderTsLiteral(value);
|
|
1251
|
+
}
|
|
1252
|
+
// ...
|
|
1253
|
+
}
|
|
1254
|
+
export const myTextDescriptor = postgresCodec(myTextTemplate, {
|
|
1255
|
+
dataType: pgText,
|
|
1256
|
+
jsonProjection: (expression) => expression,
|
|
1257
|
+
});
|
|
1258
|
+
|
|
1259
|
+
// after: the template renders nothing, and the target passes the renderer
|
|
1260
|
+
export class MyTextTemplate extends CodecDescriptorTemplateImpl<void> {
|
|
1261
|
+
// ...
|
|
1262
|
+
}
|
|
1263
|
+
export const myTextDescriptor = postgresCodec(myTextTemplate, {
|
|
1264
|
+
dataType: pgText,
|
|
1265
|
+
renderValueLiteral: renderTsLiteral,
|
|
1266
|
+
jsonProjection: (expression) => expression,
|
|
1267
|
+
factory: (descriptor, dataType) => () => new MyTextCodec(descriptor, dataType),
|
|
1268
|
+
});
|
|
1269
|
+
```
|
|
1270
|
+
|
|
1271
|
+
Without the option, the adapted codec renders no literal, so an enum or value set on it is typed as the codec's whole output type.
|
|
1272
|
+
|
|
1273
|
+
### `enum-block-written-values`
|
|
1274
|
+
|
|
1275
|
+
1. Read `block.writtenValues?.[key]` in place of `block.numberTexts?.[key]`. A number entry is `{ kind: 'number', text }`, with the text as written.
|
|
1276
|
+
2. Rename a `readWrittenNumber` hook to `readWrittenValueForCodec`, and read `written` in place of `text`.
|
|
1277
|
+
3. Give every refused `WrittenValueReading` a `code`, such as `PSL_VALUE_TYPE_INCOMPATIBLE`.
|
|
1278
|
+
|
|
1279
|
+
```ts
|
|
1280
|
+
// before
|
|
1281
|
+
readWrittenNumber: ({ text, codecId, subject }) => ({ ok: false, message: `${subject}: refused` }),
|
|
1282
|
+
|
|
1283
|
+
// after
|
|
1284
|
+
readWrittenValueForCodec: ({ written, codecId, subject }) => ({
|
|
1285
|
+
ok: false,
|
|
1286
|
+
code: 'PSL_VALUE_TYPE_INCOMPATIBLE',
|
|
1287
|
+
message: `${subject}: refused`,
|
|
1288
|
+
}),
|
|
1289
|
+
```
|
|
1290
|
+
|
|
1291
|
+
The detection matches every file that names `WrittenValueReading`, including one that already sets `code`. Check each refused reading.
|
|
1292
|
+
|
|
1293
|
+
## Columns are compared by their data type
|
|
1294
|
+
|
|
1295
|
+
### `type-lookups-one-framework-type`
|
|
1296
|
+
|
|
1297
|
+
The pair of a codec lookup and a data type lookup has one type in the framework. Replace `SqlTypeLookups` and `MongoTypeLookups` with `TypeLookups`:
|
|
1298
|
+
|
|
1299
|
+
```ts
|
|
1300
|
+
// Before
|
|
1301
|
+
import type { SqlTypeLookups } from '@prisma/orm-family-sql/contract/data-type';
|
|
1302
|
+
function storageTypeOf(codecId: string, lookups: SqlTypeLookups) {}
|
|
1303
|
+
|
|
1304
|
+
// After
|
|
1305
|
+
import type { TypeLookups } from '@prisma/orm-framework/components/codec';
|
|
1306
|
+
function storageTypeOf(codecId: string, lookups: TypeLookups) {}
|
|
1307
|
+
```
|
|
1308
|
+
|
|
1309
|
+
`TypeLookups` asks only for `codecLookup.descriptorFor` and `dataTypeLookup.get`. Where your code needs the whole lookups, name them as type arguments: `TypeLookups<CodecLookupWithDescriptors, DataTypeLookup>`.
|
|
1310
|
+
|
|
1311
|
+
### `type-name-normalisers-removed`
|
|
1312
|
+
|
|
1313
|
+
`normalizeSchemaNativeType` and `normalizeSqliteNativeType` are gone. If you used them to decide whether two columns have the same type, compare the columns' data types instead, with `sqlColumnTypesEqual(a, b)` from `@prisma/orm-family-sql/schema-ir/types`: two columns have the same type when both have a `storedType`, the two are one data type, their `storedTypeParams` are equal, and both or neither are lists.
|
|
1314
|
+
|
|
1315
|
+
### `introspected-type-text`
|
|
1316
|
+
|
|
1317
|
+
```ts
|
|
1318
|
+
// Before
|
|
1319
|
+
const { nativeType, many, resolvedNativeType } = introspectedNativeType({
|
|
1320
|
+
formattedType, dataType: row.data_type, udtName, characterMaximumLength, numericPrecision, numericScale,
|
|
1321
|
+
});
|
|
1322
|
+
|
|
1323
|
+
// After
|
|
1324
|
+
const { typeText, many } = introspectedTypeText({
|
|
1325
|
+
formattedType, informationSchemaType: row.data_type, udtName, characterMaximumLength, numericPrecision, numericScale,
|
|
1326
|
+
});
|
|
1327
|
+
```
|
|
1328
|
+
|
|
1329
|
+
On the database side, `typeText` is the type as introspection reads it, such as `integer` or `timestamp(3) with time zone`, not a normalised name. On Postgres an enum is named as a contract names it (`mood`, or `app.status` outside `public`) and a type off the search path keeps its schema (`extensions.vector(3)`); on SQLite the declared type is lower-cased. On the contract side it is the name a migration writes.
|
|
1330
|
+
|
|
1331
|
+
### `schema-ir-column-type-text`
|
|
1332
|
+
|
|
1333
|
+
```ts
|
|
1334
|
+
// Before
|
|
1335
|
+
new SqlColumnIR({ name: 'id', nativeType: 'int4', nullable: false, resolvedNativeType: 'int4' });
|
|
1336
|
+
|
|
1337
|
+
// After
|
|
1338
|
+
import { pgInt4 } from '@prisma/orm-postgres/target/data-types';
|
|
1339
|
+
|
|
1340
|
+
new SqlColumnIR({
|
|
1341
|
+
name: 'id',
|
|
1342
|
+
typeText: 'int4',
|
|
1343
|
+
nullable: false,
|
|
1344
|
+
storedType: pgInt4,
|
|
1345
|
+
storedTypeParams: {},
|
|
1346
|
+
});
|
|
1347
|
+
```
|
|
1348
|
+
|
|
1349
|
+
A column with no `storedType` is one no data type claims, and it never compares equal to another, so a column a test builds by hand to compare needs `storedType` and `storedTypeParams`: the data type the column is stored as (the type its codec represents, unless that type is stored as another), and that type's parameters in normal form, such as `{ precision: 10, scale: 0 }` for `numeric(10)`. `storedTypeParams` is only for comparing; DDL writes the parameters as written, from `codecRef.typeParams`.
|
|
1350
|
+
|
|
1351
|
+
Read `column.typeText` where you read `column.nativeType`, and `column.storedType` where you read `column.dataType`; a reader that needs the type the codec represents gets it from `column.codecRef`. Code that compared `resolvedNativeType` compares types with `sqlColumnTypesEqual` instead. Code that read `codecBaseNativeType` to write DDL writes the type from `column.storedType` and the parameters in `column.codecRef.typeParams`, with `renderSqlTypeName` from `@prisma/orm-family-sql/contract/data-type`.
|
|
1352
|
+
|
|
1353
|
+
### `default-resolver-takes-the-column`
|
|
1354
|
+
|
|
1355
|
+
A resolver reads the column's `many` or `typeText` instead of a type name, and reads a default with the new readers:
|
|
1356
|
+
|
|
1357
|
+
```ts
|
|
1358
|
+
// Before
|
|
1359
|
+
import type { DefaultResolver } from '@prisma/orm-family-sql/family/control';
|
|
1360
|
+
import { parsePostgresDefault } from '@prisma/orm-postgres/target/default-normalizer';
|
|
1361
|
+
|
|
1362
|
+
const resolve: DefaultResolver = (def, resolvedNativeType) =>
|
|
1363
|
+
def.kind === 'function' ? (parsePostgresDefault(def.expression, resolvedNativeType) ?? def) : def;
|
|
1364
|
+
|
|
1365
|
+
// After
|
|
1366
|
+
import type { DefaultResolver } from '@prisma/orm-family-sql/family/control';
|
|
1367
|
+
import { readPostgresDefault } from '@prisma/orm-postgres/target/default-normalizer';
|
|
1368
|
+
|
|
1369
|
+
const resolve: DefaultResolver = (def, column) => {
|
|
1370
|
+
if (def.kind !== 'function') return def;
|
|
1371
|
+
const read = readPostgresDefault(def.expression, column.many);
|
|
1372
|
+
return read.kind === 'function' ? read : def;
|
|
1373
|
+
};
|
|
1374
|
+
```
|
|
1375
|
+
|
|
1376
|
+
`readPostgresDefault` and `readSqliteDefault` always return a value. Where `parsePostgresDefault` or `parseSqliteDefault` returned `undefined` for an expression they could not read, the new readers return `{ kind: 'function', expression }` with the expression as reported. A literal is `{ kind: 'literal', literal }`, which the column's codec reads, not a `ColumnDefault`. `readSqliteDefault` takes the column's declared type, as `column.typeText` gives it.
|
|
1377
|
+
|
|
1378
|
+
A control adapter that implements `SqlControlAdapter` deletes its `normalizeDefault` member. Nothing called it.
|
|
1379
|
+
|
|
1380
|
+
### `control-adapters-take-declared-data-types`
|
|
1381
|
+
|
|
1382
|
+
```ts
|
|
1383
|
+
// Before
|
|
1384
|
+
import { PostgresControlAdapter } from '@prisma/orm-postgres/adapter/control';
|
|
1385
|
+
|
|
1386
|
+
const adapter = new PostgresControlAdapter(
|
|
1387
|
+
createPostgresBuiltinCodecLookup(),
|
|
1388
|
+
createPostgresBuiltinDataTypeLookup(),
|
|
1389
|
+
);
|
|
1390
|
+
|
|
1391
|
+
// After
|
|
1392
|
+
import { PostgresControlAdapter } from '@prisma/orm-postgres/adapter/control';
|
|
1393
|
+
import { postgresDataTypes } from '@prisma/orm-postgres/target/data-types';
|
|
1394
|
+
|
|
1395
|
+
const adapter = new PostgresControlAdapter(
|
|
1396
|
+
createPostgresBuiltinCodecLookup(),
|
|
1397
|
+
createPostgresBuiltinDataTypeLookup(),
|
|
1398
|
+
postgresDataTypes,
|
|
1399
|
+
);
|
|
1400
|
+
```
|
|
1401
|
+
|
|
1402
|
+
```ts
|
|
1403
|
+
// Before
|
|
1404
|
+
import { SqliteControlAdapter } from '@prisma/orm-sqlite/adapter/control';
|
|
1405
|
+
|
|
1406
|
+
const adapter = new SqliteControlAdapter(createSqliteBuiltinCodecLookup());
|
|
1407
|
+
|
|
1408
|
+
// After
|
|
1409
|
+
import { SqliteControlAdapter } from '@prisma/orm-sqlite/adapter/control';
|
|
1410
|
+
import { sqliteDataTypes } from '@prisma/orm-sqlite/target/data-types';
|
|
1411
|
+
|
|
1412
|
+
const adapter = new SqliteControlAdapter(createSqliteBuiltinCodecLookup(), sqliteDataTypes);
|
|
1413
|
+
```
|
|
1414
|
+
|
|
1415
|
+
The adapter resolves each column the database reports to the first of these data types that claims it, in the order given. When your stack has extensions that declare data types, such as pgvector, pass `stack.declaredDataTypes.map(({ type }) => type)`, or build the adapter with the adapter descriptor's `create(stack)`, which does that for you. With only the target's types, a column of an extension's type is reported as one no data type declares.
|
|
1416
|
+
|
|
1417
|
+
### `resolved-sql-type-carries-the-data-type`
|
|
1418
|
+
|
|
1419
|
+
```ts
|
|
1420
|
+
// Before
|
|
1421
|
+
const resolved = resolveReportedSqlType(reported, dataTypes);
|
|
1422
|
+
const type = dataTypes.find(({ id }) => id === resolved?.dataType);
|
|
1423
|
+
|
|
1424
|
+
// After
|
|
1425
|
+
const resolved = resolveReportedSqlType(reported, dataTypes);
|
|
1426
|
+
const type = resolved?.dataType;
|
|
1427
|
+
```
|
|
1428
|
+
|
|
1429
|
+
The resolver already found the data type, so there is no second lookup, and no case where the id names no type in the list.
|
|
1430
|
+
|
|
1431
|
+
### `alter-type-postcheck-by-data-type`
|
|
1432
|
+
|
|
1433
|
+
```ts
|
|
1434
|
+
// Before
|
|
1435
|
+
const checkText = alterTypeCheckText('"app"."status"', dataTypes, where); // 'app.status'
|
|
1436
|
+
|
|
1437
|
+
// After
|
|
1438
|
+
const check = alterTypeCheck('"app"."status"', dataTypes, where);
|
|
1439
|
+
// { kind: 'identity', typeName: '"app"."status"', many: false }
|
|
1440
|
+
```
|
|
1441
|
+
|
|
1442
|
+
A check of kind `catalog-text` holds the text `buildExpectedFormatType` gave for the same type. Code that read `AlterColumnTypeCall`'s `checkType` as a string reads `call.checkType.text` for a `catalog-text` check and `call.checkType.typeName` for an `identity` check.
|
|
1443
|
+
|
|
1444
|
+
## Type-constructor arguments are values of data types
|
|
1445
|
+
|
|
1446
|
+
### `value-arguments-name-a-data-type`
|
|
1447
|
+
|
|
1448
|
+
An argument is read as a value of its data type, through the same read and cast as an attribute argument (ADR 254), in PSL and in the TypeScript builder. Name the data type the argument takes:
|
|
1449
|
+
|
|
1450
|
+
```ts
|
|
1451
|
+
// Before
|
|
1452
|
+
Vector: {
|
|
1453
|
+
kind: 'typeConstructor',
|
|
1454
|
+
args: [{ kind: 'number', name: 'length', integer: true, minimum: 1, maximum: 16000 }],
|
|
1455
|
+
output: { codecId: 'pg/vector@1', typeParams: { length: { kind: 'arg', index: 0 } } },
|
|
1456
|
+
},
|
|
1457
|
+
|
|
1458
|
+
// After
|
|
1459
|
+
Vector: {
|
|
1460
|
+
kind: 'typeConstructor',
|
|
1461
|
+
args: [{ kind: 'value', dataType: 'pg/int4', name: 'length' }],
|
|
1462
|
+
output: { codecId: 'pg/vector@1', typeParams: { length: { kind: 'arg', index: 0 } } },
|
|
1463
|
+
},
|
|
1464
|
+
```
|
|
1465
|
+
|
|
1466
|
+
Move any bound the argument carried to the data type's `params` schema, which the codec's `paramsSchema` references. A string argument becomes a value of the data type it names; an argument that holds SQL, such as a type name, is a value of `sql/expression`, written ``sql`...` ``. The data type must be registered in the stack and written by some authoring entry, itself or through a type it casts from: assembly refuses a value argument otherwise, with `CONTRACT.DATA_TYPE_UNREGISTERED` or `CONTRACT.DATA_TYPE_NOT_WRITABLE`. A type constructor argument still declared with another kind, `option` and `object` included, is refused when the stack is assembled, with `CONTRACT.PACK_CONTRIBUTION_INVALID` naming the constructor and the argument.
|
|
1467
|
+
|
|
1468
|
+
A field preset's `number`, `option` and `object` arguments are unchanged; convert only a type constructor's arguments. Detection cannot tell the two apart, so it also reports a field preset's arguments: leave those as they are, including the properties of an `object` argument.
|
|
1469
|
+
|
|
1470
|
+
### `value-argument-types-in-typescript`
|
|
1471
|
+
|
|
1472
|
+
A target or extension that registers a data type its arguments take declares the TypeScript value in its pack's type, beside `__codecTypes`:
|
|
1473
|
+
|
|
1474
|
+
```ts
|
|
1475
|
+
export const myTargetPack: typeof myTargetPackBase & {
|
|
1476
|
+
readonly __codecTypes?: CodecTypes;
|
|
1477
|
+
readonly __dataTypeArguments?: {
|
|
1478
|
+
readonly 'my/int': { readonly argument: number; readonly parameter: number };
|
|
1479
|
+
};
|
|
1480
|
+
} = myTargetPackBase;
|
|
1481
|
+
```
|
|
1482
|
+
|
|
1483
|
+
`argument` is what an author passes to the helper, and `parameter` is the type parameter the data type's reader gives for it, which the column's type is built from. An extension whose arguments take the target's types, such as `pg/int4`, declares nothing.
|
|
1484
|
+
|
|
1485
|
+
To type a descriptor of a value argument on its own, use `AuthoringValueArgument` from `components/authoring`; it now includes `name` and `optional`.
|
|
1486
|
+
|
|
1487
|
+
### `psl-and-print-helpers-take-data-types`
|
|
1488
|
+
|
|
1489
|
+
Pass the stack's `DataTypeSupport` to `mapPslHelperArgs({ ..., dataTypes })` and `instantiatePslFieldPreset({ ..., dataTypes })`. Replace `parsePslPositionalArgs` with the values of the call you built; to write a call's arguments back as PSL text, use `writtenTypeArguments(descriptor, args, dataTypes)`. A SQL target spreads `sqlTargetTypeConstructors({ sizeType: '<its size data type>' })` from `@prisma/orm-family-sql/family/pack` into its type namespace, and passes the same `sizeType` to `temporalCodecPresetWithPrecision`. Import `temporalCodecPresetWithPrecision` and `temporalStringAuthoringPresets` from `family/pack` too; `family/control` no longer exports them. The size type is the data type of a length or a precision: `pg/int4` on Postgres.
|
|
1490
|
+
|
|
1491
|
+
Import `assembleAuthoringDataTypes` from `components/authoring` instead of `components/control`. To build the data types a set of components reads values with, call `assembleDataTypeSupport(components, dataTypeOfCodec)`; it refuses a duplicate data type or entry, and a value argument whose data type is unregistered or that nothing writes.
|
|
1492
|
+
|
|
1493
|
+
### `composed-helpers-take-no-data-type-lookup`
|
|
1494
|
+
|
|
1495
|
+
Drop `dataTypeLookup` from the options of `createComposedAuthoringHelpers`:
|
|
1496
|
+
|
|
1497
|
+
```ts
|
|
1498
|
+
// Before
|
|
1499
|
+
createComposedAuthoringHelpers({ family, target, extensions, codecLookup, dataTypeLookup });
|
|
1500
|
+
|
|
1501
|
+
// After
|
|
1502
|
+
createComposedAuthoringHelpers({ family, target, extensions, codecLookup });
|
|
1503
|
+
```
|
|
1504
|
+
|
|
1505
|
+
The helpers read value arguments, and build entity helpers, with the data types the packs register. An argument whose data type no pack in the stack registers now fails with `CONTRACT.DATA_TYPE_UNREGISTERED`. Register it, with an `authoring.dataTypes` entry, in the pack that owns it. An extension whose arguments take a target's data type, such as `pg/int4`, registers nothing: the target already does, and a second registration is refused as a duplicate.
|
|
1506
|
+
|
|
1507
|
+
### `helper-codec-invariants`
|
|
1508
|
+
|
|
1509
|
+
Rename the call and pass the type constructors and field presets as `helpers`:
|
|
1510
|
+
|
|
1511
|
+
```ts
|
|
1512
|
+
// Before
|
|
1513
|
+
enforceDataTypeInvariants({ lookup, declaredTypes, codecs, authoringEntries, constructors, codecDescriptorFor });
|
|
1514
|
+
|
|
1515
|
+
// After
|
|
1516
|
+
enforceHelperCodecInvariants({ lookup, helpers, codecDescriptorFor });
|
|
1517
|
+
```
|
|
1518
|
+
|
|
1519
|
+
The checks on data types, entries, casts and written forms now run when you build data types with `assembleDataTypeSupport(components, dataTypeOfCodec)` from `components/authoring`; call it with the same components instead of passing `declaredTypes`, `codecs` and `authoringEntries`.
|
|
1520
|
+
|
|
1521
|
+
## Client generators are generator functions
|
|
1522
|
+
|
|
1523
|
+
`@default(fn())` now means a database default only. A value the client generates is written `@onCreate(fn())` or `@onUpdate(fn())`, and in TypeScript `.onCreate(gen.fn())`. The function resolves through the stack's generator function registry, by the column's codec.
|
|
1524
|
+
|
|
1525
|
+
### `default-functions-lower-to-database-defaults-only`
|
|
1526
|
+
|
|
1527
|
+
A default function whose `lower` returned `{ kind: 'execution', generated }` no longer compiles. Move it to a generator function on the pack ref (`src/exports/pack.ts`) and the control descriptor of the extension. One component declares the function's `signature`, a `FuncCallSig` as for a default function, or a function of the stack's data types that returns one (`generator-signature-from-data-types`). A binding maps codec ids to a `resolve` that turns the call's arguments and the column into a generator, and to `printArguments`, the reverse that `contract print` uses. `singleGeneratorBinding` from `@prisma/orm-framework/components/components` builds a binding for a function that takes no arguments:
|
|
1528
|
+
|
|
1529
|
+
```ts
|
|
1530
|
+
// Before
|
|
1531
|
+
const slugidEntry: ControlMutationDefaultEntry = {
|
|
1532
|
+
signature: { documentation: 'Generates a slug identifier when a field value is omitted.' },
|
|
1533
|
+
lower: () => ({
|
|
1534
|
+
ok: true,
|
|
1535
|
+
value: { kind: 'execution', generated: { kind: 'generator', id: 'slugid' } },
|
|
1536
|
+
}),
|
|
1537
|
+
usageSignatures: ['slugid()'],
|
|
1538
|
+
};
|
|
1539
|
+
|
|
1540
|
+
const slugidPack = {
|
|
1541
|
+
// ...
|
|
1542
|
+
controlMutationDefaults: {
|
|
1543
|
+
defaultFunctionRegistry: new Map([['slugid', slugidEntry]]),
|
|
1544
|
+
generatorDescriptors: [{ id: 'slugid', applicableCodecIds: ['pg/text@1'] }],
|
|
1545
|
+
},
|
|
1546
|
+
};
|
|
1547
|
+
|
|
1548
|
+
// After
|
|
1549
|
+
import {
|
|
1550
|
+
type ExtensionPackRef,
|
|
1551
|
+
singleGeneratorBinding,
|
|
1552
|
+
} from '@prisma/orm-framework/components/components';
|
|
1553
|
+
|
|
1554
|
+
const slugidPack = {
|
|
1555
|
+
// ...
|
|
1556
|
+
controlMutationDefaults: {
|
|
1557
|
+
defaultFunctionRegistry: new Map(),
|
|
1558
|
+
generatorDescriptors: [{ id: 'slugid' }],
|
|
1559
|
+
},
|
|
1560
|
+
generatorFunctions: [
|
|
1561
|
+
{
|
|
1562
|
+
name: 'slugid',
|
|
1563
|
+
signature: { documentation: 'Generates a slug identifier when a field value is omitted.' },
|
|
1564
|
+
bindings: [singleGeneratorBinding({ codecIds: ['pg/text@1'], generatorId: 'slugid' })],
|
|
1565
|
+
},
|
|
1566
|
+
],
|
|
1567
|
+
} as const satisfies ExtensionPackRef<'sql', 'postgres'>;
|
|
1568
|
+
```
|
|
1569
|
+
|
|
1570
|
+
Put `generatorFunctions` and the generator descriptors on both the pack ref, which the TypeScript builder reads, and the control descriptor, which `contract emit`, `contract print` and the language server read. Every stack, the TypeScript builders included, checks that each binding produces a generator a descriptor registers. Declare the pack ref with `as const satisfies`, not a type annotation: the `gen` of a `defineContract` callback is built from the packs' declared functions and their signatures, so `gen.slugid()` exists only when the pack ref keeps its literal type. A binding's `resolve` may return only a generator id the binding lists in `generatorIds`; any other id throws `InternalError`. To bind a function another component declares, such as `uuid`, to a codec your extension adds, contribute a binding without a `signature`. Composing a stack fails with `CONTRACT.PACK_CONTRIBUTION_INVALID` when two components declare one function, when a binding names a function no component declares, when two bindings cover one function and codec, when two functions write one generator for one codec, when a binding produces a generator no generator descriptor registers, or when two components register one generator id.
|
|
1571
|
+
|
|
1572
|
+
### `sql-family-registers-identifier-generators`
|
|
1573
|
+
|
|
1574
|
+
The component that defines a generator registers it, and the SQL family now defines and registers `uuidv4`, `uuidv7`, `cuid2`, `ulid`, `nanoid` and `ksuid`. A SQL target, adapter or extension that registers any of them, for example by spreading `builtinGeneratorRegistryMetadata` into `generatorDescriptors`, must remove those entries; `builtinGeneratorRegistryMetadata` is removed. Two components that register one generator id make every stack fail with `CONTRACT.PACK_CONTRIBUTION_INVALID`: `Generator "uuidv4" is registered by both "sql" and "<your component>". Register each generator once, in the component that defines it.` An extension that binds `uuid` to a codec it adds keeps the binding and registers nothing for it. Register only the generators your component defines, such as `slugid`.
|
|
1575
|
+
|
|
1576
|
+
A default function that lowers to a database default, such as one that writes a SQL expression, does not change.
|
|
1577
|
+
|
|
1578
|
+
### `applicable-codec-ids-and-build-phases-removed`
|
|
1579
|
+
|
|
1580
|
+
`applicableCodecIds` on a generator descriptor is removed: a binding's `codecIds` say which codecs a generator fills, and `contract print` reads the `printArguments` of the binding. `buildPhases` had no caller. Delete both.
|
|
1581
|
+
|
|
1582
|
+
## Generator function arguments and column length
|
|
1583
|
+
|
|
1584
|
+
### `sql-target-declares-integer-argument-generators`
|
|
1585
|
+
|
|
1586
|
+
Add `generatorFunctions` to the target's pack ref and control descriptor, beside `authoring`:
|
|
1587
|
+
|
|
1588
|
+
```ts
|
|
1589
|
+
import {
|
|
1590
|
+
idGeneratorFunctionBindings,
|
|
1591
|
+
sqlIntegerArgumentGeneratorFunctions,
|
|
1592
|
+
} from '@prisma/orm-family-sql/family/pack';
|
|
1593
|
+
|
|
1594
|
+
generatorFunctions: [
|
|
1595
|
+
...sqlIntegerArgumentGeneratorFunctions({ integer: myInt4.id }),
|
|
1596
|
+
...idGeneratorFunctionBindings({ text: [MY_TEXT_CODEC_ID] }),
|
|
1597
|
+
],
|
|
1598
|
+
```
|
|
1599
|
+
|
|
1600
|
+
`integer` is the id of your target's 32-bit integer data type. An argument such as the `7` of `uuid(7)` is read and cast as a value of that type, as a column default is, then checked by the function: `uuid` takes 4 or 7, `cuid` takes 2, and `nanoid` takes 2 through 255. The `gen` helpers of a TypeScript contract keep their argument types.
|
|
1601
|
+
|
|
1602
|
+
### `generator-signature-from-data-types`
|
|
1603
|
+
|
|
1604
|
+
```ts
|
|
1605
|
+
// Before
|
|
1606
|
+
const arms = [...defaultFunctionRegistry.entries()].map(([name, entry]) =>
|
|
1607
|
+
funcCall(name, entry.signature as FuncCallSig),
|
|
1608
|
+
);
|
|
1609
|
+
|
|
1610
|
+
// After
|
|
1611
|
+
import { defaultFunctionCall } from '@prisma/orm-family-sql/contract-psl/attribute-specs';
|
|
1612
|
+
|
|
1613
|
+
const arms = [...defaultFunctionRegistry.entries()].map(([name, entry]) =>
|
|
1614
|
+
defaultFunctionCall(name, entry, dataTypes),
|
|
1615
|
+
);
|
|
1616
|
+
```
|
|
1617
|
+
|
|
1618
|
+
A generator function, new in this release (`default-functions-lower-to-database-defaults-only`), is read the same way with `generatorFunctionCall(contribution.name, contribution.signature, dataTypes)` from `@prisma/orm-framework/psl-parser`. A function you declare can keep a plain `FuncCallSig`. Write it as `(dataTypes) => FuncCallSig` when an argument is a value of a data type, read with `dataTypeValue(type, dataTypes)`.
|
|
1619
|
+
|
|
1620
|
+
### `generator-function-field-length`
|
|
1621
|
+
|
|
1622
|
+
Code that calls the registry passes the column's length:
|
|
1623
|
+
|
|
1624
|
+
```ts
|
|
1625
|
+
import { sqlCodecColumnLength } from '@prisma/orm-family-sql/contract/data-type';
|
|
1626
|
+
|
|
1627
|
+
generatorFunctions.resolve(call, {
|
|
1628
|
+
codecId,
|
|
1629
|
+
typeParams,
|
|
1630
|
+
length: sqlCodecColumnLength(dataTypes, codecId, typeParams),
|
|
1631
|
+
});
|
|
1632
|
+
```
|
|
1633
|
+
|
|
1634
|
+
A binding of your own reads the length:
|
|
1635
|
+
|
|
1636
|
+
```ts
|
|
1637
|
+
const binding: GeneratorFunctionBinding = {
|
|
1638
|
+
codecIds: ['pg/text@1', 'sql/char@1'],
|
|
1639
|
+
generatorIds: ['slugid'],
|
|
1640
|
+
resolve: ({ field }) =>
|
|
1641
|
+
field.length !== undefined && field.length < 22
|
|
1642
|
+
? { ok: false, message: `slugid() writes 22 characters, which does not fit a column of ${field.length} characters.` }
|
|
1643
|
+
: { ok: true, generator: { kind: 'generator', id: 'slugid' } },
|
|
1644
|
+
printArguments: () => ({ args: {}, text: '' }),
|
|
1645
|
+
};
|
|
1646
|
+
```
|
|
1647
|
+
|
|
1648
|
+
### `build-contract-definition-takes-lookups`
|
|
1649
|
+
|
|
1650
|
+
```ts
|
|
1651
|
+
// Before
|
|
1652
|
+
const definition = buildContractDefinition({ family, target, createNamespace, models });
|
|
1653
|
+
|
|
1654
|
+
// After
|
|
1655
|
+
const definition = buildContractDefinition({
|
|
1656
|
+
family,
|
|
1657
|
+
target,
|
|
1658
|
+
createNamespace,
|
|
1659
|
+
codecLookup,
|
|
1660
|
+
dataTypeLookup,
|
|
1661
|
+
models,
|
|
1662
|
+
});
|
|
1663
|
+
```
|
|
1664
|
+
|
|
1665
|
+
### `arg-binding-spec-label`
|
|
1666
|
+
|
|
1667
|
+
```ts
|
|
1668
|
+
// Before
|
|
1669
|
+
interpretArgs(args, { name: 'rel', positional, named }, ctx, span, node);
|
|
1670
|
+
|
|
1671
|
+
// After
|
|
1672
|
+
interpretArgs(args, { label: 'Attribute "rel"', positional, named }, ctx, span, node);
|
|
1673
|
+
```
|
|
1674
|
+
|
|
1675
|
+
### `one-of-refuses-data-type-value`
|
|
1676
|
+
|
|
1677
|
+
```ts
|
|
1678
|
+
// Before
|
|
1679
|
+
type: oneOf(str(), dataTypeValue(pgInt4.id, dataTypes)),
|
|
1680
|
+
|
|
1681
|
+
// After: a value of a data type is its own parameter
|
|
1682
|
+
type: dataTypeValue(pgInt4.id, dataTypes),
|
|
1683
|
+
```
|
|
1684
|
+
|
|
1685
|
+
### `text-data-types`
|
|
1686
|
+
|
|
1687
|
+
```ts
|
|
1688
|
+
authoring: {
|
|
1689
|
+
textDataTypes: [citext.id],
|
|
1690
|
+
},
|
|
1691
|
+
```
|
|
1692
|
+
|
|
1693
|
+
## Contract types: one field type generic, and packs typed for `defineContract`
|
|
1694
|
+
|
|
1695
|
+
The emitted `contract.d.ts` of every family, and a contract built with `defineContract` in either family, now type their fields with one generic, `FieldTypesFromDomain` from `@prisma/orm-framework/contract/types`. A contract built with `defineContract` now has the same types as the `contract.d.ts` that `prisma contract emit` writes for it. The emitter reads a pack's codecs and descriptors at run time. A contract written in TypeScript has only the pack's types, so a pack states as types what the emitter derives. `QueryOperationTypesFunction` is exported from `@prisma/orm-family-sql/contract/types`, and `ParameterizedOutputTypesFunction` from `@prisma/orm-framework/contract/types`.
|
|
1696
|
+
|
|
1697
|
+
### `field-types-expression-removed`
|
|
1698
|
+
|
|
1699
|
+
Code written against 8.0.0-rc.18 never had `fieldTypesExpression`, so there is nothing to delete. The framework declares `FieldTypeOverrides` and `ParameterizedOutputTypeFunctions` itself and writes:
|
|
1700
|
+
|
|
1701
|
+
```ts
|
|
1702
|
+
type FieldTypeOverrides = {
|
|
1703
|
+
readonly public: {
|
|
1704
|
+
readonly models: { readonly User: { readonly role: { readonly output: 'admin' | 'user'; readonly input: 'admin' | 'user' } } };
|
|
1705
|
+
readonly valueObjects: { readonly Address: { readonly kind: { readonly output: 'home' | 'work'; readonly input: 'home' | 'work' } } };
|
|
1706
|
+
};
|
|
1707
|
+
};
|
|
1708
|
+
export type FieldOutputTypes = FieldTypesFromDomain<ContractBase['domain']['namespaces'], CodecTypes, ParameterizedOutputTypeFunctions, FieldTypeOverrides, 'output'>;
|
|
1709
|
+
```
|
|
1710
|
+
|
|
1711
|
+
### `field-types-generic-moved`
|
|
1712
|
+
|
|
1713
|
+
8.0.0-rc.18 had no `FieldTypesFromDomain`, so code written against it needs no change. Code written against a development build after it imports `FieldTypesFromDomain` and `ValueTypeSide` from `@prisma/orm-framework/contract/types` instead of the SQL family's contract types entry. The generic now types value object and union fields itself, from the namespace's `valueObjects`. Its arguments are `FieldTypesFromDomain<DomainNamespaces, CodecTypes, ParameterizedOutputs, Overrides, Side>`, where `Overrides` is one map keyed like the domain, `[namespace]['models' | 'valueObjects'][owner][field]`, each entry `{ output?, input? }`; `ValueObjectTypesFromDomain` takes the same map. `ColumnTypesFromStorage` stays in the SQL family. For a storage map, apply `StoredValueType` from `@prisma/orm-framework/contract/types` to each entry, as `ColumnTypesFromStorage` does.
|
|
1714
|
+
|
|
1715
|
+
### `resolve-field-value-set-renamed`
|
|
1716
|
+
|
|
1717
|
+
Rename `EmissionSpi.resolveFieldValueSet` to `resolveStorageValueSet` in a family emitter, and drop any handling of domain enum references from it. The framework emitter now reads a field's value set itself when the field references a domain enum (`valueSet.plane` is `'domain'`), for model and value object fields alike, and no longer calls the hook for those fields. It calls `resolveStorageValueSet` only for other model fields, whose values the family keeps in its storage, such as a SQL column's value set.
|
|
1718
|
+
|
|
1719
|
+
### `typescript-contract-pack-type-slots`
|
|
1720
|
+
|
|
1721
|
+
A third-party SQL pack is typed fully for a `defineContract` contract only when it declares what an emitted `contract.d.ts` would get from its codecs and descriptors. Nothing breaks for a pack that does none of this; its operations, refined output types and aggregates are missing from a `defineContract` contract's types, as before.
|
|
1722
|
+
|
|
1723
|
+
**Query operations: `__queryOperationTypes`.** If your pack contributes query operations and exports a `QueryOperationTypes<CodecTypes>` type for its emitted `contract.d.ts`, declare it as a type-level function of the contract's codec types and add it to the pack metadata's type:
|
|
1724
|
+
|
|
1725
|
+
```ts
|
|
1726
|
+
import type { QueryOperationTypesFunction } from '@prisma/orm-family-sql/contract/types';
|
|
1727
|
+
|
|
1728
|
+
export interface QueryOperationTypesForCodecs extends QueryOperationTypesFunction {
|
|
1729
|
+
readonly queryOperationTypes: QueryOperationTypes<this['codecTypes']>;
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
export const myPackMeta: typeof myPackMetaBase & {
|
|
1733
|
+
readonly __codecTypes?: CodecTypes;
|
|
1734
|
+
readonly __queryOperationTypes?: QueryOperationTypesForCodecs;
|
|
1735
|
+
} = myPackMetaBase;
|
|
1736
|
+
```
|
|
1737
|
+
|
|
1738
|
+
**Aggregates: literal `types.aggregateDescriptors`.** The aggregate result types of a `defineContract` contract are settled from the `types.aggregateDescriptors` of the target, the adapter and every extension, against the contract's codecs, as emission settles them. Only descriptors whose `operation`, input codec ids or traits, output codec id and `nullable` are literal types take part. Declare the list with `as const` and no annotation that widens it:
|
|
1739
|
+
|
|
1740
|
+
```ts
|
|
1741
|
+
export const myAggregateDescriptors = [
|
|
1742
|
+
{
|
|
1743
|
+
operation: 'bitOr',
|
|
1744
|
+
input: { kind: 'codec', codecId: 'pg/int4@1' },
|
|
1745
|
+
output: { kind: 'codec', codecId: 'pg/int8@1' },
|
|
1746
|
+
nullable: true,
|
|
1747
|
+
},
|
|
1748
|
+
] as const;
|
|
1749
|
+
```
|
|
1750
|
+
|
|
1751
|
+
If you build descriptors with helper functions, make the helpers generic with `const` type parameters and do not use `satisfies` inside them: TypeScript widens a generic helper's result to its constraint when its returned object has a `satisfies` clause. Check the list against the descriptor type where you use it, for example `types: { aggregateDescriptors: myAggregateDescriptors satisfies ReadonlyArray<SqlAggregateDescriptor> }`.
|
|
1752
|
+
|
|
1753
|
+
**Index helpers: say what the build writes.** A contract built with `defineContract` types each index from the `IndexConstraint` a helper returns, so code reads it by name and passes it to query operations. `IndexConstraint` takes a third type parameter, the index's `map` name, type and options as the build writes them. If your pack adds an index helper, return `IndexConstraint<FieldNames, Name, { readonly map: Map; readonly type: 'yourType'; readonly options: Options }>` with literal types. When the options name fields that the build turns into column names, give an interface extending `IndexOptionsFunction` from `@prisma/orm-family-sql/contract-ts/contract-builder`, whose `options` reads `this['columnOf']`, the model's field-to-column map. See `fullTextIndex` in the Postgres pack.
|
|
1754
|
+
|
|
1755
|
+
**Declaration output: export what a contract names.** An application that exports a contract and builds with `declaration: true` needs TypeScript to name every type the contract's inferred type mentions. Export from your pack's `/pack` entry, as types, the types that end up there: your `CodecTypes`, the output types your type function gives (such as `Vector`), `QueryOperationTypesForCodecs`, `ParameterizedOutputTypesForTypeParams`, and the value types your codec types name (such as a GeoJSON `Geometry`). Naming `CodecTypes` also keeps TypeScript from inlining codec classes with private members, which fails with TS4094. Compile a small application that imports only your published package and the public `@prisma/orm-postgres` with `declaration: true` to check.
|
|
1756
|
+
|
|
1757
|
+
### Output types that depend on type parameters: one type function
|
|
1758
|
+
|
|
1759
|
+
This covers `parameterized-output-types-declared-once` (SQL packs) and `mongo-parameterized-output-types` (Mongo-family packs). If a codec's output type depends only on the column's type parameters, such as `Vector<3>` for `vector(3)`, write that mapping once, as a type-level function of the type parameters, and export it from your pack's `codec-types` entry:
|
|
1760
|
+
|
|
1761
|
+
```ts
|
|
1762
|
+
import type { ParameterizedOutputTypesFunction } from '@prisma/orm-framework/contract/types';
|
|
1763
|
+
|
|
1764
|
+
type OutputTypeMap<TypeParams> = {
|
|
1765
|
+
readonly 'my/vector@1': TypeParams extends { readonly length: infer N extends number }
|
|
1766
|
+
? Vector<N>
|
|
1767
|
+
: never;
|
|
1768
|
+
};
|
|
1769
|
+
|
|
1770
|
+
export interface ParameterizedOutputTypesForTypeParams extends ParameterizedOutputTypesFunction {
|
|
1771
|
+
readonly outputTypes: OutputTypeMap<this['typeParams']>;
|
|
1772
|
+
}
|
|
1773
|
+
```
|
|
1774
|
+
|
|
1775
|
+
Name it in two places:
|
|
1776
|
+
|
|
1777
|
+
- In the pack metadata's type, as `readonly __parameterizedOutputTypes?: ParameterizedOutputTypesForTypeParams`. A contract built with `defineContract` reads it there.
|
|
1778
|
+
- In the metadata of the component that contributes the codecs, next to the codec types import, as `types.codecTypes.parameterizedOutputTypes`. The emitted `contract.d.ts` imports it and types each column with type parameters through it:
|
|
1779
|
+
|
|
1780
|
+
```ts
|
|
1781
|
+
types: {
|
|
1782
|
+
codecTypes: {
|
|
1783
|
+
import: { package: 'my-pack/codec-types', named: 'CodecTypes', alias: 'MyTypes' },
|
|
1784
|
+
parameterizedOutputTypes: {
|
|
1785
|
+
package: 'my-pack/codec-types',
|
|
1786
|
+
named: 'ParameterizedOutputTypesForTypeParams',
|
|
1787
|
+
alias: 'MyParameterizedOutputTypes',
|
|
1788
|
+
},
|
|
1789
|
+
},
|
|
1790
|
+
},
|
|
1791
|
+
```
|
|
1792
|
+
|
|
1793
|
+
Declare both. With only `__parameterizedOutputTypes`, the emitted `contract.d.ts` types such a column by the codec's plain output type; with only `types.codecTypes.parameterizedOutputTypes`, a contract built with `defineContract` does. Nothing reports the gap, so check a column on both paths.
|
|
1794
|
+
|
|
1795
|
+
Then delete the codec's `renderOutputType`, and the `typeImports` entry that existed only so the emitted file could name its result (such as `Vector`). A codec the map leaves out, or maps to `never` for some type parameters, keeps its plain output type. On SQL, a `renderOutputType` that writes such a type still works for the emitted file but is ignored by `defineContract`; keep `renderOutputType` only for a type that no type function can compute from the type parameters, such as the text of an arktype schema. On Mongo, `renderOutputType` is no longer used for such codecs: Mongo's vector codec no longer implements it, and a Mongo `defineContract` contract ignores it.
|
|
1796
|
+
|
|
1797
|
+
```diff
|
|
1798
|
+
class MyVectorDescriptor extends PostgresCodecDescriptor<{ readonly length: number }> {
|
|
1799
|
+
override readonly codecId = 'my/vector@1' as const;
|
|
1800
|
+
- override renderOutputType({ length }: { length: number }) {
|
|
1801
|
+
- return `Vector<${length}>`;
|
|
1802
|
+
- }
|
|
1803
|
+
}
|
|
1804
|
+
```
|
|
1805
|
+
|
|
1806
|
+
A column helper that returns a column spec, built with `column(factory, codecId, typeParams)`, needs no entry: a `defineContract` contract reads the field's output type and codec id from the codec the factory builds.
|
|
1807
|
+
|
|
1808
|
+
Export `CodecTypes`, `ParameterizedOutputTypesForTypeParams` and the types they name from the pack's `/pack` entry, so an application that exports a contract can build declarations.
|
|
1809
|
+
|
|
1810
|
+
### `psl-interpreter-contract-capabilities`
|
|
1811
|
+
|
|
1812
|
+
`interpretPslDocumentToSqlContract` now puts the enabled capabilities you pass in `capabilities`, usually the composed stack's, into the contract's `capabilities`, together with the target's and the extensions'. Before, it used them only to check the schema and left them out of the contract. If you call it directly, expect the adapter's capabilities in the result, and pass the stack's capabilities if you build a contract to compare with one written in TypeScript or emitted by `prisma contract emit`.
|
|
1813
|
+
|
|
1814
|
+
## MongoDB fields have stored names
|
|
1815
|
+
|
|
1816
|
+
### `mongo-model-storage-fields`
|
|
1817
|
+
|
|
1818
|
+
```ts
|
|
1819
|
+
// before
|
|
1820
|
+
const keys = Object.keys(model.fields);
|
|
1821
|
+
const hasId = Object.hasOwn(model.fields, '_id');
|
|
1822
|
+
|
|
1823
|
+
// after
|
|
1824
|
+
import { ownDocumentIdFieldOf, ownStoredNamesOf } from '@internal/mongo-contract';
|
|
1825
|
+
|
|
1826
|
+
const keys = Object.values(ownStoredNamesOf(model));
|
|
1827
|
+
const hasId = ownDocumentIdFieldOf(model) !== undefined;
|
|
1828
|
+
```
|
|
1829
|
+
|
|
1830
|
+
`ownStoredNamesOf(model)` maps each of a model's own fields to its stored name; `valueObjectStoredNamesOf(valueObject)` maps each field of a value object, which has no storage block, to its own name. `storedNamesOf(models, name)` adds the fields a variant inherits from its base, and `modelAndBasesOf(models, name)` walks a model and its bases. A model built by hand, for example in a test, adds `fields` to its storage:
|
|
1831
|
+
|
|
1832
|
+
```ts
|
|
1833
|
+
// before
|
|
1834
|
+
{ fields: { _id: objectIdField, email: stringField }, relations: {}, storage: { collection: 'users' } }
|
|
1835
|
+
|
|
1836
|
+
// after
|
|
1837
|
+
{
|
|
1838
|
+
fields: { _id: objectIdField, email: stringField },
|
|
1839
|
+
relations: {},
|
|
1840
|
+
storage: { collection: 'users', fields: { _id: { field: '_id' }, email: { field: 'email' } } },
|
|
1841
|
+
}
|
|
1842
|
+
```
|
|
1843
|
+
|
|
1844
|
+
## MongoDB validator derivation moves to the contract package
|
|
1845
|
+
|
|
1846
|
+
### `mongo-validator-derivation-moves-to-mongo-contract`
|
|
1847
|
+
|
|
1848
|
+
```ts
|
|
1849
|
+
// before
|
|
1850
|
+
import type { FieldValueSets } from '@internal/mongo-contract-psl';
|
|
1851
|
+
|
|
1852
|
+
// after
|
|
1853
|
+
import type { FieldValueSets } from '@internal/mongo-contract';
|
|
1854
|
+
```
|
|
1855
|
+
|
|
1856
|
+
Through the public package, import from `@prisma/orm-family-mongo/contract` instead of `@prisma/orm-family-mongo/contract-psl`.
|
|
1857
|
+
|
|
1858
|
+
### `mongo-derive-json-schema-replaced-by-derive-collection-validators`
|
|
1859
|
+
|
|
1860
|
+
`deriveJsonSchema` took the fields of one model and ignored its relations, so its validator could differ from the one a contract emits. `deriveCollectionValidators` takes the contract's models and derives the validator of every collection that stores a root model, with each variant as a `oneOf` branch.
|
|
1861
|
+
|
|
1862
|
+
```ts
|
|
1863
|
+
// before
|
|
1864
|
+
import { deriveJsonSchema } from '@internal/mongo-contract-psl';
|
|
1865
|
+
|
|
1866
|
+
const validator = deriveJsonSchema(
|
|
1867
|
+
ns.models['Account'].fields,
|
|
1868
|
+
{ codecLookup, dataTypeLookup },
|
|
1869
|
+
ns.valueObjects,
|
|
1870
|
+
valueSets,
|
|
1871
|
+
);
|
|
1872
|
+
|
|
1873
|
+
// after
|
|
1874
|
+
import { collectionControlPoliciesOf, deriveCollectionValidators } from '@internal/mongo-contract';
|
|
1875
|
+
|
|
1876
|
+
const validator = deriveCollectionValidators({
|
|
1877
|
+
models: ns.models,
|
|
1878
|
+
lookups: { codecLookup, dataTypeLookup },
|
|
1879
|
+
valueObjects: ns.valueObjects ?? {},
|
|
1880
|
+
valueSets,
|
|
1881
|
+
controlPolicies: collectionControlPoliciesOf(contract),
|
|
1882
|
+
})['accounts'];
|
|
1883
|
+
```
|
|
1884
|
+
|
|
1885
|
+
`ns` is `contract.domain.namespaces[namespaceId]`, and `valueSets` is the storage namespace's `entries.valueSet`, as before. `controlPolicies` is required: only a collection whose control policy is `managed` gets a validator, as in an emitted contract. `collectionControlPoliciesOf(contract)` reads the policies a built contract declares. A call to `derivePolymorphicJsonSchema` becomes the same call: the validator of a root model with variants already has one `oneOf` branch per variant.
|
|
1886
|
+
|
|
1887
|
+
## Generated checks can no longer be waived
|
|
1888
|
+
|
|
1889
|
+
Prisma 8 adds a check to a list column of a managed table so that its elements cannot be null, and a check to an enum-typed column so that it holds only the enum's values. `@noCheck` in PSL and `.noCheck()` in TypeScript used to skip these checks while the field kept its non-null element type. The client type then said the elements could not be null while the database accepted null. Both are removed, from an extension's contract source as from an application's.
|
|
1890
|
+
|
|
1891
|
+
### `psl-nocheck-removed`
|
|
1892
|
+
|
|
1893
|
+
Write a list whose elements may be null as `T?[]`:
|
|
1894
|
+
|
|
1895
|
+
```prisma
|
|
1896
|
+
// Before
|
|
1897
|
+
scopes String[] @default([]) @noCheck(elementNotNull)
|
|
1898
|
+
|
|
1899
|
+
// After
|
|
1900
|
+
scopes String?[] @default([])
|
|
1901
|
+
```
|
|
1902
|
+
|
|
1903
|
+
The database does not change: neither form has a check. The element type in the extension's `contract.d.ts` gains `| null`, so code in the extension and in applications that read the list must handle null elements.
|
|
1904
|
+
|
|
1905
|
+
If you want the check instead, delete the attribute and keep `T[]`. An application that installs the extension then gets the check in its next migration of the extension's contract space. Applying it fails if a stored list already holds a null element.
|
|
1906
|
+
|
|
1907
|
+
Delete `@noCheck(membership)`. The next migration adds the membership check to the enum column. Applying it fails if a stored value is not one of the enum's values.
|
|
1908
|
+
|
|
1909
|
+
A bare `@noCheck` waived every check the column had. Apply both rules above.
|
|
1910
|
+
|
|
1911
|
+
On a table the extension does not manage (`@@control(external)` or a contract-level policy other than `managed`), no check is derived either way. Only the element type changes.
|
|
1912
|
+
|
|
1913
|
+
Re-emit the bundled contract with the extension's own emit script, and ship the new `contract.json` and `contract.d.ts` together.
|
|
1914
|
+
|
|
1915
|
+
### `ts-nocheck-method-removed`
|
|
1916
|
+
|
|
1917
|
+
The same rules apply to the TypeScript builder:
|
|
1918
|
+
|
|
1919
|
+
```ts
|
|
1920
|
+
// Before
|
|
1921
|
+
scopes: field.text().many().noCheck('elementNotNull'),
|
|
1922
|
+
|
|
1923
|
+
// After
|
|
1924
|
+
scopes: field.text().many({ elementsNullable: true }),
|
|
1925
|
+
```
|
|
1926
|
+
|
|
1927
|
+
Delete `.noCheck('membership')` the same way. Re-emit the bundled contract.
|
|
1928
|
+
|
|
1929
|
+
### `stored-contracts-drop-nocheck`
|
|
1930
|
+
|
|
1931
|
+
Migration snapshots that an extension ships, and any other stored `contract.json` written by an earlier release, may have a `noCheck` key on a column. This release refuses such a contract and says to re-emit it. A historical snapshot cannot be re-emitted from today's source, so run the script instead. Do this before you re-emit the bundled contract, and commit your work first so the script's changes can be reviewed and undone with git. Run it from the extension's package root:
|
|
1932
|
+
|
|
1933
|
+
```sh
|
|
1934
|
+
node <guide>/scripts/remove-nocheck/remove-nocheck.ts
|
|
1935
|
+
```
|
|
1936
|
+
|
|
1937
|
+
`<guide>` is the directory that holds this guide. Node 24 or later runs the TypeScript script directly; it needs no `tsx`. The script reads and writes files only and needs no database. It removes the `noCheck` key from every column of every SQL contract under the root, in any `*.json` file, skipping `node_modules`, `dist`, `build` and every directory whose name starts with a dot, such as `.git`, `.agents` or `.claude`. It follows links to files and directories, also outside the root; commit or back up the files there too. That includes a test fixture of an old contract: if you keep one on purpose, restore it with git afterwards. Where the key waived the element check of a list, the script also makes the column, the field that maps it and their types in `contract.d.ts`, the row types such as `ReadonlyArray<CodecTypes['pg/text@1']['output'] | null>` included, lists whose elements may be null, which is what the source says after `psl-nocheck-removed`. The script does not change which checks a contract declares. In each PostgreSQL contract it also writes each literal default in the form this release stores, for example `"1.5"` on `numeric(10,2)` as `"1.50"`, because this release refuses a contract that stores another form, a snapshot included. The script carries this release's rules for each PostgreSQL built-in data type and for `postgis/geometry` and `pgvector/vector`, so its result does not depend on the installed packages. A geometry default is written as the upper-case little-endian HEXEWKB PostGIS prints, whatever case and byte order it had. It leaves a default of any other data type, such as one the extension defines, as it is. Besides the project root, it takes one option, `--default`, described below.
|
|
1938
|
+
|
|
1939
|
+
The storage hash changes, so the script also renames each changed snapshot directory to its new hash. It rewrites every `migration.json`, ref, `migration.ts` and `contract.d.ts` that names an old hash, and gives each changed migration a new `migrationHash`.
|
|
1940
|
+
|
|
1941
|
+
When it finishes, it prints how many files it rewrote, how many snapshot directories it renamed, and each storage hash it replaced (`<old> -> <new>`). A package with no `noCheck` key and no default in another form is left unchanged, and the script says so. It changes no file and exits 1, naming the file, when a `contract.json`, `migration.json` or ref is not valid JSON, when the `ops.json` of a migration whose hashes change is not valid JSON, when a contract's stored storage hash or snapshot directory name does not match its content (restore that file from version control, or re-emit it, and run the script again), or when a renamed snapshot directory already exists with different content, or when this release refuses a PostgreSQL default. If it stops partway, for example on a full disk, it says so; run it again to finish.
|
|
1942
|
+
|
|
1943
|
+
This release refuses a default that is not a value of its column's type, for example a time with more fraction digits than its column holds, a `pgvector/vector` element that `real` cannot hold exactly (`0.123456789` is stored as `0.12345679`), or a `postgis/geometry` in another SRID than its column's, and a list column's default that is not a list. The script names the file and column of each. Do not edit the stored file: that breaks its storage hash, and the next run refuses it. Choose the value the database stores, and run the script again with that value as JSON:
|
|
1944
|
+
|
|
1945
|
+
```sh
|
|
1946
|
+
node <guide>/scripts/remove-nocheck/remove-nocheck.ts --default 'public.product.opensAt="12:34:00.123457"'
|
|
1947
|
+
```
|
|
1948
|
+
|
|
1949
|
+
`--default` names the column as `<namespace>.<table>.<column>`, as the script's message does, and can be given once for each column. The script stores the value in every stored contract where that column's default is refused, migration snapshots included, checks it by the same rules and refreshes the hashes. It stops when the value is refused too, or when a `--default` names a column whose default it does not refuse. Then change the default in the contract source to the same value, so that re-emitting writes it.
|
|
1950
|
+
|
|
1951
|
+
Then re-emit the bundled contract. The extension's storage hash changes, so tell the applications that use it, in your release notes, to run `prisma db sign` against every database after they upgrade, and name the old and new hash. The app upgrade guide for this release has such a note for the Supabase extension, `supabase-contract-lists-allow-null-elements`. Tell them too that `prisma migration status` no longer marks the extension's migrations applied before the upgrade as applied, because each rewritten migration has a new hash and their databases' migration history keeps the old ones. `prisma db migrate` runs none of them again, and `prisma db verify` passes. A database that has not applied every migration yet is refused by a plain `prisma db sign`, and `prisma db migrate` stops on it with `MIGRATION.MARKER_MISMATCH`: tell them to sign it with `prisma db sign --contract <the last migration it applied>` and then run `prisma db migrate`. `--contract` takes the migration's directory name, or the new hash that migration goes to. `prisma migration status` prints the start of the old hash the database's marker holds, and the `<old> -> <new>` list in your release notes gives the new hash to sign with.
|
|
1952
|
+
|
|
1953
|
+
## Contract spaces an extension ships
|
|
1954
|
+
|
|
1955
|
+
An extension that ships a contract space, with its own `contract.json`, migration snapshots and contract source, upgrades them as an application upgrades its own. The sections of this guide named in the steps below explain each one. The scripts are under `scripts/` next to this guide. Run each script from the extension's package root.
|
|
1956
|
+
|
|
1957
|
+
Do the steps in this order, and skip a step that does not apply to the extension's contract space:
|
|
1958
|
+
|
|
1959
|
+
1. Commit your work, so every script's changes can be reviewed and undone with git.
|
|
1960
|
+
2. Rewrite the stored contracts: `stored-contracts-drop-nocheck` above, then, for a SQLite contract space, `sqlite-contracts-name-datetime-and-json-data-types` (`scripts/data-type-values/data-type-values.ts`).
|
|
1961
|
+
3. Change the contract source: `psl-nocheck-removed` and `ts-nocheck-method-removed` above, `date-time-interval-and-bytes-defaults-use-tags` and `client-functions-move-from-default-to-on-create` (`scripts/default-generators-to-on-create/rewrite-default-generators.mjs`, given the extension's Prisma 8 schema files).
|
|
1962
|
+
4. Re-emit the bundled contract. That also writes PostgreSQL defaults in the new form (`postgres-defaults-stored-in-another-spelling`); `stored-contracts-drop-nocheck` in step 2 has already brought the migration snapshots to it. For a MongoDB contract space, then run `scripts/mongo-field-storage-names/mongo-field-storage-names.ts` (`mongo-contracts-record-stored-field-names`).
|
|
1963
|
+
5. For each migration package of the contract space, change its `migration.ts` and write its `ops.json` again as `Migrations` below says.
|
|
1964
|
+
|
|
1965
|
+
For example, with `<guide>` the directory that holds this guide:
|
|
1966
|
+
|
|
1967
|
+
```sh
|
|
1968
|
+
node <guide>/scripts/data-type-values/data-type-values.ts
|
|
1969
|
+
node <guide>/scripts/mongo-field-storage-names/mongo-field-storage-names.ts
|
|
1970
|
+
```
|
|
1971
|
+
|
|
1972
|
+
Each step that changes a storage hash changes the hash of the extension's contract space. Tell the applications that use the extension, in your release notes, to run `prisma db sign` against every database after they upgrade, and name the old and new hash, as `stored-contracts-drop-nocheck` says.
|
|
1973
|
+
|
|
1974
|
+
### `sqlite-contracts-name-datetime-and-json-data-types`
|
|
1975
|
+
|
|
1976
|
+
A SQLite contract stores the data type of each column. This release gives datetime and JSON values their own data types, and stores a datetime as `toISOString()` writes it, with exactly three fraction digits. A contract emitted by the previous release still names `sqlite/text`, so the CLI of this release refuses it with `CONTRACT.VALIDATION_FAILED`:
|
|
1977
|
+
|
|
1978
|
+
```text
|
|
1979
|
+
storage.namespaces.__unbound__.entries.table.events.columns.at: codec sqlite/datetime@1 represents sqlite/datetime, not sqlite/text
|
|
1980
|
+
```
|
|
1981
|
+
|
|
1982
|
+
Commit your work first, then run the script from the extension's package root:
|
|
1983
|
+
|
|
1984
|
+
```sh
|
|
1985
|
+
node <guide>/scripts/data-type-values/data-type-values.ts
|
|
1986
|
+
```
|
|
1987
|
+
|
|
1988
|
+
Node 24 or later runs the TypeScript script directly. It reads and writes files only. It rewrites every `*.json` file under the root that parses as a SQLite contract in the previous release's form, skipping `node_modules`, `dist`, `build` and every directory whose name starts with a dot, and follows links to files and directories, also outside the root. A test fixture of a contract in the previous release's form is rewritten too; restore it with git afterwards if you keep it on purpose. In each contract it changes:
|
|
1989
|
+
|
|
1990
|
+
- the `dataType` of each column and named type whose codec is `sqlite/datetime@1` or `sqlite/json@1`, from `sqlite/text` to `sqlite/datetime` or `sqlite/json`;
|
|
1991
|
+
- each literal default of a `sqlite/datetime@1` column, and each value of an enum typed by `sqlite/datetime@1`, to three fraction digits: `"2024-01-01T00:00:00Z"` becomes `"2024-01-01T00:00:00.000Z"`. A JSON default keeps its value.
|
|
1992
|
+
|
|
1993
|
+
It then writes the storage hash each contract now has, renames the snapshot directory under `migrations/snapshots/` to that hash, and replaces the old hash in every `migration.json` (recomputing its `migrationHash`), every ref, every `migration.ts` and every `contract.d.ts`. The planned SQL does not change.
|
|
1994
|
+
|
|
1995
|
+
It prints how many files it rewrote and how many snapshot directories it renamed, and each storage hash it replaced (`<old> -> <new>`); put that list in your release notes. A package already in the new form, or with no SQLite contract, is left unchanged, and the script says so. It prints `<file>: stored hash did not recompute; rehashed from content` for a contract whose stored hash does not match its content, and rewrites it anyway. It changes no file and exits 1 when a `contract.json`, `migration.json` or ref is not valid JSON, when the `ops.json` of a migration whose hashes change is not valid JSON, or when a renamed snapshot directory already exists with different content. If it stops partway, for example on a full disk, run it again to finish. Run your formatter afterwards.
|
|
1996
|
+
|
|
1997
|
+
### `date-time-interval-and-bytes-defaults-use-tags`
|
|
1998
|
+
|
|
1999
|
+
In a Prisma 8 schema, a default of a date, time, interval or bytes column is written with the tag of the column's type. `contract emit` refuses a quoted string and shows the tag to write:
|
|
2000
|
+
|
|
2001
|
+
```text
|
|
2002
|
+
Field "Event.at": Expected timestamptz`...`; write timestamptz`2024-01-01T00:00:00Z`
|
|
2003
|
+
```
|
|
2004
|
+
|
|
2005
|
+
```prisma
|
|
2006
|
+
// before
|
|
2007
|
+
at DateTime @default("2024-01-01T00:00:00Z")
|
|
2008
|
+
local Timestamp @default("2024-01-01 12:34:56.500")
|
|
2009
|
+
day Date @default("2024-03-15")
|
|
2010
|
+
clock Time @default("12:34")
|
|
2011
|
+
zoned Timetz @default("12:34:56+02")
|
|
2012
|
+
span Interval @default("P1D")
|
|
2013
|
+
payload Bytes @default("AQID")
|
|
2014
|
+
|
|
2015
|
+
// after
|
|
2016
|
+
at DateTime @default(timestamptz`2024-01-01T00:00:00Z`)
|
|
2017
|
+
local Timestamp @default(timestamp`2024-01-01 12:34:56.500`)
|
|
2018
|
+
day Date @default(date`2024-03-15`)
|
|
2019
|
+
clock Time @default(time`12:34`)
|
|
2020
|
+
zoned Timetz @default(timetz`12:34:56+02`)
|
|
2021
|
+
span Interval @default(interval`P1D`)
|
|
2022
|
+
payload Bytes @default(bytea`\x010203`)
|
|
2023
|
+
```
|
|
2024
|
+
|
|
2025
|
+
On PostgreSQL the tag is named after the column's type: `timestamptz` for `DateTime`, `timestamp`, `date`, `time`, `timetz` and `interval` for the types of those names, and `bytea` for `Bytes`. A date or time tag takes the text you wrote. A `bytea` tag takes the bytes as hexadecimal after `\x`, not base64: `"AQID"` is the bytes 01 02 03, so write `bytea`\x010203``. For a quoted base64 string, `contract emit` names only the tag, because it cannot tell base64 from hex text; convert the bytes to hex yourself. On SQLite, a `DateTime` default uses the `datetime` tag, and a `Bytes` default the `blob` tag, whose body is the hex digits the quoted string held before.
|
|
2026
|
+
|
|
2027
|
+
### `mongo-contracts-record-stored-field-names`
|
|
2028
|
+
|
|
2029
|
+
A MongoDB contract now records each field's stored name in `model.storage.fields`, and names fields by their names in the schema: a field `id ObjectId @id @map("_id")` is `id` in the contract's `fields`, with `"storage": { "collection": "users", "fields": { "id": { "field": "_id" } } }`. Relations and a base model's `discriminator` name fields the same way. Indexes, validators and `execution` keep naming stored names, so the storage hash does not change.
|
|
2030
|
+
|
|
2031
|
+
1. Commit your work first.
|
|
2032
|
+
2. Re-emit the bundled contract and commit the regenerated `contract.json` and `contract.d.ts`.
|
|
2033
|
+
3. Run the script from the extension's package root:
|
|
2034
|
+
|
|
2035
|
+
```sh
|
|
2036
|
+
node <guide>/scripts/mongo-field-storage-names/mongo-field-storage-names.ts
|
|
2037
|
+
```
|
|
2038
|
+
|
|
2039
|
+
It rewrites every `*.json` file under the root that is a MongoDB contract with a model whose `storage` has no `fields`, skipping `node_modules`, `dist`, `build`, every directory whose name starts with a dot and every link it cannot follow, and the `contract.d.ts` next to it. These are the snapshots under `migrations/snapshots/<hash>/`, which no command regenerates. A snapshot cannot be rebuilt as a re-emit would write it, because the old contract does not say what the schema called a field, so the script keeps every field's name and records it as stored under that name: `"_id"` stays the field `_id`, stored as `_id`. Planning from such a snapshot to the re-emitted contract plans nothing. The script prints each file it rewrote, or that nothing changed. It edits the type of `storage` in each `contract.d.ts` on one line; run your formatter afterwards. If it cannot find a model's storage type in a `contract.d.ts`, it says so and exits 1: add `readonly fields: { readonly <field>: { readonly field: '<field>' }; ... }` inside that model's `readonly storage: { ... }` by hand.
|
|
2040
|
+
|
|
2041
|
+
## Migrations
|
|
2042
|
+
|
|
2043
|
+
### `setdefault-operation-class-derived`
|
|
2044
|
+
|
|
2045
|
+
`this.setDefault` on the PostgreSQL `Migration` class used to take `operationClass`, and `migration plan` wrote `operationClass: 'widening'` when a migration changed an existing default. The option is gone. The method reads the migration's start contract: the operation is widening when the start contract gives the column a default, and additive otherwise, including in a migration with no start contract. A `migration.ts` that passes the option no longer type-checks. Delete the option:
|
|
2046
|
+
|
|
2047
|
+
```typescript
|
|
2048
|
+
// before
|
|
2049
|
+
this.setDefault({ schema: 'public', table: 'user', column: col('role', 'text', { default: lit('member'), codecRef: { codecId: 'pg/text@1' } }), operationClass: 'widening' })
|
|
2050
|
+
// after
|
|
2051
|
+
this.setDefault({ schema: 'public', table: 'user', column: col('role', 'text', { default: lit('member'), codecRef: { codecId: 'pg/text@1' } }) })
|
|
2052
|
+
```
|
|
2053
|
+
|
|
2054
|
+
`node migration.ts` does not check types, so a file that still passes `operationClass` runs and ignores it. An applied migration needs nothing: `prisma db migrate` applies `ops.json`.
|
|
2055
|
+
|
|
2056
|
+
### Postchecks check the whole definition
|
|
2057
|
+
|
|
2058
|
+
The runner checks an operation's postchecks before it runs the operation. When they all hold, it records the operation as already applied and skips it. On MongoDB, which has no transaction, a run that fails part way relies on this skip when it runs again. Several postchecks held for an object of the planned name with another definition, so the runner skipped an operation whose effect was not in place, and the run failed later or left the object as it was. On PostgreSQL, SQLite and MongoDB these checks now check the whole definition.
|
|
2059
|
+
|
|
2060
|
+
The checks are written into `ops.json` when the migration package is written, so a package written by an earlier release still carries the old checks. Each detection below matches the old check of one operation. A matched `ops.json` needs action only when its migration is not applied yet: write its `ops.json` again before you apply it. Run its `migration.ts` (`node migration.ts`), or delete the package and run `prisma migration plan` again. An applied migration needs nothing; its operations do not run again. This applies to the migration packages an extension ships for its contract space as well.
|
|
2061
|
+
|
|
2062
|
+
#### PostgreSQL: the `postgres-postcheck-*` entries
|
|
2063
|
+
|
|
2064
|
+
Each of these operations now checks the object's definition in the catalog: kind, table, columns in order, types, referenced table and actions, access method, command and roles. It never compares text that PostgreSQL prints in its own form, such as expressions, predicates, check and policy bodies, or defaults. Renames now also check that the old name is gone.
|
|
2065
|
+
|
|
2066
|
+
- `postgres-postcheck-create-table`: `createTable` checks that the relation is a table, not a view, sequence or index of the same name.
|
|
2067
|
+
- `postgres-postcheck-add-column`: `addColumn` checks the column's type, and that it is NOT NULL when the column is declared NOT NULL.
|
|
2068
|
+
- `postgres-postcheck-add-column-with-temporary-default` and `postgres-postcheck-add-required-column-to-empty-table`: `addColumnWithTemporaryDefault` and `addRequiredColumnToEmptyTable` check the column's type.
|
|
2069
|
+
- `postgres-postcheck-create-index`: `createIndex` checks that the relation is an index on the planned table, with the planned uniqueness, access method and columns in order, and with an expression and a predicate only where the call has them.
|
|
2070
|
+
- `postgres-postcheck-rename-index`: `renameIndex` also checks that no index has the old name any more.
|
|
2071
|
+
- `postgres-postcheck-add-primary-key` and `postgres-postcheck-add-unique`: `addPrimaryKey` and `addUnique` check that the constraint is a primary key or a unique constraint on the planned columns in order.
|
|
2072
|
+
- `postgres-postcheck-add-foreign-key`: `addForeignKey` checks the constraint's columns, referenced table and columns in order, and its delete and update actions.
|
|
2073
|
+
- `postgres-postcheck-add-check-constraint`: `addCheckConstraint` checks that the constraint is a check constraint.
|
|
2074
|
+
- `postgres-postcheck-rename-constraint`: `renameConstraint` also checks that no constraint has the old name any more.
|
|
2075
|
+
- `postgres-postcheck-create-rls-policy`: `createRlsPolicy` checks the policy's command, roles and whether it is permissive.
|
|
2076
|
+
- `postgres-postcheck-rename-rls-policy`: `renameRlsPolicy` also checks that no policy has the old name any more, and its precheck now also refuses a policy that already has the new name.
|
|
2077
|
+
- `postgres-postcheck-autoincrement-default`: `setDefault` with `autoincrement()` also checks that the column owns the sequence of the planned name and that the sequence has the column's integer width.
|
|
2078
|
+
|
|
2079
|
+
#### `postgres-autoincrement-sequence-follows-column-type`
|
|
2080
|
+
|
|
2081
|
+
An `autoincrement()` column takes its values from a sequence it owns. `ALTER COLUMN … TYPE` does not change that sequence, so a column widened from `int4` to `int8` kept a sequence `AS integer`, and inserts failed once it reached 2147483647. An `alterColumnType` on such a column, planned or hand-written in `migration.ts`, now also runs `ALTER SEQUENCE … AS <new width>`. It first refuses, before any step, when the sequence has already handed out a value past a narrower width. Its postcheck asks for both the column type and the sequence width. A column whose `nextval(...)` default reads a sequence it does not own changes type as before, and that sequence is left alone.
|
|
2082
|
+
|
|
2083
|
+
The detection matches every integer `alterColumnType` written before this change, and none written after it. Only those on an `autoincrement()` column need action:
|
|
2084
|
+
|
|
2085
|
+
- Migration not applied yet: write its `ops.json` again before you apply it, as above.
|
|
2086
|
+
- Migration already applied: the sequence still has the old width. Change it to the column's width yourself, for example `ALTER SEQUENCE "public"."user_id_seq" AS bigint`. `pg_get_serial_sequence('"public"."user"', 'id')` names the sequence.
|
|
2087
|
+
|
|
2088
|
+
#### `setdefault-has-no-postcheck`
|
|
2089
|
+
|
|
2090
|
+
A `setDefault` operation without `autoincrement()` checked afterwards that the column has a default. The old default passes that check, so the runner skipped the operation. From 8.0.0-rc.15 until this release, only an additive `setDefault` carried the check, and a hand-written `this.setDefault` was additive unless it passed `operationClass: 'widening'`. Such a call on a column that already had a different default was skipped, and `prisma db migrate` then failed with `MIGRATION.SCHEMA_VERIFY_FAILED`. Such a `setDefault` operation now carries no check afterwards; the final schema verification compares the default's value, and setting a default twice changes nothing. A `setDefault` with `autoincrement()` keeps its checks (`postgres-postcheck-autoincrement-default`).
|
|
2091
|
+
|
|
2092
|
+
A matched `ops.json` needs action only when its migration is not applied yet and a hand-written `setDefault` in its `migration.ts` changes a default the column already has. A package the planner wrote for a column with no default needs nothing.
|
|
2093
|
+
|
|
2094
|
+
#### `postgres-alter-column-type-unchanged-refused`
|
|
2095
|
+
|
|
2096
|
+
`this.alterColumnType({ schema, table, column, type, using })` to the type the migration's start contract, after its earlier renames, already gives the column, used to build an operation whose check, the column's type, already held. The runner skipped it and `using` never ran. `migration.ts` now refuses the call with `MIGRATION.ALTER_COLUMN_TYPE_USING_WITHOUT_TYPE_CHANGE`. Write the conversion as a `dataTransform`, which checks the rows themselves:
|
|
2097
|
+
|
|
2098
|
+
```typescript
|
|
2099
|
+
// before
|
|
2100
|
+
this.alterColumnType({ schema: 'public', table: 'user', column: 'email', type: 'text', using: 'lower(email)' })
|
|
2101
|
+
// after
|
|
2102
|
+
this.dataTransform(endContract, 'Lower-case user emails', {
|
|
2103
|
+
check: () => /* a query for the users whose email is not lower-case */,
|
|
2104
|
+
run: () => /* an update that lower-cases those emails */,
|
|
2105
|
+
})
|
|
2106
|
+
```
|
|
2107
|
+
|
|
2108
|
+
A matched `migration.ts` needs action only when the call converts a column to the type the start contract already gives it.
|
|
2109
|
+
|
|
2110
|
+
#### `sqlite-postchecks-check-full-definition`
|
|
2111
|
+
|
|
2112
|
+
- `createTable` checked only that a table of that name exists, whatever its columns. It now checks every column's name, type, nullability and primary key position.
|
|
2113
|
+
- `addColumn` checked only that a column of that name exists. It now checks the column's type and nullability.
|
|
2114
|
+
- `createIndex` checked only that an index of that name exists. It now checks the index's table, ordered columns and uniqueness.
|
|
2115
|
+
- `recreateTable` did not check foreign key actions (`onDelete`, `onUpdate`) or `autoincrement()`. A migration that changed only those was skipped, and `prisma db migrate` then failed with `MIGRATION.SCHEMA_VERIFY_FAILED`. It now checks them.
|
|
2116
|
+
|
|
2117
|
+
A `recreateTable` written for an `autoincrement()` change has no text to detect; write it again as well when its migration is not applied yet.
|
|
2118
|
+
|
|
2119
|
+
#### `mongo-postchecks-check-full-definition`
|
|
2120
|
+
|
|
2121
|
+
- `createIndex` checked only the index keys, and `unique: true` when the index is unique. An index on the same keys with other options, such as `sparse`, a TTL, a partial filter, a collation, a wildcard projection, or other text weights or languages, passed the check. It now checks `unique` and `sparse` both ways, `expireAfterSeconds`, `partialFilterExpression`, `wildcardProjection`, the collation fields the call gives (MongoDB fills in the others) or no collation when it gives none, and a text index's fields, `weights`, `default_language` and `language_override`.
|
|
2122
|
+
- `collMod` with a validator that is not only a `$jsonSchema`, such as `{ status: { $in: [...] } }`, checked only the collection's validation level and action. It now compares the whole validator.
|
|
2123
|
+
|
|
2124
|
+
### Migration apply failures report the runner's own code
|
|
2125
|
+
|
|
2126
|
+
#### `control-client-apply-takes-invocation`
|
|
2127
|
+
|
|
2128
|
+
`dbInit`, `dbUpdate` and `migrate` on a control client write advice that names commands to run, and that advice needs to know where it will be run from. Pass it as the required `invocation` option, `{ cwd, configPath, dbGiven }`:
|
|
2129
|
+
|
|
2130
|
+
```ts
|
|
2131
|
+
// Before
|
|
2132
|
+
await control.dbUpdate({ contract, mode: 'apply', migrationsDir: 'migrations', answerQuestions });
|
|
2133
|
+
|
|
2134
|
+
// After
|
|
2135
|
+
await control.dbUpdate({
|
|
2136
|
+
contract,
|
|
2137
|
+
mode: 'apply',
|
|
2138
|
+
migrationsDir: 'migrations',
|
|
2139
|
+
answerQuestions,
|
|
2140
|
+
invocation: { cwd: process.cwd(), configPath: undefined, dbGiven: false },
|
|
2141
|
+
});
|
|
2142
|
+
```
|
|
2143
|
+
|
|
2144
|
+
Add the same `invocation` to every `dbInit`, `dbUpdate` and `migrate` call. Set `configPath` to the config path your tool passes to `prisma`, and `dbGiven` to `true` when it passes `--db`. Pass `{ cwd: process.cwd(), configPath: undefined, dbGiven: false }` when nothing is run from a terminal.
|
|
2145
|
+
|
|
2146
|
+
A failure of these three operations is a `CliStructuredError`, so `DbInitFailure`, `DbUpdateFailure` and `MigrateFailure` are gone from `control-api`. Replace any use of them or their code types with `CliStructuredError`, and branch on `failure.code`, a dotted code such as `MIGRATION.PLANNING_FAILED`, instead of `'PLANNING_FAILED'`, `'RUNNER_FAILED'` or `'MIGRATION_PATH_NOT_FOUND'`.
|
|
2147
|
+
|
|
2148
|
+
The failure's fields change too:
|
|
2149
|
+
|
|
2150
|
+
| Before | After |
|
|
2151
|
+
| --- | --- |
|
|
2152
|
+
| `failure.summary` | `failure.message` |
|
|
2153
|
+
| `failure.code === 'PLANNING_FAILED'`, `failure.conflicts` | `failure.code === 'MIGRATION.PLANNING_FAILED'`, `failure.meta.conflicts` |
|
|
2154
|
+
| `failure.warnings` on a failed `dbInit` or `dbUpdate`, and `value.warnings` on a successful one | the `onPlannerWarnings(warnings)` option, called once per run when planning raised warnings, whether the apply then succeeds or fails |
|
|
2155
|
+
| `failure.rowsWithoutValue`, `failure.failedTypeChange` | the runner's facts in `failure.meta`: `rowsWithoutValue` and `failedTypeChange`, and `schemaIssues` and `failedCheck` when the runner found them. A field in them is a subject object, not text such as `"User.age"` |
|
|
2156
|
+
| `failure.failedMigration`, `failure.databaseStorageHash` | removed; the advice in `failure.fix` names the migration directory and the `--from` hash |
|
|
2157
|
+
|
|
2158
|
+
In `--json` output, `db init` and `db update` print the planner's warnings of a failed apply as `warn` messages before the error, instead of in the error's `meta.plannerWarnings`.
|
|
2159
|
+
|
|
2160
|
+
#### `runner-failures-report-own-codes`
|
|
2161
|
+
|
|
2162
|
+
`MIGRATION.RUNNER_FAILED` no longer exists. Code that reads `prisma db migrate`, `db init` or `db update` output with `--json`, or a control client's failure, and matches `MIGRATION.RUNNER_FAILED` or `meta.runnerErrorCode`, now matches the runner's code itself:
|
|
2163
|
+
|
|
2164
|
+
```ts
|
|
2165
|
+
// Before
|
|
2166
|
+
if (error.code === 'MIGRATION.RUNNER_FAILED' && error.meta.runnerErrorCode === 'MIGRATION.SCHEMA_VERIFY_FAILED') {
|
|
2167
|
+
report(error.meta.issues);
|
|
2168
|
+
}
|
|
2169
|
+
|
|
2170
|
+
// After
|
|
2171
|
+
if (error.code === 'MIGRATION.SCHEMA_VERIFY_FAILED') {
|
|
2172
|
+
report(error.meta.schemaIssues);
|
|
2173
|
+
}
|
|
2174
|
+
```
|
|
2175
|
+
|
|
2176
|
+
A check that matched `MIGRATION.RUNNER_FAILED` alone, meaning "the apply failed", matches every code the runner reports: `MIGRATION.SCHEMA_VERIFY_FAILED`, `MIGRATION.PRECHECK_FAILED`, `MIGRATION.POSTCHECK_FAILED`, `MIGRATION.EXECUTION_FAILED`, `MIGRATION.POLICY_VIOLATION`, `MIGRATION.MARKER_ORIGIN_MISMATCH`, `MIGRATION.MARKER_CAS_FAILURE`, `MIGRATION.DESTINATION_CONTRACT_MISMATCH`, `MIGRATION.FOREIGN_KEY_VIOLATION` and, on MongoDB, `MIGRATION.DATA_TRANSFORM_CHECK_NOT_READ_ONLY`. `db init` and `db update` also report an extension space they cannot plan as `MIGRATION.PATH_UNREACHABLE` or `MIGRATION.NO_INVARIANT_PATH`, with `meta.spaceId`.
|
|
2177
|
+
|
|
2178
|
+
Read the facts from these `meta` keys:
|
|
2179
|
+
|
|
2180
|
+
| Before | After |
|
|
2181
|
+
| --- | --- |
|
|
2182
|
+
| `meta.issues` | `meta.schemaIssues` |
|
|
2183
|
+
| `meta.operationId`, `meta.phase`, `meta.stepDescription` of a failed check | `meta.failedCheck.operationId`, `meta.failedCheck.phase`, `meta.failedCheck.description` |
|
|
2184
|
+
| `meta.runnerErrorCode` | `code` |
|
|
2185
|
+
|
|
2186
|
+
`meta.failingSpace` is unchanged. `MIGRATION.PATH_UNREACHABLE` for a database with no marker now has `'empty'`, the empty contract's hash, in `meta.fromHash`, where it had `'<empty>'`. A failure also carries `meta.failedTypeChange` and `meta.rowsWithoutValue` when the runner found them.
|