FlywayDB migration removal

Viewed 1317

I've always thought that if a migration applied with flywaydb is removed (both: entry from DB schema_version table and migration sql file) then application (written in spring framework with flyway in classpath) will crash at startup because of invalid checksums.

Actually (I tested it today) when both migration file and DB entry is removed application starts just fine, which I found a bit confusing.

How does flyway calculate the checksums? Is it based only on content of migration file being applied or previous migrations are also taken into account?

Also, is it safe to remove already applied migrations if both file and table entry is removed?

1 Answers

Many questions here. For your main question, this behavior is controlled by the ignoreMissingMigrations flag. See https://flywaydb.org/documentation/commandline/migrate

Checksums are calculated based on the content of the migrations files (ignoring line-endings due to Git CRLF transformations).

If both a migration file and its entry in the metadata table are removed Flyway doesn't know anything about it anymore. This however doesn't mean it is safe, as it may impact your ability to recreate your database schema later.

Related