Search in sources :

Example 1 with MigrationInfo

use of org.flywaydb.core.api.MigrationInfo in project spring-boot by spring-projects.

the class FlywayEndpoint method invoke.

@Override
public List<FlywayReport> invoke() {
    List<FlywayReport> reports = new ArrayList<>();
    for (Map.Entry<String, Flyway> entry : this.flyways.entrySet()) {
        List<FlywayMigration> migrations = new ArrayList<>();
        for (MigrationInfo info : entry.getValue().info().all()) {
            migrations.add(new FlywayMigration(info));
        }
        reports.add(new FlywayReport(entry.getKey(), migrations));
    }
    return reports;
}
Also used : Flyway(org.flywaydb.core.Flyway) MigrationInfo(org.flywaydb.core.api.MigrationInfo) ArrayList(java.util.ArrayList) FlywayReport(org.springframework.boot.actuate.endpoint.FlywayEndpoint.FlywayReport) Map(java.util.Map)

Example 2 with MigrationInfo

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

the class DB2zOSMigrationMediumTest method migrate.

/**
     * Override migrate. Setting schema and table space in SQL.
     *
     * @throws Exception
     */
@Override
@Test
public void migrate() throws Exception {
    flyway.setLocations(getBasedir() + "/default");
    flyway.baseline();
    flyway.migrate();
    MigrationVersion version = flyway.info().current().getVersion();
    assertEquals("1.3", version.toString());
    assertEquals(0, flyway.migrate());
    // We should have 5 rows if we have a schema creation marker as the first entry, 4 otherwise
    if (flyway.info().applied()[0].getType() == MigrationType.SCHEMA) {
        assertEquals(5, flyway.info().applied().length);
    } else {
        assertEquals(4, flyway.info().applied().length);
    }
    for (MigrationInfo migrationInfo : flyway.info().applied()) {
        if (migrationInfo.getType().toString() != "BASELINE") {
            assertChecksum(migrationInfo);
        }
    }
    assertEquals(4, jdbcTemplate.queryForInt("SELECT COUNT(*) FROM person"));
}
Also used : MigrationInfo(org.flywaydb.core.api.MigrationInfo) MigrationVersion(org.flywaydb.core.api.MigrationVersion) Test(org.junit.Test)

Example 3 with MigrationInfo

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

the class DB2zOSMigrationMediumTest method nonEmptySchemaWithInitOnMigrateHighVersion.

/**
     * Override nonEmptySchemaWithInitOnMigrateHighVersion. createTestTable change.
     *
     * @throws Exception
     */
@Override
@Test
public void nonEmptySchemaWithInitOnMigrateHighVersion() throws Exception {
    createTestTable();
    flyway.setLocations(getMigrationDir());
    flyway.setBaselineOnMigrate(true);
    flyway.setBaselineVersion(MigrationVersion.fromVersion("99"));
    flyway.migrate();
    MigrationInfo[] migrationInfos = flyway.info().all();
    assertEquals(5, migrationInfos.length);
    assertEquals(MigrationType.SQL, migrationInfos[0].getType());
    assertEquals("1", migrationInfos[0].getVersion().toString());
    assertEquals(MigrationState.BELOW_BASELINE, migrationInfos[0].getState());
    MigrationInfo migrationInfo = flyway.info().current();
    assertEquals(MigrationType.BASELINE, migrationInfo.getType());
    assertEquals("99", migrationInfo.getVersion().toString());
}
Also used : MigrationInfo(org.flywaydb.core.api.MigrationInfo) Test(org.junit.Test)

Example 4 with MigrationInfo

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

the class DB2zOSMigrationMediumTest method failedMigration.

/**
     * Override failedMigration. Setting schema and table space in SQL.
     *
     * @throws Exception
     */
@Override
@Test
public void failedMigration() throws Exception {
    String tableName = "before_the_error";
    flyway.setLocations(getBasedir() + "/failed");
    Map<String, String> placeholders = new HashMap<String, String>();
    placeholders.put("tableName", dbSupport.quote(tableName));
    flyway.setPlaceholders(placeholders);
    flyway.baseline();
    try {
        flyway.migrate();
        fail();
    } catch (FlywaySqlScriptException e) {
        System.out.println(e.getMessage());
        // root cause of exception must be defined, and it should be FlywaySqlScriptException
        assertNotNull(e.getCause());
        assertTrue(e.getCause() instanceof SQLException);
        // and make sure the failed statement was properly recorded
        assertEquals(23, e.getLineNumber());
        assertEquals("THIS IS NOT VALID SQL", e.getStatement());
    }
    MigrationInfo migration = flyway.info().current();
    assertEquals(dbSupport.supportsDdlTransactions(), !dbSupport.getSchema(dbSupport.getCurrentSchemaName()).getTable(tableName).exists());
    if (dbSupport.supportsDdlTransactions()) {
        assertTrue(migration.getType().toString() == "BASELINE");
    } else {
        MigrationVersion version = migration.getVersion();
        assertEquals("1", version.toString());
        assertEquals("Should Fail", migration.getDescription());
        assertEquals(MigrationState.FAILED, migration.getState());
        // With schema markers, we'll have 2 applied
        if (flyway.info().applied()[0].getType() == MigrationType.SCHEMA) {
            assertEquals(2, flyway.info().applied().length);
        } else {
            assertEquals(1, flyway.info().applied().length);
        }
    }
}
Also used : MigrationInfo(org.flywaydb.core.api.MigrationInfo) MigrationVersion(org.flywaydb.core.api.MigrationVersion) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) FlywaySqlScriptException(org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException) Test(org.junit.Test)

Example 5 with MigrationInfo

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

the class EnterpriseDBMigrationMediumTest method migrationsWithPlaceholders.

/**
     * Tests migrations containing placeholders.
     */
@Test
public void migrationsWithPlaceholders() throws Exception {
    int countUserObjects1 = jdbcTemplate.queryForInt("SELECT count(*) FROM user_objects");
    Map<String, String> placeholders = new HashMap<String, String>();
    placeholders.put("tableName", "test_user");
    flyway.setPlaceholders(placeholders);
    flyway.setLocations("migration/dbsupport/enterprisedb/sql/placeholders");
    flyway.migrate();
    MigrationVersion version = flyway.info().current().getVersion();
    assertEquals("1.1", version.toString());
    assertEquals("Populate table", flyway.info().current().getDescription());
    assertEquals("Mr. T triggered", jdbcTemplate.queryForString("select name from test_user"));
    flyway.clean();
    int countUserObjects2 = jdbcTemplate.queryForInt("SELECT count(*) FROM user_objects");
    assertEquals(countUserObjects1, countUserObjects2);
    MigrationInfo[] migrationInfos = flyway.info().applied();
    for (MigrationInfo migrationInfo : migrationInfos) {
        assertNotNull(migrationInfo.getScript() + " has no checksum", migrationInfo.getChecksum());
    }
}
Also used : MigrationInfo(org.flywaydb.core.api.MigrationInfo) 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