use of org.flywaydb.core.api.MigrationPattern in project flyway by flyway.
the class JdbcTableSchemaHistory method removeFailedMigrations.
@Override
public boolean removeFailedMigrations(RepairResult repairResult, MigrationPattern[] migrationPatternFilter) {
if (!exists()) {
LOG.info("Repair of failed migration in Schema History table " + table + " not necessary as table doesn't exist.");
return false;
}
List<AppliedMigration> appliedMigrations = filterMigrations(allAppliedMigrations(), migrationPatternFilter);
boolean failed = appliedMigrations.stream().anyMatch(am -> !am.isSuccess());
if (!failed) {
LOG.info("Repair of failed migration in Schema History table " + table + " not necessary. No failed migration detected.");
return false;
}
try {
appliedMigrations.stream().filter(am -> !am.isSuccess()).forEach(am -> repairResult.migrationsRemoved.add(CommandResultFactory.createRepairOutput(am)));
for (AppliedMigration appliedMigration : appliedMigrations) {
jdbcTemplate.execute("DELETE FROM " + table + " WHERE " + database.quote("success") + " = " + database.getBooleanFalse() + " AND " + (appliedMigration.getVersion() != null ? database.quote("version") + " = '" + appliedMigration.getVersion().getVersion() + "'" : database.quote("description") + " = '" + appliedMigration.getDescription() + "'"));
}
clearCache();
} catch (SQLException e) {
throw new FlywaySqlException("Unable to repair Schema History table " + table, e);
}
return true;
}
Aggregations