Repository navigation
TML-3537: Changing a value object or a variant is a migration, and Postgres checks value object and discriminator columns - #30869
Merged
Merged
Conversation
…ch briefs Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…he storage changed When the storage hash changes but the planner plans nothing, migration plan writes the package with an empty ops.json and names the storage entities that changed (changedStorageEntities in --json). db migrate and db update move the marker. Only a first migration with no operations is still refused. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…dinate EntityCoordinate moves to @internal/contract, so the foundation can use it. ValueObjectFieldType is EntityCoordinate<'storage', 'valueObject'> with kind 'valueObject'; ValueSetRef extends EntityCoordinate. The domain plane no longer has valueObjects. Domain validation checks each value object reference against storage.namespaces.<ns>.entries.valueObject and refuses the old domain key. valueObjectAt and storageValueObjectsAtDefaultNamespace replace domainValueObjectsAtDefaultNamespace. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ueObject A StorageValueObject entity kind with its schema; a member typed by an enum refers to the storage value set. A domain field type refers to the value object by its storage coordinate. The domain namespace schema drops valueObjects, and an old contract that has it is refused with a message that says to re-emit. The editor JSON schema is regenerated. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…alueObject A MongoValueObject entity kind with its schema; a member typed by an enum refers to the storage value set. A domain field type refers to the value object by its storage coordinate. The domain namespace schema and the contract serializer refuse the old domain valueObjects key with a message that says to re-emit. Readers of a field's value object name use entityName. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…sets into storage The SQL build writes each value object to entries.valueObject of the default namespace before the storage hash, and fields and nested members refer to it by its storage coordinate; an enum member refers to the storage value set. A model node now carries its discriminator, variants and base, so the build writes the <Base>.<field> value set and points the discriminator column at it. An enum-typed discriminator keeps the enum's value set, and an enum named like the discriminator's value set is refused. SQL PSL pairs variants before the build instead of patching them in afterwards. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The Mongo builder writes value objects to entries.valueObject and buildMongoStorage hashes them. field.valueObject, Mongo PSL and the Prisma 6 reader write the storage coordinate. A value object member typed by an enum refers to the storage value set, and the validator refusals count such enums. The Mongo target serializer carries every entries kind through deserialize and serialize. The derived validators do not change. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…hanged The no-operations sentence is appended to the existing summary, so an automatic baseline keeps its baseline text and a plan keeps its extension migration directories. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ed when no entity did Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…no operations Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…re-emitted Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…espace without entries Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ue set ContractValueObjectField types valueSet as EntityCoordinate<'storage', 'valueSet'>, so a value object cannot refer to the domain plane by type. The SQL and Mongo builders write members and model fields through separate functions. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…e-set check as deferred Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…s reference names FieldTypesFromDomain takes the storage namespaces as a last type parameter with a default, so a contract without value objects types its fields as before. ValueObjectTypesFromStorage replaces ValueObjectTypesFromDomain and is keyed by storage namespace. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The SQL and Mongo emitters write entries.valueObject in the storage namespaces type. A value object field type is its storage coordinate. The domain valueObjects line and the top-level valueObjects block are gone. A value object member's override reads the storage value set it names. The Mongo builder types value objects in storage too. A contract without value objects emits the same text as before. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ration order does not change the storage hash Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…e already has a value set of that name The refusal checks the base table's storage namespace, not every enum, and uses the colon form of the other enumType messages. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…espaces are refused Every value object is stored in the default storage namespace and models refer to composite types by bare name, so the second one silently replaced the first. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…en storage is a class instance Real families hydrate storage into a class, which isPlainRecord rejects, so every such plan said the change was outside the storage entities. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…orrected reason for the clash refusal Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… the field's storage reference Run time reads go through valueObjectAt; type-level reads go through the new ContractValueObjectAt. The dead fallback to the flat valueObjects block of contract.d.ts is gone. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The statement resolver still refuses a statement that names a value object, but looks for it under storage entries.valueObject. A statement contract now carries its storage namespaces. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…mespaces'>, and ContractWithDomain stays on functions that read the domain Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…elds and value object members in both families; ContractValueObjectSchema is named after its type; SQL's value object schema leaves out unions and dictionaries by its structure, and its refusal names the value object and the member Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…union and dictionary value object members and checks a domain field's type Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… changedStorageEntities, the words its README and summary use Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…DB value object member leaves it out, and drops dict false Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…nd reads the valueSet slot; ADR 309 describes the codec's JSON type, and its first consequence and the rejected alternative agree with the cases that have no operations Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…e SQL refusal, and the missing jsonType error says why without guessing the codec's age Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…he upgrade script keeps a malformed nullable, and ADR 309 gives the full check name Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…and db update says when it signs a changed contract with no operations and names what changed Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… names the check, table and column, gives the query that finds the rows, and the route that keeps them Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…d apply with --advance-ref db, so the next plan writes nothing; the advice to fix rows re-runs db migrate with its flags Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Contributor
WalkthroughWarning Review details and warnings were omitted to fit the comment limit. |
@prisma/orm-extension-arktype-json
@prisma/orm-extension-middleware-cache
@prisma/orm-extension-paradedb
@prisma/orm-extension-pgvector
@prisma/orm-extension-postgis
@prisma/orm-extension-supabase
@prisma/orm-family-mongo
@prisma/orm-family-sql
@prisma/orm-framework
@prisma/orm-mongo
@prisma/orm-mysql
@prisma/orm-postgres
@prisma/orm-sqlite
@prisma/orm-target-mongo
@prisma/orm-target-mysql
@prisma/orm-target-postgres
@prisma/orm-target-sqlite
@prisma/orm-toolchain
commit: |
Contributor
size-limit report 📦
|
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…-value-objects-storage Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> # Conflicts: # docs/architecture docs/ADR-INDEX.md
wmadden
approved these changes
Oct 28, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 28, 2026
…the CLI they run in-process sees one copy of Prisma ORM Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
wmadden
enabled auto-merge
October 28, 2026 14:16
opensource-fork-sync Bot
pushed a commit
to cla7aye15I4nd/opensource-prisma__orm
that referenced
this pull request
Oct 30, 2026
`8.0.0-rc.21` → `8.0.0-rc.22`. See [versioning](https://github.com/prisma/orm/blob/main/docs/oss/versioning.md). **Publishing was broken and is fixed.** From 23 October every `Publish to npm` run on `main` failed with `ENEEDAUTH` on three packages that had never been on npm: `@prisma/orm-mysql`, `@prisma/orm-target-mysql` (prisma#30856) and `@prisma/orm-postgres-contrib` (prisma#30904). Trusted publishing cannot authenticate a package that does not exist yet. They were published once by hand and given a trusted publisher; the re-run of run 41053844815 then published all three from CI. The failed runs had also skipped the rc.21 git tag and GitHub Release, which the upgrade-coverage check needs to find the previous release. [`v8.0.0-rc.21`](https://github.com/prisma/orm/releases/tag/v8.0.0-rc.21) now exists at the rc.21 release commit `fad17c1d03`. **Merging this PR ships the release.** The push to `main` carries the new root version. The `Publish to npm` workflow then publishes `8.0.0-rc.22` under the `latest` dist-tag and creates a pre-release GitHub Release. ## What to review - **Release notes:** [`docs/releases/v8.0.0-rc.22.md`](https://github.com/prisma/orm/blob/release/8.0.0-rc.22/docs/releases/v8.0.0-rc.22.md), mirrored in `CHANGELOG.md`. Seven breaking changes: the PostgreSQL convenience date and time types (prisma#30847), value objects in storage (prisma#30869), the MongoDB execution context (prisma#30865), the MongoDB driver descriptor (prisma#30906), packs declaring their Postgres extension (prisma#30902), one installed copy of Prisma ORM (prisma#30883) and merged MongoDB indexes (prisma#30894). Six features and two fixes. The notes leave out prisma#30728 (telemetry backend), prisma#30891 (CI), prisma#30901 (tests), and prisma#30862, prisma#30895, prisma#30897 and prisma#30898 (docs only). - **Upgrade guides:** `skills/prisma-8/upgrading/{app,extension}/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/instructions.md`, assembled from the fifteen pending fragments (the fifteenth, from prisma#30918, declares no change). The app guide has 19 changes plus the Supabase restamp, opens with the order to do the steps in, and ships one script (`value-objects-in-storage`). The extension guide has 16 changes. None was dropped. The originals are archived unchanged under `upgrade-instructions/releases/8.0.0-rc.21-to-8.0.0-rc.22/sources/`. - **Corrections made while assembling:** - `mongo-runtime-takes-adapter` said `createMongoExecutionStack()` no longer takes a `driver`. prisma#30906, merged later, gave it one back, and the driver entry tells you to pass it. The entry now says what `main` does, and its detection no longer flags a stack built with a driver. - The convenience types entry now says to leave a `DateTime(as: ...)` field alone, and the step order renames the old types before rewriting the `temporal.*` aliases. Otherwise an agent would rename the `DateTime(as: temporal)` the alias table writes. - References to "this release's guide" now name the rc.20 → rc.21 guide they meant. - **Tests:** the upgrade-instruction tests read the published guides and script. The `value-objects-in-storage` tests no longer call live framework code: the two tests that checked the fixtures against this release's serializers are removed, and the one hash they computed is a recorded constant. - **Version bump:** every `package.json`, `pnpm-lock.yaml` (workspace specifiers only), the skill's `library_version`, and the Supabase contract version stamps. ## Checks run locally - `check:upgrade-coverage --mode publish --prev fad17c1 --head HEAD`: pass. The `--mode pr` form CI runs passes now that the tag exists. - `check:release-notes --mode pr`: pass - `lint:skills`: pass - `test/upgrade-instructions`: 102 files, 1,980 tests pass The prisma/web docs PR follows once this is published. Agent: paddington-54 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Added repeatable client `connect()` behavior, PostgreSQL extension declarations and additional types, plus MySQL ORM and SQL-builder read support. * **Breaking Changes** * PostgreSQL date/time defaults and types, value-object storage, MongoDB APIs and indexes, and extension-pack migrations have changed. Review the upgrade guidance before updating. * **Bug Fixes** * Improved precision for PostgreSQL `now()` values and clarified Prisma 7 `@db.*` diagnostics. * **Documentation** * Added Prisma 8.0.0-rc.22 release notes and upgrade instructions. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked issue
Refs TML-3537. This is the third of four pull requests for the remaining migration statements. The first two (namespaces, enum values) are merged. The fourth adds the value object and variant statements on top of this one.
At a glance
A model stores a value object in one
jsonbcolumn:Before this change,
contract.jsonkeptAddressin the domain plane, and the field named it:Now
Addressis a storage entity, and the field refers to it by its storage coordinate:On a managed Postgres table, the column gets a derived check.
migration planwrites it:Before, renaming
streetchanged only the domain plane. The storage hash stayed the same, andmigration planreported "No changes detected" while every row kept the old key. Now the rename changes the storage hash and the check, so the migration system sees it.Summary
The migration system tells database states apart by the storage hash. A value object's fields and a discriminator's values are stored data, so they now live in storage, where the hash covers them. The decision is recorded in ADR 309.
Decision
This PR ships four things:
storage.namespaces.<ns>.entries.valueObject.<Name>, with the definition they had in the domain plane. A domain field refers to one by storage coordinate. This is the first reference from the domain plane to the storage plane. A contract that still keepsvalueObjectsin the domain is refused with a message that says to re-emit it.<Base>.<field>(for exampleTask.type), holding the variants' values sorted. The base table's discriminator column refers to it, as an enum column refers to its enum's value set. MongoDB writes none, because its collection validator already lists each variant's value.<table>_<column>_shape_<hash>for a value object column, and<table>_<column>_check_<hash>for a discriminator column ("type" IN ('bug', 'feature')). The checks are content-named, so any change to the value object or the variants drops the old check and adds the new one.migration planwrites the migration with no operations and names what changed.db migrateanddb updatemove the marker to the new hash. Before, such a plan was refused.Every contract with value objects or variants is re-emitted, and the
prisma-8-demoinitial migration now creates the two checks. Projects upgrade with a script.Reviewer notes
contract.d.tsand the example migration snapshots changed hash.pnpm fixtures:checkis clean. The source changes are in the families' authoring, emit, ORM and validator code, the Postgres check derivation and the CLI's no-operation plan.jsonpathpredicate, ending inIS TRUE, so an unknown result fails. A required member must be present and of its codec's JSON type, a nullable member may be absent or JSONnull, and no other key is allowed. A value object that contains itself is checked down to where it refers back to itself, as the MongoDB validator does.jsonTypefield ('string' | 'number' | 'boolean' | 'object' | 'array' | 'any'), as MongoDB data types declarebsonTypes. The check reads it.TypeScriptrequires the field. At run time a codec package built before this release still loads; only a value object member that uses such a codec is refused, withCONTRACT.CODEC_JSON_TYPE_MISSING, naming the codec and the member.valueObjectstorage entity kind, with one schema both families use, because domain fields refer to it. ADR 221 says families and packs own entity kinds, so ADR 309 and a note in ADR 221 record the exception.<Base>.<field>in the same namespace. No authoring surface writes that name, so only a hand-written definition reaches the refusal.User.addressas plainjsonb, and the value object type tests read a new PSL fixture. This is recorded inprojects/migration-statements/deferred.md.mongo-demoandretail-storemigration chains faildb migrateon mongodb-memory-server withMIGRATION.SCHEMA_VERIFY_FAILED. They fail the same way onorigin/main, so this PR did not cause it. Filed as TML-3749.How it fits together
packages/1-framework/0-foundation/contract/src/domain-types.tsandpackages/1-framework/0-foundation/contract/src/storage-value-objects.ts.@@discriminatorwith its variants before the build, so the discriminator value set is in the hash. Seepackages/2-sql-family/2-authoring/contract-ts/src/build-contract.tsandpackages/2-sql-family/2-authoring/contract-psl/src/interpreter.ts.contract.d.tstypes a value object field from the storage plane, through a new, required sixth parameter ofFieldTypesFromDomain, so everycontract.d.tschanges. A SQL discriminator field is typed by its variants' values ('bug' | 'feature'). Seepackages/1-framework/0-foundation/contract/src/field-value-types.ts.contract print,contract inferand the statement resolver find a value object through the field's coordinate.contract printshare that derivation. Seepackages/2-sql-family/1-core/contract/src/check-expressions.tsandpackages/3-targets/postgres/1-target/src/core/check-expressions.ts.changedStorageEntitiesin--json). When rows break a new check, the runner reports which check and column, and the CLI gives the query that finds the rows and the way to keep their data. Seepackages/1-framework/3-tooling/cli/src/control-api/operations/migration-plan.tsandpackages/1-framework/3-tooling/cli/src/utils/runner-failure-advice.ts.Behavior changes & evidence
test/integration/test/cli-journeys/value-object-checks.e2e.test.ts(V1),packages/3-targets/postgres/1-target/test/check-expressions.value-object.test.ts.migration.tsbetween the drop of the old check and the add of the new one. Following that advice applies cleanly. Evidence:value-object-checks.e2e.test.ts(V2, V3).value-object-checks.e2e.test.ts(V4).migratemoves the marker. Evidence:value-object-checks.e2e.test.ts(V5),test/integration/test/cli-journeys/plans-with-no-operations.e2e.test.tsand its SQLite and MongoDB twins.test/integration/test/cli-journeys/value-object-validator.mongo.e2e.test.ts.valueObjectsin the domain is refused withCONTRACT.VALIDATION_FAILED, saying to re-emit it. Evidence:packages/1-framework/0-foundation/contract/test/validate-domain.test.ts.Every journey runs through
migration planandmigrate, and throughdb update, and ends withdb verify --schema-onlyclean and a further plan empty.Upgrade
The upgrade instructions are in
upgrade-instructions/pending/value-objects-in-storage/. For an app:node <guide>/scripts/value-objects-in-storage/value-objects-in-storage.ts. It rewrites every contract and snapshot, renames each snapshot directory to its new storage hash, and rewrites the migrations, refs,migration.tsandcontract.d.tsfiles that name an old hash. It prints each<old> -> <new>hash. A second run changes nothing.prisma db sign --db "$DATABASE_URL". A database you could not migrate first is signed at the new hash of its marker's hash withprisma db sign --contract <new hash> --no-advance-ref, then migrated.prisma contract emit.prisma migration plan, and apply it withprisma db migrate --advance-ref db --db "$DATABASE_URL". On MongoDB there is nothing to plan.Adding a check takes a lock on the table while Postgres reads every row, and a later change to the value object replaces the check and reads the rows again. The guide says so.
Extension authors:
contract.storage:contractModelToMongoResultShape,contractFieldToMongoFieldShapeandcompileMongoQuerytake the storage, andMongoValueObjectsis removed;ValueObjectTypesFromDomainis nowValueObjectTypesFromStorage, andFieldTypesFromDomaintakes the storage namespaces as a required sixth argument;jsonType, and the check expression types moved to@prisma/orm-postgres/family-contract/check-expressions.The script and both guides were run from start to finish on copies of
prisma-8-demoandmongo-demowith real migration histories, including a database behind the last migration and a row that breaks the new check. A secondmigration planafterwards writes nothing.Testing performed
value-object-checks.e2e.test.ts(10 cases) andvalue-object-validator.mongo.e2e.test.ts(2 cases).test/integration/test/sql-orm-client/(142 files), the upgrade script's integration test, the print round-trip files.pnpm fixtures:check,pnpm lint:deps,pnpm lint:ratchets,pnpm check:error-reference,pnpm check:upgrade-coverage --mode pr.test --coveragein each touched package.Skill update
skills/prisma-8/references/contract.mdsays value objects are lowered to storage value objects, describes the derived Postgres checks and the discriminator value set, and says a value object change is a migration.Follow-ups
--rename Address.street:Address.line1,--convert Bug,--delete Bug) are the next pull request. It also adds--backfillfor a new required value object member, so rows that lack it can be filled without a hand-written update.orm.Bug.create);orm.Task.variant('bug').createworks. This fails onmaintoo.projects/migration-statements/deferred.md: the SQL TypeScript builder has no value objects; SQL PSL does not namespace composite types; a column's value set reference is not checked against storage; the SQL ORM cannot write aBigIntorBytesmember of a value object.Alternatives considered
db update, which runs no data operations, still could not apply it.?&and-. One strictjsonpathpredicate covers nesting, lists, member types and nullability, and one form for every shape is simpler to derive and to read back.Checklist
git commit -s) per the DCO.TML-NNNN: <sentence-case title>form.Agent: radagast-20