Retry pass

I just set up and fully understand the span, and I came to this situation:

  • I successfully set up a new project to work with span.
  • I successfully migrated the test database from version 0 to 1.0.3.
  • Failed to migrate to version 1.0.4. (I tried to add a column that was already there, no problem so far, my bad.)

However, as soon as I made the necessary changes to the corresponding script to work, flyway continued to display this message:

Current schema version: 1.0.4 com.googlecode.flyway.core.migration.MigrationException: Migration to version 1.0.4 failed! Please restore backups and roll back database and code! 

Since I did not want to restore the full dump and apply each migration again, just to make the alter script table work, what I finally did was some changes to the schema_version table:

  • 1 I deleted the entry for version 1.0.4
  • 2nd I set the current_version field to 1 for version 1.0.3
  • And then do the span: migrate again.

After that, the migration was finally applied and a success message was shown, however, I am not quite sure if this applies correctly to such situations. I am not sure if I have the right to modify the "schema_version" table myself, as I think this should only be changed by span.

So, explaining what happened to me, my question is:

Is there a way to "repeat" to apply failed migration in the span without changing the schema_version table itself?

Any command I don't know to complete this task?

+7
source share
2 answers

The answer to this is the FAQ: http://flywaydb.org/documentation/faq.html#repair

The upcoming Flyway 2.0 will include a recovery command. This code has already been verified by SCM.

Note. This applies only to the Flyway metadata table. You are still responsible for cleaning up any other consequences of the failed migration.

Update: Flyway 2.0 is now released. You can take it at http://flywaydb.org

+3
source

I don’t know if this is a good idea or not, but you can try to repair () if migration () failed:

 final Flyway flyway = new Flyway(); flyway.setBaselineOnMigrate(true); flyway.setValidateOnMigrate(false); flyway.setDataSource(dataSource()); try { flyway.migrate(); } catch (final Exception e) { logger.error("Flyway migration failed, doing a repair and retrying ..."); flyway.repair(); flyway.migrate(); } 
+3
source

All Articles