-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Transaction SAVEPOINT support #12898
Description
Problem
I would like to use the SQL SAVEPOINT (nested transaction) feature for nesting transactions.
My use case: running integration tests inside of isolated transactions. More details in prisma/web#6604
I would like to temporarily replace BEGIN statements with SAVEPOINT statements for code executed in my test. The idea is that I want to wrap each test inside its own transaction so it's isolated and doesn't see data from any other tests running at the same time, and issue a ROLLBACK at the end so the test never actually commits anything to the DB.
To make this work I need to disable any code running inside the test from beginning a new transaction, instead creating a savepoint. More details can be seen in prisma/web#6604.
Suggested solution
Something like SQLAlchemy perhaps: https://docs.sqlalchemy.org/en/14/orm/session_transaction.html#using-savepoint
Alternatives
Currently I have to run integration tests one by one and truncate every table at the end of each test. This is horribly slow and inefficient and prevents me from running my tests in parallel.