Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flyway on production database - Migration Checksum mismatch

Every time I change something from DB structure I create a new migration file using timestamp to execute in order, with a clean database the migrate command (with maven plugin or command-line tool) it works perfectly, but in a production database, with the same DB structure but with data added I got this error:

Failed to execute goal org.flywaydb:flyway-maven-plugin:3.2.1:migrate (main) on project eee-ejb: org.flywaydb.core.api.FlywayException: Validate failed. Migration Checksum mismatch for migration 1430224929 [ERROR] -> Applied to database : -1639634536 [ERROR] -> Resolved locally : -1412099238

How can I use flyway in a production database where data is constantly added?

like image 669
Claudinei Avatar asked Apr 28 '15 12:04

Claudinei


People also ask

How do you resolve checksum error in Flyway?

sql by adding a comment at the beginning of the file. This happens because we altered an already applied migration and Flyway detects an inconsistency. In order to realign the checksums, we can use the same flyway:repair command. However, this time no migration will be executed.

What checksum does Flyway use?

Flyway uses the CRC32 algorithm for checksum generation.

How does Flyway checksum work?

Flyway will once again scan the filesystem or the classpath of the application for migrations. The migrations are checked against the schema history table. If their version number is lower or equal to the one of the version marked as current, they are ignored.


2 Answers

This has nothing to do with data being added. It is the migration script itself that is being modified. One place to check is Git CRLF normalization issues.

Update: Flyway 4.0 now automatically takes care of this.

like image 104
Axel Fontaine Avatar answered Nov 05 '22 13:11

Axel Fontaine


The script that was originally ran is now changed. If you are sure that the change is what you'd wanted, run

./flyway repair

This will accept the change, update the metadata table and you will not get the error.

like image 23
kenchew Avatar answered Nov 05 '22 13:11

kenchew