From 22b759f0d8eb0f7dab69b4d53d7b21b1e6ac6448 Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 22 Feb 2022 16:08:56 +0100 Subject: [PATCH] adapt flyway migration repair checksum mismatch if detected --- .../webservice/SEBServerMigrationStrategy.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/SEBServerMigrationStrategy.java b/src/main/java/ch/ethz/seb/sebserver/webservice/SEBServerMigrationStrategy.java index 6e9fd653..e90d7fec 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/SEBServerMigrationStrategy.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/SEBServerMigrationStrategy.java @@ -11,6 +11,7 @@ package ch.ethz.seb.sebserver.webservice; import org.flywaydb.core.Flyway; import org.flywaydb.core.api.MigrationInfo; import org.flywaydb.core.api.MigrationInfoService; +import org.flywaydb.core.api.output.ValidateResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -116,6 +117,20 @@ public class SEBServerMigrationStrategy implements FlywayMigrationStrategy { this.flyway.clean(); } + + // repair checksum mismatch if needed + final ValidateResult validateWithResult = this.flyway.validateWithResult(); + if (!validateWithResult.validationSuccessful + && validateWithResult.getAllErrorMessages().contains("checksum mismatch")) { + + SEBServerInit.INIT_LOGGER.info("----> Migration validation checksum mismatch error detected: "); + SEBServerInit.INIT_LOGGER.info("----> {}", validateWithResult.getAllErrorMessages()); + SEBServerInit.INIT_LOGGER.info("----> Try to run repair task..."); + + this.flyway.repair(); + + } + this.flyway.migrate(); final MigrationInfoService info = this.flyway.info();