GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||
GeezerVison is showing github.com — TML-3537: Changing a value object or a variant is a migration, and Postgres checks value object and discriminator columns by wmadden-electric · Pull Request #30869 · prisma/orm Conversation
Contributor
Linked issueRefs 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 glanceA model stores a value object in one type Address { street String city String } model User { id Int @id address Address? @@map("user") } Before this change, "domain": { "namespaces": { "public": { "models": { "User": { "fields": { "address": { "nullable": true, "type": { "kind": "valueObject", "name": "Address" } } } } }, "valueObjects": { "Address": { "fields": { "city": { "nullable": false, "type": { "kind": "scalar", "codecId": "pg/text@1" } }, "street": { "nullable": false, "type": { "kind": "scalar", "codecId": "pg/text@1" } } } } } } } } Now "domain": { "namespaces": { "public": { "models": { "User": { "fields": { "address": { "nullable": true, "type": { "kind": "valueObject", "plane": "storage", "namespaceId": "public", "entityKind": "valueObject", "entityName": "Address" } } } } } } } }, "storage": { "namespaces": { "public": { "entries": { "valueObject": { "Address": { "fields": { "city": { "nullable": false, "type": { "kind": "scalar", "codecId": "pg/text@1" } }, "street": { "nullable": false, "type": { "kind": "scalar", "codecId": "pg/text@1" } } } } } } } } } On a managed Postgres table, the column gets a derived check. CONSTRAINT "user_address_shape_<hash>" CHECK ("address" IS NULL OR jsonb_path_match("address", 'strict $.type() == "null" || ($.type() == "object" && exists($.keyvalue() ? (@.key == "city" && (@.value.type() == "string"))) && exists($.keyvalue() ? (@.key == "street" && (@.value.type() == "string"))) && !exists($.keyvalue() ? (@.key != "city" && @.key != "street")))') IS TRUE) Before, renaming SummaryThe 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. DecisionThis PR ships four things:
Every contract with value objects or variants is re-emitted, and the Reviewer notes
How it fits together
Behavior changes & evidence
Every journey runs through UpgradeThe upgrade instructions are in
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:
The script and both guides were run from start to finish on copies of Testing performed
Skill update
Follow-ups
Alternatives considered
Checklist
Agent: radagast-20
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions…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
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
|
There was an error while loading. Please reload this page.
@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: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
size-limit report 📦
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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
There was an error while loading. Please reload this page.
…-value-objects-storage
…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]>
There was an error while loading. Please reload this page.
`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]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.