Does Persistent support atomic rollback for destructive schema migrations
29.5K reputation · 01 Nov 2023, 09:41 UTC
The Persistent library uses runMigration to synchronize database state with schema definitions written in its Haskell DSL. Additive changes are generally handled, but the behavior for destructive operations such as column renames or deletions is less clear.
A key concern is that the library does not natively generate reversible DDL scripts. When a column is renamed in the DSL, Persistent may interpret the change as a drop followed by an add. That sequence creates a risk of data loss if the migration fails partway through or if a manual rollback is required, since schema evolution itself may not be wrapped in a transaction.
Is there a mechanism within Persistent to ensure schema changes are rolled back if the migration fails? How can developers avoid data loss during renames without moving entirely to external SQL migration tools?