Search in sources :

Example 11 with MigrationInfo

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

the class FlywayInfoTask method run.

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

Example 12 with MigrationInfo

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

the class UndoMojo method doExecute.

@Override
protected void doExecute(Flyway flyway) {
    flyway.undo();
    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 13 with MigrationInfo

use of org.flywaydb.core.api.MigrationInfo in project keywhiz by square.

the class PreviewMigrateCommand method run.

@Override
protected void run(Bootstrap<KeywhizConfig> bootstrap, Namespace namespace, KeywhizConfig config) throws Exception {
    DataSource dataSource = config.getDataSourceFactory().build(new MetricRegistry(), "migration-preview-datasource");
    Flyway flyway = Flyway.configure().dataSource(dataSource).locations(config.getMigrationsDir()).table(config.getFlywaySchemaTable()).load();
    MigrationInfoService info = flyway.info();
    MigrationInfo current = info.current();
    if (current == null) {
        logger.info("No migrations have been run yet.");
    } else {
        logger.info("Currently applied migration:");
        logger.info("* {} - {}", current.getVersion(), current.getDescription());
    }
    if (info.pending().length > 0) {
        logger.info("Pending migrations:");
        for (MigrationInfo migration : info.pending()) {
            logger.info("* {} - {}", migration.getVersion(), migration.getDescription());
        }
    } else {
        logger.info("No pending migrations");
    }
}
Also used : Flyway(org.flywaydb.core.Flyway) MigrationInfo(org.flywaydb.core.api.MigrationInfo) MigrationInfoService(org.flywaydb.core.api.MigrationInfoService) MetricRegistry(com.codahale.metrics.MetricRegistry) DataSource(javax.sql.DataSource)

Example 14 with MigrationInfo

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

the class FlywayMediumTest method baselineAgainWithSameVersion.

@Test
public void baselineAgainWithSameVersion() throws Exception {
    DriverDataSource dataSource = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_db_init_same;DB_CLOSE_DELAY=-1", "sa", "", null);
    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    flyway.setLocations("migration/sql");
    flyway.setBaselineVersionAsString("0.5");
    flyway.baseline();
    flyway.baseline();
    assertEquals(1, flyway.info().applied().length);
    MigrationInfo current = flyway.info().current();
    assertEquals("0.5", current.getVersion().toString());
    assertEquals(MigrationType.BASELINE, current.getType());
    assertEquals(MigrationState.BASELINE, current.getState());
}
Also used : MigrationInfo(org.flywaydb.core.api.MigrationInfo) DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) Test(org.junit.Test)

Example 15 with MigrationInfo

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

the class FlywayMediumTest method outOfOrderInOrder.

@Test
public void outOfOrderInOrder() {
    DriverDataSource dataSource = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_out_of_order_in_order;DB_CLOSE_DELAY=-1", "sa", "", null);
    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    flyway.setLocations("migration/sql");
    flyway.migrate();
    MigrationVersion highest = null;
    for (MigrationInfo migrationInfo : flyway.info().applied()) {
        assertEquals(MigrationState.SUCCESS, migrationInfo.getState());
        if (highest == null) {
            highest = migrationInfo.getVersion();
        } else {
            assertTrue(migrationInfo.getVersion().compareTo(highest) > 0);
            highest = migrationInfo.getVersion();
        }
    }
    assertEquals(MigrationVersion.fromVersion("2.0"), highest);
}
Also used : MigrationInfo(org.flywaydb.core.api.MigrationInfo) DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) MigrationVersion(org.flywaydb.core.api.MigrationVersion) Test(org.junit.Test)

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