Search code examples
flyway

Flyway - how to fix issue when schema has a version newer thatn latest available migration


I'm new to flyway, and I'm receiving this warning, when calling flyway migrate :

WARNING: Schema 'schema' has a version (34) that is newer than the latest available migration (0) !

In a directory with migrations, I have migrations till 36, but none of this next migrations are applied to database. When I call flyway migrate all of migration's state till 34,are set to FUTURE. Only missing one is 29. What can be the reason and solution (except clearing database) ?

I think that has happened because I was fixing 29 and I deleted this migration from flyway database table and revert also it effect on db. Is it possible to fix this, and what does it mean ?


Solution

  • Disclaimer:

    This is dangerous, but an option.

    Perform the following steps.

    1. Back up your schema. At a minimum back up your schema_version table
    2. delete all records in the schema_version where the version is higher than 29 (or recent migrations compared to version 29). Refer to your migration folder.
    3. Run flyway migrate, this will try and recreate the migration version 29, but it may fail since the content of the 29 version was already applied to the database. If it fails, update this migration record to set the column success=1.
    4. copy data from the backup of schema_version to insert all records of migrations above version 29.

    hope this helps.