Search in sources :

Example 1 with MigrationState

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());
}
Also used : MigrationState(org.flywaydb.core.api.MigrationState)

Example 2 with MigrationState

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;
}
Also used : MigrationInfo(org.flywaydb.core.api.MigrationInfo) MigrationInfoImpl(org.flywaydb.core.internal.info.MigrationInfoImpl) MigrationState(org.flywaydb.core.api.MigrationState) AppliedMigration(org.flywaydb.core.internal.schemahistory.AppliedMigration)

Aggregations

MigrationState (org.flywaydb.core.api.MigrationState)2 MigrationInfo (org.flywaydb.core.api.MigrationInfo)1 MigrationInfoImpl (org.flywaydb.core.internal.info.MigrationInfoImpl)1 AppliedMigration (org.flywaydb.core.internal.schemahistory.AppliedMigration)1