Product articles Flyway Undo migrations

Undoing Actions on Groups of Database Tables

During development you'll occasionally need an undo script that drops a group of tables, or you might need to truncate a group of tables and then insert fresh data in order to run some tests. Unless you perform the required actions in the correct dependency order, you'll be tripped up by foreign key constraint violations. This article provides a SQL function that returns the list of tables in the correct dependency order. Read more

Rollbacks, Undos and Undonts

Rollback scripts are designed to allow us to recover safely from a failed deployment that leaves the database in an indeterminate state. They must check exactly what needs to be reverted before doing so. If you work with an RDBMS that cannot support transaction DDL rollback they are vital. This article proposes a strategy where you create and test a rollback file, at the same time as the forward migration, and reuse it as a Flyway undo script. Read more

Automating Flyway Undos

How to auto-generate first-cut undo scripts for every Flyway migration. For every new version of a database created by a Flyway versioned migration, we compare it to a 'source' directory containing object-level build scripts for the previous version. The SQL Compare engine does the rest, producing the associated undo script that will revert the database to the previous version, if required. Read more