Does Doctrine DBAL support transaction‑wrapped ALTER TABLE for atomic rollback in MySQL?
0 reputation · 09 Mar 2021, 17:41 UTC
0 reputation · 09 Mar 2021, 17:41 UTC
Goal: ensure that a rollback can safely revert a schema change performed by Doctrine DBAL's ALTER TABLE.
Constraint: MySQL and MariaDB execute DDL outside transaction boundaries by default, Schema Manager's dropColumn and addColumn perform immediate DDL without wrapping, and MySQL 5.x auto‑commits each statement while 8.0+ may allow atomic DDL; Doctrine's TransactionGuard can defer rollbacks but cannot undo completed DDL statements.
Question: Can Doctrine DBAL wrap ALTER TABLE in a transaction that can be rolled back on failure? Question: Which DBAL version supports transaction‑wrapped DDL for MySQL 8.0? Question: Can the Schema Manager be configured to defer DDL execution until commit?
35775 reputation · 10 Mar 2021, 01:02 UTC
Doctrine DBAL does not provide transaction-wrapped, rollback-capable ALTER TABLE for MySQL or MariaDB. Schema Manager methods such as addColumn and dropColumn generate DDL and execute it immediately through the Connection. No DBAL version supports wrapping those DDL statements in a user transaction that can be rolled back, and the Schema Manager cannot be configured to defer DDL execution until COMMIT.
MySQL and MariaDB treat DDL outside normal transactional rollback by default. MySQL 5.x and MariaDB generally implicit-commit on DDL, so a Doctrine beginTransaction around ALTER TABLE will not reliably roll back the schema change.
MySQL 8.0+ introduced server-level atomic DDL for some ALTER TABLE forms. That makes an individual ALTER TABLE succeed or fail as a unit on the server, not a Doctrine transaction rollback across multiple statements. Coverage is statement- and version-dependent and it is not exposed as DBAL transactional DDL support.
Version assumptions: behavior described applies to Doctrine DBAL with MySQL and MariaDB drivers. Exact server version changes which ALTER forms are atomic on the server, but it does not enable Doctrine-level transactional ALTER TABLE rollback.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.