Search code examples
flyway

Delete migration in flyway


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).

  • If I change old migration it will fail on old envs due to checksum;
  • If I leave it, on new envs I will have invalid data from 1.44;

How can I delete it so that I accomplish what I need and not to get an error? What's the correct way?


Solution

  • 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.