use of org.flywaydb.core.api.MigrationState in project flyway by flyway.
the class MigrationInfoImpl method compareTo.
@SuppressWarnings("NullableProblems")
public int compareTo(MigrationInfo o) {
if ((getInstalledRank() != null) && (o.getInstalledRank() != null)) {
return getInstalledRank() - o.getInstalledRank();
}
MigrationState state = getState();
MigrationState oState = o.getState();
if (((getInstalledRank() != null) || (o.getInstalledRank() != null)) && (!(state == MigrationState.BELOW_BASELINE || oState == MigrationState.BELOW_BASELINE || state == MigrationState.IGNORED || oState == MigrationState.IGNORED))) {
if (getInstalledRank() != null) {
return Integer.MIN_VALUE;
}
if (o.getInstalledRank() != null) {
return Integer.MAX_VALUE;
}
}
if (getVersion() != null && o.getVersion() != null) {
return getVersion().compareTo(o.getVersion());
}
// Versioned pending migrations go before repeatable ones
if (getVersion() != null) {
return Integer.MIN_VALUE;
}
if (o.getVersion() != null) {
return Integer.MAX_VALUE;
}
return getDescription().compareTo(o.getDescription());
}
use of org.flywaydb.core.api.MigrationState in project flyway by flyway.
the class DbRepair method deleteMissingMigrations.
private boolean deleteMissingMigrations() {
boolean removed = false;
for (MigrationInfo migrationInfo : migrationInfoService.all()) {
MigrationInfoImpl migrationInfoImpl = (MigrationInfoImpl) migrationInfo;
if (migrationInfo.getType().isSynthetic()) {
continue;
}
AppliedMigration applied = migrationInfoImpl.getAppliedMigration();
MigrationState state = migrationInfoImpl.getState();
boolean isMigrationMissing = state == MigrationState.MISSING_SUCCESS || state == MigrationState.MISSING_FAILED || state == MigrationState.FUTURE_SUCCESS || state == MigrationState.FUTURE_FAILED;
boolean isMigrationIgnored = Arrays.stream(configuration.getIgnoreMigrationPatterns()).anyMatch(p -> p.matchesMigration(migrationInfoImpl.getVersion() != null, state));
if (isMigrationMissing && !isMigrationIgnored) {
schemaHistory.delete(applied);
removed = true;
repairResult.migrationsDeleted.add(CommandResultFactory.createRepairOutput(migrationInfo));
}
}
return removed;
}
Aggregations