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);
}
}
}
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);
}
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);
}
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"));
}
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"));
}
Aggregations