Repository navigation
feat: add support for nested transaction rollbacks via savepoints in sql - #21678
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
155d16c to
5d80814
Compare
|
@Jolg42 Is it possible to verify that prisma/prisma-engines#4375 fixes the issue and gets the test to pass? |
|
Update: That surfaced that the PR in prisma-engines is not up do date with Update 2: |
|
Ummm, seems it is not working @LucianBuzzo. Or I messed up royally. Asking some colleagues for advice. |
|
@janpio I'll look into it on my end - any idea how to run just the |
|
@janpio I'm replicating the issue on my end - I think I might need to update the client code to maintain the same transaction ID in nested transactions 🤔 . I'm going to dig through and see what I can come up wiht. |
69291d4 to
5ffdd3d
Compare
|
Can be updated to use version from #22161 now |
Added rationale comments above #withActiveTransactionLock and #runSerialized explaining that transaction operations are serialized per tx id to avoid savepoint/depth/status races across await boundaries.
- Add optional Transaction.savepoint(action, name) API in @prisma/driver-adapter-utils and re-export SavepointAction. - Update binder to forward wrapped savepoint methods for error-capturing adapters. - Refactor TransactionManager nested start/commit/rollback to prefer adapter-provided savepoint SQL, with provider-based fallback retained behind a TODO. - Implement savepoint methods for pg, neon, ppg, planetscale, mariadb, libsql, better-sqlite3, and mssql transaction implementations. - Extend transaction-manager tests to verify adapter-provided savepoint SQL and optional release behavior. - Validation: transaction-manager test suite passes; touched packages type-check with tsconfig.build.json using --emitDeclarationOnly false --noEmit.
- Replace Transaction savepoint(action, name) with async createSavepoint/rollbackToSavepoint/releaseSavepoint in driver-adapter-utils and binder. - Refactor TransactionManager nested transaction flow to call adapter savepoint methods and remove provider fallback SQL synthesis. - Migrate adapter savepoint implementations (pg, neon, ppg, planetscale, mariadb, libsql, better-sqlite3, mssql, d1-http, d1-worker) to execute async savepoint operations. - Update transaction-manager tests for method-based savepoint behavior and missing-method error cases. - Simplify nested ITX scope symbol storage in getPrismaClient to TX_SCOPE_CONTEXT. - Document the new Transaction savepoint API shape in AGENTS.md.
|
@jacek-prisma let's go for the hatrick? 😅 🤞 |
|
Congratulations @LucianBuzzo! |
|
Haha thanks @janpio we got there in the end! 🎉 |
This adds a high level test that should pass if/when prisma/prisma-engines#4375 is merged.Transactions are now handled inside this repository, so the update to prisma-engines is no longer required.
This change adds support for handling rollbacks in nested transactions
in SQL databases. Specifically, the inner transaction should be rolled
back if the outer transaction fails.
To do this we keep track of the transaction ID and transaction depth so we can
re-use an existing open transaction in the underlying engine. This change also
allows the use of the
$transactionmethod on an interactive transaction client.Summary by CodeRabbit
New Features
Tests
Documentation