Repository navigation
sql-orm-client: update and delete filtered related rows on many-to-many relations in update() - #31016
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
size-limit report 📦
|
@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-mariadb
@prisma/orm-mongo
@prisma/orm-mysql
@prisma/orm-postgres
@prisma/orm-postgres-contrib
@prisma/orm-sqlite
@prisma/orm-target-mariadb
@prisma/orm-target-mongo
@prisma/orm-target-mysql
@prisma/orm-target-postgres
@prisma/orm-target-sqlite
@prisma/orm-toolchain
commit: |
bee797c to
9a6b79f
Compare
9a6b79f to
a20fb3d
Compare
a20fb3d to
5142d53
Compare
The Postgres, SQLite and MySQL renderers accepted only one-column subqueries. A ListExpression compared with IN to a subquery now renders as a row value, and the subquery must project one column per value. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Steven McClankerton <[email protected]>
5142d53 to
68df656
Compare
…elation write the targets linked through the junction The write on the target table keeps the caller filter and adds key IN (SELECT link FROM junction), and the key of the parent goes into that subquery: a FilterData condition lands in the SELECT whose FROM alias its column names. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Steven McClankerton <[email protected]>
… no changes from extension authors Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Steven McClankerton <[email protected]>
…ST already expresses Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Steven McClankerton <[email protected]>
68df656 to
f781591
Compare
…risma#31018) Ports the upstream engine tests for nested `updateMany` and `deleteMany` inside `update()`, which prisma#31013, prisma#31014 and prisma#31016 made possible. Fourth part of slice `filtered-many-writes` of the nested-mutations project. Stacked on prisma#31016. Tests and fixtures only. Of the +5743 lines, 5150 are emitted fixtures (`contract.json`, `contract.d.ts`); tests are +380, hand-written fixtures +175, ledgers and docs +38. ## Changes - **`nested_update_many_inside_update.rs` (8) and `nested_delete_many_inside_update.rs` (6)**, ported into `test/integration/test/ports/engines/writes/nested_mutations/already_converted/`, all passing. Both suites share four fixtures under `nested_mutations/_fixture/`, one per relation shape: one-to-one optional, parent-to-many with a required child, parent-to-many with an optional child, and many-to-many (junction keys cascade, as upstream's implicit table does). - **One variant per relation shape, by owner decision (2026-11-12).** Upstream runs most of these tests over `relation_link_test`, a matrix of up to 32 schema variants per relation shape (81 fixtures in prisma#30642). Nested filtered writes do not depend on the shape of the key, and composite keys are covered by prisma#31016's integration tests, so each test is ported against one representative variant and the other variants are recorded as not ported in `engines/non-ported/writes/nested_mutations/already_converted/<suite>/<suite>.md`. This is an exception to the matrix rule of `projects/port-all-tests/spec.md`, recorded in the ports README. - **Rejections on to-one relations** (`one2n_rel_error_nested_um`, `o2n_rel_fail`) assert Prisma 8's `ORM.RELATION_MUTATION_UNSUPPORTED` (`reason: 'to-one-relation'`); upstream answers with error 2009. The checklist notes the difference. - **`unchecked_nested_update_many.rs` › `disallow_write_parent_inline_rel_sclrs`** runs on an empty database and asserts `ORM.RELATION_MUTATION_INVALID` (`problem: 'parent-link-column'`), with its own fixture (upstream's `ModelA`/`ModelB` schema). - **`combining_different_nested_mutations.rs` › `create_then_disconnect`** (taken out of prisma#31013), now on the shared many-to-many fixture. - `projects/port-all-tests/checklists/engines-writes.md`: the 16 entries ticked. ## Verification - The ported files on PGlite: 16 of 16 pass. - `test/integration` typecheck and lint, `fixtures:check`, build, `check:upgrade-coverage` against prisma#31016. 🤖 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 integration coverage for nested child creation and disconnection, filtered nested updates and deletes, and invalid nested relation updates. * **Documentation** * Documented representative relation-shape coverage and listed nested mutation variants that are not ported. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Steven McClankerton <[email protected]> Co-authored-by: Steven McClankerton <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
…ed-row updateAll and deleteAll (prisma#31021) Documents nested writes in the `sql-orm-client` README and the error reference, including what slice `filtered-many-writes` of the nested-mutations project added: the array return from a relation callback (prisma#31013) and `updateAll`/`deleteAll` on related rows (prisma#31014, prisma#31016). Last PR of the slice; stacked on prisma#31020. Docs only. ## Changes - **`sql-orm-client` README, new "Nested writes" section:** the relation callback and a table of each operation with where it is available and on which relations; the many-to-many limits that already existed (`disconnect()` without criteria, junction tables with required columns); one transaction per multi-statement write; the array return (order, empty array, at most one operation on a to-one relation, the errors); `where(w).updateAll(data)`/`deleteAll()` and the forms without `where`, touching only rows related to the record (by foreign key, or by a junction row), with the filter forms `where` takes, the parent-link rule and update defaults; and that many-to-many `deleteAll()` leaves junction rows to the database's foreign-key action. No user doc under `docs/` covered nested writes, so the README is where they are described. - **Error reference:** `ORM.RELATION_MUTATION_INVALID` and `ORM.RELATION_MUTATION_UNSUPPORTED` list the new cases and the payload fields the code sends (`index`, `problem: 'parent-link-column'`, `fields`, `reason: 'to-one-relation'`, `operations`, `reason: 'junction-required-columns'`, `junction`). - An `upgrade-instructions/pending/` entry declaring no changes, which the coverage check requires for a README under `packages/3-extensions/`. ## Verification `check:error-reference`, `check:upgrade-coverage` against prisma#31020, `lint:docs`. 🤖 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 * **Documentation** * Expanded guidance on nested relation writes, supported operations, transaction behavior, and bulk updates and deletes. * Clarified error reference details for invalid nested operations, unsupported relation operations, and related error information. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Steven McClankerton <[email protected]> Co-authored-by: Steven McClankerton <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Inside
update(),updateAll()anddeleteAll()now work on many-to-many relations: they write only the target rows linked to the parent through the junction. Third part of slicefiltered-many-writesof the nested-mutations project (spec:projects/nested-mutations/slices/filtered-many-writes/spec.md). Stacked on #31014.Changes
mutation-graph/nested-mutations.ts): a many-to-manyupdateAll/deleteAllgoes through the sameaddUpdateAll/addDeleteAllas the one-to-many and top-level ones. The related rows' description gets one more filter,target.key IN (SELECT j.target_fk FROM junction j), with the junction under its own alias, and the parent'sFilterDataedge targetsj.parent_fk. There is no junctionFindnode and no rule. The interim many-to-many rejection from sql-orm-client: update and delete filtered related rows on one-to-many relations in update() #31014 is removed.deleteAll()does not touch junction rows; the database's foreign-key action decides (with keys that do not cascade, its error rolls back the whole update).mutation-graph/filtered-statement.ts): aFilterDataedge's condition goes into theSELECTwhoseFROMalias is the alias of the edge's target column: the outerWHEREfor the statement's own tables, as every edge does today, or theWHEREof the subquery that reads that alias. An alias found in neither is anInternalError.Find,Update(both paths) andDeleteuse it.IN(Postgres, SQLite and MySQL adapters): a composite target key is(t.k1, t.k2) IN (SELECT j.k1, j.k2 FROM …), which the SQL AST already expresses as aListExpressionINaSubqueryExpr. The renderers used to refuse anyINsubquery of more than one column; they now accept one with as many columns as the row value and refuse a mismatch withRUNTIME.AST_INVALID.connectbefore anupdateAllin the same array is applied first and theupdateAllsees the new link.Why
Design record D8 in
projects/nested-mutations/mutation-graph.mdchoseIN (SELECT …)because a bound list of linked keys grows with the relation and exceeds bound-value limits. D8 reached it through a junctionFindinlined by a peephole; the parent's key is only known at run time and reaches nodes throughFilterDataedges, so either way an edge's condition has to be placed inside a subquery. Building the subquery in the translation needs only that placement, without a junction node, an inlining rule, or rules that run on databases withoutRETURNING. A new AST form for row-valueINwas not needed: the AST already had one, and only the renderers refused it.Verification
@internal/sql-orm-client: typecheck, lint, 2008 tests (graph tests of the subquery write and ofconnectthenupdateAllwith state edges; placement tests forUpdateandDeleteand the unknown-alias error).deleteAll()with cascading and with non-cascading junction keys (rolled back);connectthenupdateAll; a composite-key target. On SQLite: another user's tag unchanged, cascadingdeleteAll(), a composite-key target. MySQL facade suite against a localmysql:8.4(188 passed, 1 skipped).lint:deps,lint:ratchets(casts unchanged),check:upgrade-coverageagainst sql-orm-client: update and delete filtered related rows on one-to-many relations in update() #31014.🤖 Generated with Claude Code
Summary by CodeRabbit
updateAll()anddeleteAll()operations are supported for many-to-many relations, including relations with composite keys.INsubqueries are supported when the subquery returns the same number of columns as the compared row.