use-transactions-for-atomicity
Installation
SKILL.md
Summary
When an operation requires multiple writes (INSERT, UPDATE, DELETE) to the database, wrap them in a Transaction. If any part fails, the entire transaction should be Rolled Back.
Rationale
- Integrity: Prevents partial updates (e.g., money deducted but item not shipped) which leave the database in an inconsistent state.
- Concurrency: Transactions (depending on isolation level) help manage concurrent access to the same data.
Guidance
- Start: Begin transaction.
- Execute: Perform all writes.
- Check Error: If any error occurs,
ROLLBACKimmediately. - Commit: If all succeeded,
COMMIT. - Defer: In Go/backend code, ensure
Rollbackis deferred in case of panics or early returns.