Magento 2 Declarative Schema Rollback Safety for Destructive Changes
0 reputation · 21 Aug 2022, 19:10 UTC
Magento 2 applies declarative schema changes from etc/db_schema.xml during schema upgrade and records the applied module version in setup_module. The platform does not provide a native down migration or rollback command for schema changes.
Once a destructive change such as dropping, renaming, or narrowing a column is applied, reversing it requires manual SQL or a new forward patch. A module owner wants to declare that a schema change is reversible only when a matching rollback patch exists, but Magento does not validate this pairing before marking the version as applied.
Assumes Magento 2.4.x declarative schema behavior. Can a custom extension intercept declarative schema changes and apply a compensating rollback without corrupting module version tracking? Should Magento require a rollback patch for destructive db_schema.xml changes before the upgrade completes? Which MySQL DDL behaviors affect whether a manual rollback preserves existing data?