feat(postgres): wire ORM to transactions#347
Open
aqrln wants to merge 1 commit intotransaction-api-m1from
Open
feat(postgres): wire ORM to transactions#347aqrln wants to merge 1 commit intotransaction-api-m1from
aqrln wants to merge 1 commit intotransaction-api-m1from
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/emitter
@prisma-next/migration-tools
@prisma-next/vite-plugin-contract-emit
@prisma-next/runtime-executor
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-pipeline-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
This was referenced Apr 15, 2026
13fd20e to
c15f5d9
Compare
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.
PR Stack: Transaction API
maindb.transaction()+tx.sql#345tx.orminto transactions#346Closes https://linear.app/prisma-company/issue/TML-1912/orm-transaction-support
Summary
Implements Milestone 2 of the transaction API: wiring
tx.ormso that ORM collections used inside adb.transaction()callback execute against the transaction connection. Also adds relations to the e2e fixture contract to enable nested-mutation integration tests.Implementation
The production change is surgical — ~12 lines in a single file.
PostgresTransactionContextgainsormTransaction-scoped ORM client construction
Inside
transaction(), a newormBuilder()creates an ORM client bound to the transaction'sexecute:Key design decision: The
runtimeobject passed toormBuilderexposes onlyexecute()— it deliberately omitsconnection()andtransaction(). This ensureswithMutationScopein the mutation executor naturally falls through to direct scope reuse instead of attempting a nested transaction. Zero changes to the mutation executor were needed.Tests
Unit tests (4 new)
transaction()providesormon the tx contextpostgres.test.tstx.ormis the transaction-scoped proxytx.ormhas the same type asdb.ormtransaction.types.test-d.tsexecuteNestedCreateMutation()reuses scope when runtime lackstransactionmutation-executor.test.tsexecuteon the transaction runtimewithMutationScopereuses runtime when notransactionorconnectionexistsmutation-executor.test.tsE2E integration tests (5 new — real PGlite database)
tx.orm.Post.create()with nestedauthor: (r) => r.create(...)— both rows existcreate()thenwhere().first()sees the rowE2E fixture contract changes
The fixture contract gained relations across all three models to enable nested-mutation tests:
Userposts1:N→PostUser.id→Post.userIdPostauthorN:1→UserPost.userId→User.idPostcomments1:N→CommentPost.id→Comment.postIdCommentpostN:1→PostComment.postId→Post.idThe contract definition was refactored to compose models with
rel.belongsTo()/rel.hasMany()before passing todefineContract, using lazy refs (() => Comment) for circular relations.Design patterns
{ execute }object; omittingtransaction()/connection()makeswithMutationScopefall through naturallyRuntimeQueryablepassed toormBuilderis a narrowed shape, preventing accidental nested-transaction creationdb.orm.User.first()before entering transactions to force contract verification (which needs its own connection) outside the transaction, avoiding deadlock on single-connection PGliteFiles changed
packages/3-extensions/postgres/src/runtime/postgres.ts— addtx.ormconstructionpackages/3-extensions/postgres/test/postgres.test.ts— 1 unit testpackages/3-extensions/postgres/test/transaction.types.test-d.ts— 1 type testpackages/3-extensions/sql-orm-client/test/mutation-executor.test.ts— 2 unit teststest/e2e/framework/test/transaction-orm.test.ts— 5 e2e tests (new)test/e2e/framework/test/fixtures/contract.ts— add relations to fixturetest/e2e/framework/test/fixtures/generated/contract.{d.ts,json}— regeneratedtest/e2e/framework/package.json+pnpm-lock.yaml— add@prisma-next/postgresdev depprojects/orm-client-transaction-api/{plan,spec}.md— mark M2 tasks done