I'm experiencing the following issue:
org.flywaydb.core.api.FlywayException: Validate failed: Detected applied migration not resolved locally: 1.44
That happened when I understood that the data that I added in 1.44 is invalid and I don't want to deal with it on old environments, but on new environments I don't want this data. I want the data that I will insert within new migration(e.g. 1.48).
How can I delete it so that I accomplish what I need and not to get an error? What's the correct way?
Another way is to install the Flyway command-line tool and run flyway repair. The effect is the same: flyway repair will remove failed migrations from the flyway_schema_history table and realign checksums of already applied migrations. 6. Flyway Callbacks
For this purpose, we can use the afterMigrateError Flyway callback. We first create the SQL callback file db/callback/afterMigrateError__repair.sql: This will automatically remove any failed entry from the Flyway state history, whenever a migration error occurs.
It doesn't matter if during the migration process some intermediary state isn't exactly what you want, as long as the final one (1.48 in your case) is correct. Now if you really need to delete this migration, ask yourself whether replacing it with an empty file could also do the job.
How Flyway Works To keep track of which migrations we've already applied and when, it adds a special bookkeeping table to our schema. This metadata table also tracks migration checksums, and whether or not the migrations were successful. The framework performs the following steps to accommodate evolving database schemas:
This questions is related to Best pratice: How to modify flyway migration script after it has been used
The basic answer is: don't delete once it's been applied
It doesn't matter if during the migration process some intermediary state isn't exactly what you want, as long as the final one (1.48 in your case) is correct.
Now if you really need to delete this migration, ask yourself whether replacing it with an empty file could also do the job. If yes you could then follow the advice I gave here: https://stackoverflow.com/a/35491545/350428
Now if that's still not enough and you really really need to delete this migration, delete the file and patch up the flyway_schema_history
table by hand to make it consistent again. This is risk-prone and should be an absolute last resort solution.
you can UNDO your migration: UNDO flyway migration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With