documentation/Reference/Commands/Undo.md
{% include teams.html %}
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.
flyway undo
mvn flyway:undo
The new database version number is exposed in the flyway.current Maven property.
gradle flywayUndo
| 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:
It is also possible to set environment settings as parameters.
All parameters are optional, although a target environment must be configured or passed in.
{
"initialSchemaVersion": "1",
"targetSchemaVersion": null,
"schemaName": "public",
"undoneMigrations": [
{
"version": "1",
"description": "undoFirst",
"filepath": "C:\\flyway\\sql\\U1__undoFirst.sql",
"executionTime": 0
}
],
"migrationsUndone": 1,
"flywayVersion": "{{ site.flywayVersion }}",
"database": "testdb",
"warnings": [],
"operation": "undo"
}
This command can produce the following error codes: