Search in sources :

Example 26 with MigrationVersion

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

the class MigrationTestCase method failedMigration.

@Test
public void failedMigration() throws Exception {
    String tableName = "before_the_error";
    flyway.setLocations(getMigrationDir() + "/failed");
    Map<String, String> placeholders = new HashMap<String, String>();
    placeholders.put("tableName", dbSupport.quote(tableName));
    flyway.setPlaceholders(placeholders);
    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(21, 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()) {
        assertNull(migration);
    } 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 27 with MigrationVersion

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

the class MigrationInfoHelperSmallTest method extractSchemaVersionDefaults.

@Test
public void extractSchemaVersionDefaults() {
    Pair<MigrationVersion, String> info = MigrationInfoHelper.extractVersionAndDescription("V9_4__EmailAxel.sql", "V", "__", ".sql");
    MigrationVersion version = info.getLeft();
    String description = info.getRight();
    assertEquals("9.4", version.toString());
    assertEquals("EmailAxel", description);
}
Also used : MigrationVersion(org.flywaydb.core.api.MigrationVersion) Test(org.junit.Test)

Example 28 with MigrationVersion

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

the class MigrationInfoHelperSmallTest method extractSchemaVersionCustomSeparator.

@Test
public void extractSchemaVersionCustomSeparator() {
    Pair<MigrationVersion, String> info = MigrationInfoHelper.extractVersionAndDescription("V9_4-EmailAxel.sql", "V", "-", ".sql");
    MigrationVersion version = info.getLeft();
    String description = info.getRight();
    assertEquals("9.4", version.toString());
    assertEquals("EmailAxel", description);
}
Also used : MigrationVersion(org.flywaydb.core.api.MigrationVersion) Test(org.junit.Test)

Example 29 with MigrationVersion

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

the class MigrationInfoImplSmallTest method validateFuture.

@Test
public void validateFuture() {
    MigrationVersion version = MigrationVersion.fromVersion("1");
    String description = "test";
    MigrationType type = MigrationType.SQL;
    AppliedMigration appliedMigration = new AppliedMigration(1, version, description, type, null, 123, new Date(), "abc", 0, true);
    MigrationInfoImpl migrationInfo = new MigrationInfoImpl(null, appliedMigration, new MigrationInfoContext(), false);
    String message = migrationInfo.validate();
    assertTrue(message, message.contains("not resolved"));
}
Also used : MigrationVersion(org.flywaydb.core.api.MigrationVersion) AppliedMigration(org.flywaydb.core.internal.metadatatable.AppliedMigration) MigrationType(org.flywaydb.core.api.MigrationType) Date(java.util.Date) Test(org.junit.Test)

Example 30 with MigrationVersion

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

the class MigrationInfoImplSmallTest method validate.

@Test
public void validate() {
    MigrationVersion version = MigrationVersion.fromVersion("1");
    String description = "test";
    MigrationType type = MigrationType.SQL;
    ResolvedMigrationImpl resolvedMigration = new ResolvedMigrationImpl();
    resolvedMigration.setVersion(version);
    resolvedMigration.setDescription(description);
    resolvedMigration.setType(type);
    resolvedMigration.setChecksum(456);
    AppliedMigration appliedMigration = new AppliedMigration(1, version, description, type, null, 123, new Date(), "abc", 0, true);
    MigrationInfoImpl migrationInfo = new MigrationInfoImpl(resolvedMigration, appliedMigration, new MigrationInfoContext(), false);
    String message = migrationInfo.validate();
    assertTrue(message.contains("123"));
    assertTrue(message.contains("456"));
}
Also used : MigrationVersion(org.flywaydb.core.api.MigrationVersion) AppliedMigration(org.flywaydb.core.internal.metadatatable.AppliedMigration) MigrationType(org.flywaydb.core.api.MigrationType) ResolvedMigrationImpl(org.flywaydb.core.internal.resolver.ResolvedMigrationImpl) Date(java.util.Date) Test(org.junit.Test)

Aggregations

MigrationVersion (org.flywaydb.core.api.MigrationVersion)40 Test (org.junit.Test)27 SQLException (java.sql.SQLException)9 MigrationInfo (org.flywaydb.core.api.MigrationInfo)8 FlywayException (org.flywaydb.core.api.FlywayException)7 HashMap (java.util.HashMap)6 AppliedMigration (org.flywaydb.core.internal.metadatatable.AppliedMigration)6 ResolvedMigrationImpl (org.flywaydb.core.internal.resolver.ResolvedMigrationImpl)6 MigrationType (org.flywaydb.core.api.MigrationType)4 ArrayList (java.util.ArrayList)3 MigrationChecksumProvider (org.flywaydb.core.api.migration.MigrationChecksumProvider)3 MigrationInfoProvider (org.flywaydb.core.api.migration.MigrationInfoProvider)3 MigrationExecutor (org.flywaydb.core.api.resolver.MigrationExecutor)3 ResolvedMigration (org.flywaydb.core.api.resolver.ResolvedMigration)3 FlywaySqlScriptException (org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException)3 Date (java.util.Date)2 FlywaySqlException (org.flywaydb.core.internal.dbsupport.FlywaySqlException)2 PlaceholderReplacer (org.flywaydb.core.internal.util.PlaceholderReplacer)2 StopWatch (org.flywaydb.core.internal.util.StopWatch)2 TransactionTemplate (org.flywaydb.core.internal.util.jdbc.TransactionTemplate)2