Skip to content

[master] Savepoint Support for Database Transactions #55996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yitzwillroth
Copy link
Contributor

@yitzwillroth yitzwillroth commented Jun 11, 2025

This pull request introduces an API for utilizing database transaction savepoints (while fully respecting the framework’s usage of savepoints under the hood for simulating nested transactions) giving developers greater control over database commit logic and enabling the use of more complex failure handling patterns.

Features:

  • Comprehensive support for database savepoints within transactions, allowing developers to create, rollback to, release, and purge savepoints within transactions.
  • New events for savepoint creation, rollback, and release, enabling advanced transaction control and event handling.
  • Expanded database interface and facade with methods to manage and query savepoints, enhancing transaction flexibility across supported database drivers (MySQL, MariaDB, PostgreSQL, SQLite, SQL Server with limitations).
  • New static methods for savepoint operations are accessible via the database facade.
  • Improved compatibility and error handling for savepoint operations, including clear feedback when unsupported on certain database systems.

Benefits:

  • Granular Error Handling: Ability to recover from partial failures within transactions
  • Performance: Avoid restarting entire transactions for minor failures
  • Complex Business Logic: Support for multi-step processes with checkpoints
  • Laravel-esque API: Follows Laravel's conventions and provides both manual and callback-based APIs

As this is a bit bigger lift, I've submitted initially without tests for feedback. Presuming feedback is generally positive, I'll add tests (current failing tests are related to initializeSavepointManagement() being called in the Connection constructor and would require a minor adjustment to the mock).


Change Summary
Pasted Graphic

Bonus poem from CodeRabbit:

Hopping through code, I found a new land,
Where savepoints abound, and transactions are grand.
With rollbacks and releases, I leap without fear,
Each query a burrow, each savepoint a cheer!
🐇✨
Now, my database garden is tidy and bright—
Thanks to these changes, all bugs take flight!

Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

*
* @throws \Throwable
*/
protected function createSavepoint()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you move this method below within MR?

Copy link
Contributor Author

@yitzwillroth yitzwillroth Jun 11, 2025

Choose a reason for hiding this comment

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

Organization. The Connection uses the trait, so it's still accessible in the same place, just lives together with the other (new) savepoint methods.

@yitzwillroth yitzwillroth marked this pull request as ready for review June 11, 2025 20:22
@yitzwillroth yitzwillroth changed the title :feat: Savepoint Support for Database Transactions [Master] Savepoint Support for Database Transactions Jun 11, 2025
@yitzwillroth yitzwillroth changed the title [Master] Savepoint Support for Database Transactions [master] Savepoint Support for Database Transactions Jun 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants