Repository navigation
TML-3467: The Prisma 7 reader keeps the columns and tables @ignore hides - #30672
Merged
Merged
Conversation
Project spec, plan and design notes for P-TML-1151, and the spec for slice 1 (TML-3468). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… its tables Each model is converted on its own into a table description (column descriptions, primary key, uniques, indexes, checks, resolved foreign keys, control policy) and its domain model. A single-table variant adds its columns to its base's table. The tables are then merged per namespace and table name, and one column lowering and one table lowering run over them before the contract is assembled as before. build-contract.ts is split into modules for each step. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ition Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… refuse a variant column its base table lacks A column's site is now a field of a model or a column of a table, and one helper gives the message subject and error metadata for both; messages for fields are unchanged. resolveForeignKey takes the source table and an owner name instead of a model. mergeTables refuses a single-table variant column that is not on its base table (CONTRACT.COLUMN_ON_STI_VARIANT) instead of adding it. Tests cover the merge and the namespace a relation to a shared model name resolves to. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
ContractDefinition gains tables: table nodes made of column nodes, a primary key, uniques, indexes, checks, foreign keys and a control policy. A column node is a field node without its field part, and FieldNode is now a column node plus that part. A foreign key may name its target table instead of a model. A table node for a modelled table adds only columns; one for any other table is a whole table. Both lower through the same column and table lowering as a model's table. Refused: a column declared by a field and a column node, table-level properties on a modelled table (CONTRACT.TABLE_OWNED_BY_MODEL), two table nodes for one table, and a foreign key to an undeclared table (CONTRACT.TABLE_UNKNOWN). The equation matrix shows each column kind lowers the same as a column node as it does as a field. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The enum handle decides the column's storage value set and its membership check, so it moves from the field part onto ColumnNode; FieldNode still has it. The equation matrix gains an enumType() row with whole-storage equality, replacing the two tests that showed the gap. A column a table node lists twice is now reported as listed twice by its table node. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Record the stage boundary as built, the enum handle on the column node, the variant refusals, the intended differences from main, and the items deferred from review. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…pes and names lowerTable emits a table's checks sorted by name, the order canonicalization uses, so moving a field from the middle of a model to a column node leaves the in-memory storage equal. A table node may not declare a column a single-table variant's field maps; the error names the variant field. An omitted or empty namespace means the default namespace for models, table nodes and table-targeted foreign keys alike. FieldNode extends ScalarMemberNode and ColumnNode; ValueObjectFieldNode takes its column part from ColumnNode; ModelNode and TableNode share TableProperties, which the table-owned-by-model check reads. One name per concept across both stages (enumTypeHandle, id). Column sites and foreign-key owners use one split, and a table node is named with its namespace. CONTRACT.COLUMN_ON_STI_VARIANT is renamed CONTRACT.VARIANT_COLUMN_NOT_ON_BASE_TABLE. The new node types are exported, and DEVELOPING.md describes the two stages. 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]>
compareCodeUnits is exported from @internal/contract/hashing-utils, and lowerTable sorts checks with it instead of a local copy. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
QA found the CONTRACT.TABLE_UNKNOWN message stated the problem without the fix. Also correct a column descriptor name in the slice spec example. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…el's namespace The model branch kept an empty namespaceId as the target namespace, so the foreign key pointed at a namespace that does not exist. It now uses the same rule as the table branch. 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]>
…s only from them getModelFields lists a model's own and inherited fields, and resolveFieldColumn refuses any name that is not a field of the model or of the variant in scope with ORM.FIELD_UNKNOWN (Model "<model>" has no field "<name>"). where shorthand and callbacks, orderBy, select, distinct, distinctOn, groupBy, cursor, aggregates, having, create, update and upsert data, single-table and multi-table variant creates, conflictOn, include nested select and scalar reducers, relation filters, relation join fields and fragments all resolve through it; nothing falls back to treating a name as a column. Row mapping drops any column no field maps, and a model with no fields maps to an empty row. A column the ORM picks itself, such as a key column, maps back to its field strictly. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…exemption Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ts only the fields its type offers Relation lookups by a caller's name use Object.hasOwn, so Object.prototype members are never relations. The where/orderBy accessor returns undefined for then and toJSON and the plain-object value for Object.prototype members, after fields and relations, and refuses every other unknown name. It accepts the model's own and inherited fields plus the narrowed variant's; select alone still accepts every variant's fields on an unnarrowed collection. A field whose column is missing from its table is an internal error. update() checks its data with assertModelFieldNames. The ORM.FIELD_UNKNOWN reference entry lists every surface. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The test for a field named then now declares that field with defineContract instead of patching contract data. The test for a relation that names a column as its join field is removed: no authoring surface produces that shape, and the build will refuse it. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
resolveModelColumns gives the columns a query on a model reads from a table: its own and inherited fields on that table, its variants' fields there, and on a multi-table variant's table the inherited key. The default projection (top level, include children, include distinct inner and outer), RETURNING, multi-table variant joins, include binding keys and the default include nested select use it instead of every column of the table. compileSelect and the RETURNING compilers take the model. An integration test builds a contract whose tables hold columns no field maps, through table nodes, and shows they are never read and cannot be named. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
No source can build a polymorphic contract with an extra column yet. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…nt's The top-level projection uses the pinned variant as its model, and include children and their binding keys use the include's pinned variant. A collection pinned to one single-table variant no longer reads a sibling variant's columns. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Relation lowering refuses a join column no field of its model maps (CONTRACT.RELATION_INVALID, reason join-column-not-a-field) instead of passing the column name through as a field name; the target side of a many-to-many relation names junction columns and is exempt. The SQL contract validators refuse a domain field with no storage entry and an execution default on a column no field maps. The build warns (PN_COLUMN_REQUIRED_UNMAPPED) when a table some model maps holds a required column with no default that no field maps, since every ORM insert into it fails. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The hydration test leaves the field out of the domain as well as storage. The two printer refusal tests now pin that the contract is refused when it is read, before the printer sees it. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
validateSqlContractFully refuses a domain field with no storage entry and an execution default on a column no field maps before contract print sees the contract, so refuseFieldsWithoutColumn and refuseUnwrittenExecutionDefaults could no longer run. They are removed with the writtenExecutionDefaults set only they read, and the two matching CONTRACT.PRINT_UNSUPPORTED bullets leave the error reference. 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 extension fragment states that every surface refuses a name that is not a field with ORM.FIELD_UNKNOWN, and that conflictOn now raises ORM.FIELD_UNKNOWN instead of ORM.ARGUMENT_INVALID. The error reference describes the current behaviour only. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
validateRelationJoinFields checks every relation's local fields against its model and its target fields against the target model, own and inherited; the target side of a many-to-many relation (junction columns) and a cross-space target are not checked. A contract loaded from JSON is refused the same way the build refuses it. The execution-default validator now gives its reason as execution defaults belonging to fields. Two family-sql test contracts that joined on names that were not fields are corrected, and the hydration test whose local join field had no column now expects the refusal. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… where it comes from The field-to-column maps are getOwnFieldColumns, getModelFieldColumns, getModelAndVariantFieldColumns and getModelAndEveryVariantFieldColumns, with getOwnColumnFields and getModelColumnFields the other way; one FieldColumn type replaces two. columnOfCallerField refuses a name a caller passed with ORM.FIELD_UNKNOWN; columnOfContractField and fieldOfColumn resolve names the contract or the ORM chose and raise an internal error, which a relation join field now does since the contract validators refuse an unmapped one. getColumnsReadOnTable sits beside the other field functions on the shared cachedFor cache, and the variant placement rule is written once on getModelAndVariantFieldColumns. A multi-table variant create reuses that map; errors on a narrowed select or accessor name the variant; compileSelect takes the model before the table like the mutation compilers. Relation shorthand filters check names before reading the accessor, an unnarrowed select of a field two variants map to different columns reads both, and fragments see inherited fields. The warning sink pattern doc and the contract-ts README list PN_COLUMN_REQUIRED_UNMAPPED. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ation, and record the upgrade for applications The cross-space branch of relation lowering now resolves its local join columns through joinFieldOf, before its nullability check, so an unmapped column is refused at build time with the join message instead of failing later. The app audience gets the same upgrade instruction as the extension audience. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
When the refused name is the column of a field of the model, the ORM.FIELD_UNKNOWN message names that field and the payload carries it as fieldForColumn. When the name is a column of the model's tables that no field maps, the message says the ORM cannot read or write it. Otherwise the message is unchanged. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The column can be on a variant's table rather than the table of the model the caller addressed, so the ORM.FIELD_UNKNOWN hint now names the table. 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]>
…ide when reading a Prisma 7 schema An @@ignore model becomes a table with no model: its columns, keys, indexes and foreign keys. Foreign keys reach its table by name. An implicit many-to-many junction with an @ignore list field or an @@ignore model on either side is kept as a table with no model. Column types with no Prisma 8 codec are refused inside @@ignore models too, and an @@ignore model's table collides with another model's like any table. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…cross schemas Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ject upgrades The handover test marks a field @ignore and a model @@ignore and removes them again: the storage hash stays, migration plan reports no changes, and Prisma 7 sees no drift. A new test upgrades a project signed without the ignored objects: it plans a migration that records them, signs again with no findings, migrates nothing, and then plans nothing. The upgrade instruction tells Prisma 7 projects that use @ignore to do the same. The planner golden manifest and the reader docs follow. 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]>
… paths as they really behave Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… refusals and names The upgrade instruction names the refusals ignored objects can now meet and gives both ways to bring each existing database to the new hash after the handover, plus the recovery from signing first; the upgrade test proves all three. The primary-key refusal gives its reason and both fixes. ignoredFields holds only fields marked @ignore, ignored junctions are built as tables first, and the names say ignored. New fixtures pin an @@ignore model with a sort argument, an ignored JSON null default and an ignored relation with SetNull over a required field. The READMEs drop the advice to ignore codec-less columns and say contract print refuses ignored storage for now. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…the primary-key refusal's reason in the Prisma 7 source spec Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…fusal list, and plain migrate then sign The primary-key refusal says Prisma 7 requires @ignore on every relation field pointing to a model marked @@ignore. The upgrade instruction lists only refusals that are new, as examples. The upgrade test proves plain db migrate leaves the db ref behind and db sign then catches it up, and the example README describes all four cases. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Contributor
@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-postgres
@prisma/orm-sqlite
@prisma/orm-target-mongo
@prisma/orm-target-postgres
@prisma/orm-target-sqlite
@prisma/orm-toolchain
commit: |
Contributor
size-limit report 📦
|
wmadden
approved these changes
Oct 9, 2026
…-prisma7-ignore-keeps-storage Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> # Conflicts: # projects/unmapped-storage/design-notes.md # projects/unmapped-storage/plan.md
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 9, 2026
… print and Prisma 7 journeys The round-trip test lists the Prisma 7 fixtures with ignored storage as print refusals until TML-3469. The Prisma 7 journey expects LegacyThing and no strict findings for ignored storage. The print journey prints the fixtures with their ignored fields and models removed, and checks that print refuses the schema as it is. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
wmadden-electric
enabled auto-merge
October 9, 2026 15:59
…-prisma7-ignore-keeps-storage Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> # Conflicts: # examples/prisma7-adoption/test/handover.test.ts
…ed, now that the ledger is not reported Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
opensource-fork-sync Bot
pushed a commit
to cla7aye15I4nd/opensource-prisma__orm
that referenced
this pull request
Oct 13, 2026
## At a glance This PR removes `projects/unmapped-storage/`, the planning files of the project "Storage a model does not map". Its four slices have merged, and its decisions live in ADR 267 ([prisma#30641](prisma#30641)). It also corrects one stale phrase in the Prisma 7 source project's slice 1 spec: an `@ignore` field used by an index is now kept, not refused. Merge this after ADR 267 ([prisma#30641](prisma#30641)), because the project's done conditions include that ADR, and after [prisma#30705](prisma#30705), which makes the code match what ADR 267 says about a model with no fields. ## What the project delivered | Slice | PR | Outcome | |---|---|---| | 1 | [prisma#30665](prisma#30665) | A contract definition can hold columns and tables no model maps, lowered by the same code as a model's table. | | 2 | [prisma#30667](prisma#30667) | The SQL ORM reads and writes only the columns a model's fields map; naming any other column throws `ORM.FIELD_UNKNOWN`. | | 3 | [prisma#30672](prisma#30672) | The Prisma 7 reader keeps `@ignore` fields and `@@ignore` models as columns and tables, so adding or removing `@ignore` after the handover plans nothing. | | 4 | [prisma#30671](prisma#30671) | Prisma 7's `_prisma_migrations` table is left out of introspection, so `db verify --strict` passes on a database Prisma 7 built. | ## Done conditions - Adding `@ignore` to a field and `@@ignore` to a model in `examples/prisma7-adoption` plans no operations, and so does removing them. Met: `examples/prisma7-adoption/test/handover.test.ts`. - The handover test asserts strict verify reports nothing unclaimed. Met: same file, after every edit. - `findMany()` with no `select` returns no extra column, and `create` with its name throws `ORM.FIELD_UNKNOWN`. Met: `test/integration/test/sql-orm-client/unmapped-storage.test.ts`. - ADR 267 is merged. Open: [prisma#30641](prisma#30641) awaits review. - The Prisma 7 project's slice 1 text no longer says ignored objects are omitted. Met by slice 3, plus the phrase corrected here. ## Where the deferred items went - Many-to-many `on.targetFields` holds junction column names: TML-3570. - Whether validator tests may build malformed contracts by hand: TML-3571. - A model with no fields types its rows as accepting any key: fixed in [prisma#30705](prisma#30705) (TML-3536), because ADR 267 states the fixed behaviour. Its review found TML-3572 (the SQL ORM builds inputs from the row type), TML-3573 (Mongo contracts built without emitting) and TML-3574 (other empty maps in emitted types). - Prisma 8 syntax for unmapped columns and tables, the polymorphic integration test, and rebuilding `buildMixedPolyContract` through a source: TML-3469. - A relation to a bare model name used in two namespaces resolves by list order: TML-3280. - A junction declared only by a table node is refused: kept as designed, per ADR 267. - A cross-space foreign key carries the target model's name as well as its table: checked and kept; the name is real information about the target (TML-3569, cancelled). ## Retro - **Every path an upgrade instruction describes needs a test.** The slice 3 spec first described the post-handover upgrade order wrongly, then claimed migrating was unsafe. Tests for each path (sign, `migrate --advance-ref db`, migrate then sign, sign-first recovery) showed the real behaviour, and the instruction and ADR were corrected from them. - **Run the cross-cutting test families on a merge of main before queueing.** Slices 2 and 3 each left the merge queue once. Tests on main had changed or been added after the PR's own CI: ported `_count` tests for slice 2, and print refusals plus Prisma 7 journeys for slice 3. Running the print round-trip and Prisma 7 CLI journey files after merging main would have caught both. - **After merging a sibling slice, run the shared test file even when git merges it cleanly.** Slices 3 and 4 both edited `handover.test.ts`. The merge was clean apart from one comment, but left a call to a helper slice 4 had renamed. - **Approved means queue it at once.** Slice 2 sat approved but not queued for hours. Project: [Storage a model does not map](https://linear.app/prisma-company/project/storage-a-model-does-not-map-97488a1828eb). Agent: anansi-36 Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[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.
At a glance
Before: the contract read from this Prisma 7 schema had no
legacy_keycolumn, noaudit_rowstable and no foreign key from it. So it described a different database from the one Prisma 7 built.After: the contract's storage has
Userwithid,emailandlegacy_key, andaudit_rowswith its primary key and its foreign key toUser. The domain has modelUserwithidandemailonly. In the handover example, adding these@ignoreattributes after Prisma 8 has taken over migrations plans nothing, and so does removing them.The decision
The Prisma 7 reader describes exactly what the schema says the database holds, or refuses (ADR 252).
@ignoreand@@ignorehide a field or model from Prisma 7's client, not from its database, so the reader now keeps them as storage:@ignorescalar field becomes a column node on its model's table, with its type, nullability and column default. It gets no execution default (uuid(),cuid(),@updatedAtand similar), because the ORM never writes the column. A required column with no default triggers the existingPN_COLUMN_REQUIRED_UNMAPPEDwarning.PSL.PRISMA7_IGNORED_FIELD_REFERENCED, because the model would have no field that identifies a row.@ignorerelation field keeps its foreign key. A relation that is not ignored but joins on an ignored field stays refused.@@ignoremodel becomes a table node with its columns, keys, indexes and foreign keys. Foreign keys to and from it target the other table by model when it has one, and by table name when it does not.The table node and the column node come from ADR 267 (#30641). The ORM changes that keep queries to a model's own fields are in #30667.
What can now be refused
@ignoreor@@ignoreas a way around a missing codec. That is no longer true, and the messages no longer say so.@@ignoremodel with@@index([at(sort: Desc)]), or an ignoredJsonfield with@default("null"), is now refused. Before, it loaded only because the object was dropped. The upgrade instruction lists the diagnostics.Upgrading a signed project
A project that uses
@ignoreand signed with an earlier Prisma 8 gets a new storage hash.prisma contract emit, thenprisma db sign.prisma contract emit, thenprisma migration plan, then bring each existing database to the new hash withprisma db signorprisma db migrate --advance-ref db. Signing before planning makes the next plan fail withMIGRATION.HASH_NOT_IN_GRAPH;migration plan --from <previous hash>recovers.The instruction is
upgrade-instructions/pending/prisma7-ignore-keeps-storage/app/instructions.md.How it is proven
ignored-field-defaults,ignored-field-in-index,ignored-relation-field,ignored-models,ignored-model-many-to-manyand others hold the expected contract;ignored-field-no-codec,ignored-field-in-primary-keyandignored-objects-meet-every-rulehold the expected refusals. Each fixture schema validates with Prisma 7.10.0.examples/prisma7-adoption/test/handover.test.ts: after the handover, adding@ignoreand@@ignoreplans nothing with the storage hash unchanged, and removing them does too; Prisma 7'smigrate diffis empty for both edits.examples/prisma7-adoption/test/upgrade-ignore.test.ts: four upgrade paths (sign;migrate --advance-ref db; plain migrate then sign; sign first, then recover with--from). Each ends with verify finding nothing and the next plan empty.interpreter-fixtures.integration.test.tsreports no ignored object as unclaimed.Not in this PR
contract printstill refuses a contract with ignored storage, because Prisma 8 has no syntax yet for a column no field maps (TML-3469). The docs tell such projects to keep the Prisma 7 schema as the contract source until then._prisma_migrationstable is handled in TML-3453: db verify --strict passes on a database Prisma 7 built, because Prisma 7's ledger is left out #30671.Alternatives considered
Project: Storage a model does not map. Closes TML-3467 and TML-3462.
Agent: anansi-36
Summary by CodeRabbit
@ignoreor@@ignore, covering migration planning and database signing.