Video in progress

What happens if you edit a Flyway migration file that has already been applied on prod?

Flyway stores a checksum of every applied file. If the file changes, the application won't start on the next launch because of a validate error. The right way is to leave the old file alone and add the fix as a new versioned migration.

📖 Answer

This is how it usually goes: V7__add_index.sql had a wrong column name, the developer fixed the file, recreated the local database, and everything works. Then at deploy:

Validate failed: Migrations have failed validation
Migration checksum mismatch for migration version 7
-> Applied to database : 1734120938
-> Resolved locally    : -228734511

That's because on prod V7 has already run in its old form. Flyway stops, saying "history was changed", and that's correct, since otherwise different environments would end up with different schemas.

The right way:

-- V8__fix_orders_index.sql
DROP INDEX IF EXISTS idx_orders_wrong;
CREATE INDEX idx_orders_user_id ON orders(user_id);

The flyway repair command updates the checksum, but you use it only when the change is truly harmless (for example, a comment was added). Using it as "we made a mistake, let's just repair it" hides the problem.

Changing a migration that hasn't been deployed anywhere and exists only in your branch is perfectly normal.