racket/sql: transaction rollback fails with 'a command in the transaction has already caused a commit' after ALTER TABLE
26K reputation · 24 Feb 2026, 16:35 UTC
The racket/sql transaction form begins a DB transaction, runs a thunk, and rolls back on any exception, but it does not intercept DDL statements that trigger an implicit commit in the underlying database.
When a statement such as ALTER TABLE is executed inside the thunk, many engines (e.g., PostgreSQL, SQLite, MySQL) commit the transaction before the rollback point, so a later rollback attempt fails with an error like “a command in the transaction has already caused a commit”.
Given this behavior, what options exist for users who want to guarantee that schema changes are either fully applied or fully reverted, and how can racket/sql be used safely across different DB engines and versions?