use of org.flywaydb.core.api.MigrationInfo in project flyway by flyway.
the class DbRepair method repairChecksumsAndDescriptions.
public void repairChecksumsAndDescriptions() {
migrationInfoService.refresh();
for (MigrationInfo migrationInfo : migrationInfoService.all()) {
MigrationInfoImpl migrationInfoImpl = (MigrationInfoImpl) migrationInfo;
ResolvedMigration resolved = migrationInfoImpl.getResolvedMigration();
AppliedMigration applied = migrationInfoImpl.getAppliedMigration();
if (resolved != null && applied != null && resolved.getVersion() != null) {
if (!ObjectUtils.nullSafeEquals(resolved.getChecksum(), applied.getChecksum()) || !ObjectUtils.nullSafeEquals(resolved.getDescription(), applied.getDescription())) {
metaDataTable.update(migrationInfoImpl.getVersion(), resolved.getDescription(), resolved.getChecksum());
}
}
}
}
use of org.flywaydb.core.api.MigrationInfo in project flyway by flyway.
the class InfoServlet method doGet.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
MigrationInfoService migrationInfoService = flyway.info();
response.setContentType("application/json");
PrintWriter writer = response.getWriter();
writer.print("{\"status\":\"OK\", \"rows\":[");
boolean first = true;
for (MigrationInfo migrationInfo : migrationInfoService.all()) {
if (!first) {
writer.print(",");
}
writer.print("{\"version\":\"" + migrationInfo.getVersion() + "\",");
String description = migrationInfo.getDescription() == null ? "" : migrationInfo.getDescription();
writer.print("\"description\":\"" + description + "\",");
writer.print("\"script\":\"" + migrationInfo.getScript() + "\",");
writer.print("\"type\":\"" + migrationInfo.getType() + "\",");
writer.print("\"installedOn\":\"" + DateUtils.formatDateAsIsoString(migrationInfo.getInstalledOn()) + "\",");
writer.print("\"state\":\"" + migrationInfo.getState().name() + "\"}");
first = false;
}
writer.print("]}");
}
use of org.flywaydb.core.api.MigrationInfo in project flyway by flyway.
the class MigrationTestCase method nonEmptySchemaWithInitOnMigrateHighVersion.
@Test
public void nonEmptySchemaWithInitOnMigrateHighVersion() throws Exception {
createTestTable();
flyway.setLocations(getBasedir());
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());
}
use of org.flywaydb.core.api.MigrationInfo in project flyway by flyway.
the class MigrationTestCase method migrate.
@Test
public void migrate() throws Exception {
flyway.setLocations(getBasedir());
flyway.migrate();
MigrationVersion version = flyway.info().current().getVersion();
assertEquals("2.0", 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()) {
assertChecksum(migrationInfo);
}
assertEquals(2, jdbcTemplate.queryForInt("select count(*) from all_misters"));
}
use of org.flywaydb.core.api.MigrationInfo 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);
}
}
}
Aggregations