Search in sources :

Example 26 with MigrationInfo

use of org.flywaydb.core.api.MigrationInfo 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)

Example 27 with MigrationInfo

use of org.flywaydb.core.api.MigrationInfo in project flyway by flyway.

the class MigrateMojo method doExecute.

@Override
protected void doExecute(Flyway flyway) {
    flyway.migrate();
    MigrationInfo current = flyway.info().current();
    if (current != null && current.getVersion() != null) {
        mavenProject.getProperties().setProperty("flyway.current", current.getVersion().toString());
    }
}
Also used : MigrationInfo(org.flywaydb.core.api.MigrationInfo)

Example 28 with MigrationInfo

use of org.flywaydb.core.api.MigrationInfo in project flyway by flyway.

the class InfoMojo method doExecute.

@Override
protected void doExecute(Flyway flyway) {
    MigrationInfoService info = flyway.info();
    MigrationInfo current = info.current();
    MigrationVersion currentSchemaVersion = current == null ? MigrationVersion.EMPTY : current.getVersion();
    log.info("Schema version: " + currentSchemaVersion);
    log.info("");
    log.info(MigrationInfoDumper.dumpToAsciiTable(info.all()));
}
Also used : MigrationInfo(org.flywaydb.core.api.MigrationInfo) MigrationVersion(org.flywaydb.core.api.MigrationVersion) MigrationInfoService(org.flywaydb.core.api.MigrationInfoService)

Example 29 with MigrationInfo

use of org.flywaydb.core.api.MigrationInfo in project flyway by flyway.

the class MigrationInfoDumper method dumpToAsciiTable.

/**
 * Dumps the info about all migrations into an ascii table.
 *
 * @param migrationInfos The list of migrationInfos to dump.
 * @return The ascii table, as one big multi-line string.
 */
public static String dumpToAsciiTable(MigrationInfo[] migrationInfos) {
    List<String> columns = Arrays.asList("Category", "Version", "Description", "Type", "Installed On", "State");
    List<List<String>> rows = new ArrayList<>();
    for (MigrationInfo migrationInfo : migrationInfos) {
        List<String> row = Arrays.asList(getCategory(migrationInfo), getVersionStr(migrationInfo), migrationInfo.getDescription(), migrationInfo.getType().name(), DateUtils.formatDateAsIsoString(migrationInfo.getInstalledOn()), migrationInfo.getState().getDisplayName());
        rows.add(row);
    }
    return new AsciiTable(columns, rows, true, "", "No migrations found").render();
}
Also used : MigrationInfo(org.flywaydb.core.api.MigrationInfo) AsciiTable(org.flywaydb.core.internal.util.AsciiTable)

Aggregations

MigrationInfo (org.flywaydb.core.api.MigrationInfo)29 Test (org.junit.Test)14 MigrationVersion (org.flywaydb.core.api.MigrationVersion)10 Flyway (org.flywaydb.core.Flyway)5 DriverDataSource (org.flywaydb.core.internal.util.jdbc.DriverDataSource)5 SQLException (java.sql.SQLException)4 HashMap (java.util.HashMap)4 MigrationInfoService (org.flywaydb.core.api.MigrationInfoService)4 FlywaySqlScriptException (org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException)3 MigrationInfoImpl (org.flywaydb.core.internal.info.MigrationInfoImpl)3 ArrayList (java.util.ArrayList)2 ResolvedMigration (org.flywaydb.core.api.resolver.ResolvedMigration)2 AppliedMigration (org.flywaydb.core.internal.schemahistory.AppliedMigration)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 PrintWriter (java.io.PrintWriter)1 Connection (java.sql.Connection)1 Map (java.util.Map)1 PostConstruct (javax.annotation.PostConstruct)1 DataSource (javax.sql.DataSource)1 MigrationState (org.flywaydb.core.api.MigrationState)1