Caused By: Org.Flywaydb.Core.Api.Flywayexception: Validate Failed. Migration Checksum Mismatch for Migration 2

Flyway 3.0 Migration Checksum mismatch

Flyway 3.0 changed the default of validateOnMigrate to true.

This is however a good thing, as in the spirit of fail fast, errors are discovered sooner.

In your case some scripts did change since they were applied, which is what Flyway is reporting.

You have two options:

  • suppress the error by setting validateOnMigrate to false (2.3 default behavior)
  • invoke Flyway.repair() to reallign the checksums

Reference

Flyway Repair

flyway - Validate failed: Detected failed migration to version 1

First of all, you should evaluate flyway repair to tell the flyway that you have fixed the issue and then run flyway migrate.

Spring Boot 1.5 to 2 migration - Flyway migration checksum mismatch

It seems that the checksum algorithm has changed between versions.
In (some) versions of Flyway 4,

all checksums are automatically recalculated and updated with the new algorithm on first run (Flyway #253)

I'm not sure if this means that the checksum is calculated with both versions, and if it matches the old version is updated with the new version, or if it means that it's blindly overwritten with the new one.


Flyway Checksum Algorithm:

  • version 3 - crc32 over bytes:

    bytes = resource.loadAsBytes()
    ...
    crc32.update(bytes);
  • version 5 (not a verbatim copy) - crc32 over lines (ignoring CR/LF, and using UTF-8 encoding):

    BufferedReader bufferedReader = new BufferedReader(new StringReader(resource.loadAsString(configuration.getEncoding())));
    [...]
    while ((line = bufferedReader.readLine()) != null) {
    crc32.update(line.getBytes("UTF-8"));
    }

Solution

In the answer to Flyway repair with Spring Boot multiple solutions are presented.

Because manual intervention had to be avoided, I've used the FlywayMigrationStrategy and a jdbcTemplate to update at startup the checksums from fixed known values to the new fixed know values required by Flyway 5.



Related Topics



Leave a reply



Submit