Migrationsmedium5-8 years

A migration `V5__add_index_on_orders.sql` has already run in production. A follow-up PR notices the index is on the wrong column and fixes the column name inside `V5`. The next deploy fails before the application starts. What exactly did Flyway check, and what should the PR have done instead? When is `flyway repair` the right tool?

Flyway records every applied migration in flyway_schema_history, including a checksum of the file's contents. On every run it recomputes the checksum of each already-applied file on disk and compares it with the stored one, for every version in the history, not just the newest. Editing V5 changed its checksum, so validation failed with a checksum mismatch and nothing ran: in a Spring Boot app, the Flyway initialiser fails and the context never starts. That is deliberate: the database was built by the old contents of that file, and Flyway refuses to guess whether the difference matters. The PR should have added V6__fix_orders_index_column.sql that drops the wrong index and creates the right one. repair rewrites stored checksums to match the files, which is only right when the edited migration has run nowhere but your own laptop.

The lesson behind it →