Home > Net >  How to apply migrations to history table but no database?
How to apply migrations to history table but no database?

Time:11-25

I deleted some non repeatable migrations flyway_schema_history from a certain point onwards. Now I want to rerun the migrations so they get inserted into the history table but of course they fail because they have already been applied (columns renamed for example). Is there a way to apply the migrations to the history table without actually running them in the database? Failing that, is there a different way to fix this that you could suggest? repair option didn't work, then again not sure if I used it right.

CodePudding user response:

I just ran a series of tests to validate this, FLYWAY REPAIR is the way to deal with this. You should have seen an error when running MIGRATE along the lines of:

ERROR: Validate failed: Migrations have failed validation Detected applied migration not resolved locally: 4.1. If you removed this migration intentionally, run repair to mark the migration as deleted.

Then, if you run REPAIR, you should see something like:

Repair of failed migration in Schema History table "public"."flyway_schema_history" not necessary. No failed migration detected. Repairing Schema History table for version "4.1" (Marking as DELETED) ... Successfully repaired schema history table "public"."flyway_schema_history" (execution time 00:00.080s).

That worked on multiple deletes of existing migrations.

CodePudding user response:

One of my migrations was failing because it conflcited with the current state of the database since the migration had already been applied (renaming a column) so simply removing the migration records wasn't enough. In the end, I manually inserted the records and then ran flyway:repair which fixed the checksums. I hope someone offers a cleaner solution but this worked for me.

  • Related