Undo
Published 15 January 2025
Description
Undoes the most recently applied versioned migration.
If target is specified, Flyway will attempt to undo versioned migrations in the reverse of their applied order, until
it hits
one with a version below the target, or one without a corresponding undo migration. If group is active, Flyway will
attempt to undo all these migrations within a
single transaction.
If there is no versioned migration to undo, calling undo has no effect.
There is no undo functionality for repeatable migrations. In that case the repeatable migration should be modified to include the older state that one desires and then reapplied using migrate.
Can optionally take a snapshot of the target database on deployment success and store it in the target database or elsewhere. This ensures that the snapshot history table is kept up to date if storing snapshots on migrate, and using that for drift analysis.
See Migrations for more information.
Usage examples
Undo via command line
flyway undo
Undo via Maven
mvn flyway:undo
The new database version number is exposed in the flyway.current Maven property.
Undo via Gradle
gradle flywayUndo
Parameters
Optional parameters specific to undo
| Parameter | Namespace | Description |
|---|---|---|
saveSnapshot |
undo | Whether to generate a snapshot of the schema state after undo. |
Universal commandline parameters are listed here.
All relevant configuration settings are listed here. The settings from these
sections can be set as parameters on the undo command:
- General settings
- Migration location and naming settings
- Migration reading settings
- Migration execution settings
- Flyway schema history settings
- Placeholders
- Settings in database-specific namespaces
- Settings in secrets management namespaces
It is also possible to set environment settings as parameters.
All parameters are optional, although a target environment must be configured or passed in.
JSON output format
{
"initialSchemaVersion": "1",
"targetSchemaVersion": null,
"schemaName": "public",
"undoneMigrations": [
{
"version": "1",
"description": "undoFirst",
"filepath": "C:\\flyway\\sql\\U1__undoFirst.sql",
"executionTime": 0
}
],
"migrationsUndone": 1,
"flywayVersion": "11.17.0",
"database": "testdb",
"warnings": [],
"operation": "undo"
}
Error codes
This command can produce the following error codes: