sql-transaction-consistency-review

Review SQL-backed Rust changes for transaction atomicity, isolation, and side-effect ordering defects.

2|Updated May 6, 2026
One-click install
npx skills add https://github.com/bpcakes/jig-skills --skill sql-transaction-consistency-review-bpcakes
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-transaction-consistency-review
Source: https://github.com/bpcakes/jig-skills/tree/main/plugins/jig-rust/skills/sql-transaction-consistency-review
Command: npx skills add https://github.com/bpcakes/jig-skills --skill sql-transaction-consistency-review-bpcakes

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Multi-step database writes in Rust services often break domain invariants through missing transactions, pool-versus-transaction handle confusion, SELECT-then-INSERT races, and side effects emitted before commit. This Skill gives an agent a structured review workflow to find those concrete consistency defects with file locations and fixes. ## Core Features & Use Cases - Transaction boundary analysis: Maps state-changing flows, names the invariant at risk, and verifies every query uses the transaction handle rather than a pool or separate connection. - Concurrency and isolation checks: Constructs two-request interleavings to detect check-then-write races, and recommends constraints, upserts, row locks, or serializable isolation with retry. - Side-effect and lifecycle auditing: Flags emails, webhooks, queue publishes, and cache writes that occur before commit, plus connections held across slow external calls and missing retry handling for serialization failures. - Use Case: Before merging a pull request that adds a payment flow using SQLx and PostgreSQL, run this review to confirm the debit and credit happen atomically, the idempotency row is written in the same transaction, and the webhook is sent only after commit. ## Quick Start Ask the agent to review your current working changes for SQL transaction consistency and report findings with file locations without editing code.

Frequently Asked Questions about sql-transaction-consistency-review

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I review Rust code for SQL transaction consistency?

Map every read that influences a write, name the domain invariant, then verify all queries in the unit of work use the transaction handle rather than a pool. Check commit and rollback paths, side-effect ordering, and whether concurrent requests can invalidate check-then-write logic.

How do I fix SELECT-then-INSERT race conditions in PostgreSQL?

Replace the check-then-insert pattern with a unique or exclusion constraint, INSERT ... ON CONFLICT with RETURNING, or a row lock such as SELECT ... FOR UPDATE. A code-level mutex is insufficient when multiple processes write to the same database.

Does SQLx rollback a transaction automatically on drop?

Yes, SQLx rolls back a transaction on drop if it is still in progress, but relying on drop should be intentional. Success paths should call commit().await explicitly, and code must not emit side effects before confirming commit succeeded.

Why is passing a pool instead of a transaction handle a bug?

Passing &Pool to a repository during an active transaction checks out a separate connection, so those queries run outside the transaction and are not rolled back on failure. Repository functions should accept the active transaction or an executor handle threaded through the unit of work.

When should database transactions be retried after serialization failures?

Retry the whole transaction body when using Serializable isolation or when deadlocks are possible, detecting PostgreSQL SQLSTATE 40001 and 40P01. Use bounded attempts with backoff, and keep non-idempotent side effects outside the retried transaction.