Skip to content

feat: Add typed interface for savepoints in transactions - #2950

Merged
SandPod merged 7 commits into
serverpod:mainfrom
SandPod:2938-support-savepoints-in-transactions
Nov 27, 2024
Merged

SandPod merged 7 commits into
serverpod:mainfrom
SandPod:2938-support-savepoints-in-transactions

Conversation

@SandPod

@SandPod SandPod commented Nov 11, 2024 •

Copy link
Copy Markdown
Contributor

Closes: #2938

Adds typed support for Postgres savepoints in transactions.
When a savepoint is created a typed object is returned that can be used to either release or rollback the savepoint.

A typical transaction can looks like this:

await session.db.transaction<void>(
  (transaction) async {
    var savepoint = await transaction.createSavepoint();
    await SimpleData.db
        .insertRow(session, SimpleData(num: 1), transaction: transaction);
    await savepoint.rollback();
  },
);

Where transaction.createSavepoint() creates the typed savepoint and savepoint.rollback() rollsback the transaction to the savepoint state.

This PR also migrates the test framework to use the new savepoint system.

Additional context

The tests in this PR might be updated if we fix: #2546

Then we could validate that we get the expected errors.

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

If you need help, consider asking for advice on the discussion board.

Breaking changes

None - only internal changes to the postgres adapter was required along with non breaking new methods for the transaction interface.

@SandPod
SandPod marked this pull request as draft November 11, 2024 13:38
@SandPod
SandPod marked this pull request as ready for review November 11, 2024 13:50

@hampuslavin hampuslavin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super clean! 💯 Just found a single typo nit

Co-authored-by: Hampus Lavin <[email protected]>
@SandPod
SandPod merged commit bc40ec7 into serverpod:main Nov 27, 2024
@SandPod
SandPod deleted the 2938-support-savepoints-in-transactions branch November 27, 2024 11:11
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support transaction savepoint and rollbacks

2 participants