Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete migration in flyway

Tags:

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?

like image 907
dvelopp Avatar asked May 04 '18 11:05

dvelopp


People also ask

How to fix Flyway migrations that fail?

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

How do I remove a failed entry from Flyway state history?

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.

Is it possible to delete a migration after the migration process?

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 does Flyway work?

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:


2 Answers

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.

like image 149
Axel Fontaine Avatar answered Sep 22 '22 07:09

Axel Fontaine


you can UNDO your migration: UNDO flyway migration

like image 45
EmeraldTablet Avatar answered Sep 23 '22 07:09

EmeraldTablet