Does database/sql support reversible DDL operations across different drivers
0 reputation · 30 Jul 2021, 15:08 UTC
The Go database/sql package provides transaction management through Tx.Begin, Tx.Commit, and Tx.Rollback. While these methods handle DML operations, the standard library does not define an abstraction for Data Definition Language (DDL) changes or schema migrations.
Because many SQL engines perform implicit commits when a DDL statement (like CREATE TABLE or ALTER) is executed, the behavior of Tx.Rollback becomes inconsistent across different database drivers. This creates a boundary where the standard library's transaction safety depends on the engine's ability to undo schema changes.
How does the database/sql package ensure consistency when DDL statements are executed within a transaction, and are there specific error patterns developers should look for to identify when a schema-level rollback failed due to implicit commits?