1

I was running a db repair command on my db, and surpassingly found out later that for each old migration version a new DELETE migration was created. It was only effecting the flyway_schema_history table, the rest of the tables stayed the same, and nothing was deleted/ dropped.

But, now when I am trying to run migrations scripts I get failures when running the flyway, since it tries to run the first migration script again. I do not want to delete this migrations.

Can someone explain to me why did it happen, and much more important, do I have a way to revert it and delete the DELETE rows?

Tom Carmi
  • 385
  • 1
  • 5
  • 18

1 Answers1

1

As of Flyway 7, running repair marks any migrations that are Missing as DELETED in the flyway_schema_history table, which is a way of telling Flyway that the migrations have been removed

If the migrations aren't Missing, what has likely happened is you haven't configured flyway.locations when running repair

As for fixing it, there are two options that are the most ideal as of today:

  • If you have Flyway Teams or Enterprise edition, or are able to get a trial, you can use flyway.skipExecutingMigrations when running migrate to update the flyway_schema_history table, telling Flyway that the migrations are applied again, without actually executing them
  • Otherwise, you could go directly into the flyway_schema_history table and delete the DELETE rows
DoodleBobBuffPants
  • 169
  • 1
  • 1
  • 9
  • Since it was urgent, and I saw no harm in it, I already done 2, though I found it a bad practice. – Tom Carmi May 05 '23 at 07:00
  • In order to avoide doing it again in the next time, can you please explain a bit or give a link to an explanation about what is the locations and how is it specified? – Tom Carmi May 05 '23 at 07:02
  • 1
    `flyway.locations` is documented [here](https://documentation.red-gate.com/fd/locations-184127514.html) and includes what it's for and how to specify it. To summarise, it's the locations where your migrations are, and `repair` needs to know, otherwise it treats migrations that have already been applied as `Missing` if it can't find them in any of the configured locations. I've updated the answer with a link to the docs for `locations` too – DoodleBobBuffPants May 05 '23 at 07:41