====== Rolling Back ChangeSets ====== LiquiBase allows you to undo changes you have made to your database, either automatically or via custom rollback SQL. Rollback support is available in [[command line]], [[Ant]], [[Maven]], and [[Grails]]. ===== How Rollback SQL is controlled ===== Many refactorings such as "create table", "rename column", and "add column" can automatically create rollback statements. If your change log contains only statements that fit into this category, your rollback commands will be generated automatically. Other refactorings such as "drop table" and "insert data" have no corresponding rollback commands that can be automatically generated. In these cases, and cases where you want to override the default generated rollback commands, you can specify the rollback commands via the tag within the changeSet tag. ===== "Roll Back To" Modes ===== You can specify what changes to rollback in three ways: ==== Date/Time ==== Specifying a date/time to rollback to will roll back all change-sets that were executed against the target database after the given date/time. ==== Tag ==== Specifying a tag to rollback to will roll back all change-sets that were executed against the target database after the given tag was applied. See the [[command line]] documentation for how to tag your database. ==== Number of Change Sets ==== You can specify the number of change-sets to rollback. ===== Roll back Execution Modes ===== LiquiBase has three modes for managing rollbacks: ==== Execute Rollback Directly ==== The rollback commands can be executed directly against the target database. If any changes cannot be rolled back, you will be notified and none of the changes will roll back. ==== Generating a Rollback Script ==== Rather than actually updating the database, the SQL required to roll back the database can be generated. This is useful if you want to preview what rollback commands will be executed before they are actually run. ==== Generating a "Future Rollback" Script ==== This mode is designed to allow you to generate a rollback script at the same time you generate your migration script. It allows you to take an updated application and generate both the SQL to update the database to the new version as well as the SQL to bring that new version back to the current version if needed. This functionality is very useful when a DBA wants to control SQL going into the database, as well as for applications that require rollback documentation for internal and/or [[http://en.wikipedia.org/wiki/Sarbanes-Oxley_Act|SOX-compliant]] processes. You do not need to specify a rollback date, tag, or count in this mode.