Does dbRollback() undo an ALTER TABLE executed inside a DBI transaction?
0 reputation · 21 Mar 2022, 22:25 UTC
I am writing an R package that applies schema changes through DBI and want failures to leave the database untouched. My plan was to wrap everything in dbBegin() / dbCommit() and call dbRollback() on error, but I am unsure whether that actually protects statements like ALTER TABLE.
My understanding is that many backends issue an implicit commit around DDL, so dbRollback() would only revert DML executed after that point, while some systems (SQLite in its default mode, PostgreSQL) support transactional DDL. That would make rollback safety backend-dependent rather than something DBI guarantees.
Assume current CRAN DBI with RSQLite, RMariaDB, and RPostgres as the target backends, and that portability across all three matters.
Does DBI itself specify any behavior for rolling back DDL, or is it entirely delegated to the driver and DBMS? Is there a documented, portable pattern for making schema migrations failure-safe from R, or is per-backend branching the accepted approach? Which backends among these three actually roll back ALTER TABLE today?