use of org.flywaydb.core.api.MigrationInfo in project flyway by flyway.
the class ConcurrentMigrationTestCase method migrateConcurrently.
@Test
public void migrateConcurrently() throws Exception {
Runnable runnable = new Runnable() {
public void run() {
try {
createFlyway().migrate();
} catch (Exception e) {
LOG.error("Migrate failed", e);
error = e.getMessage();
}
}
};
Thread[] threads = new Thread[NUM_THREADS];
for (int i = 0; i < NUM_THREADS; i++) {
threads[i] = new Thread(runnable);
}
for (int i = 0; i < NUM_THREADS; i++) {
threads[i].start();
}
for (int i = 0; i < NUM_THREADS; i++) {
threads[i].join();
}
assertNull(error, error);
final MigrationInfo[] applied = flyway.info().applied();
int expected = 4;
if (applied[0].getType() == MigrationType.SCHEMA) {
expected++;
}
if (needsBaseline()) {
expected++;
}
assertEquals(expected, applied.length);
assertEquals("2.0", flyway.info().current().getVersion().toString());
assertEquals(0, flyway.migrate());
Connection connection = null;
try {
connection = concurrentMigrationDataSource.getConnection();
assertEquals(2, new JdbcTemplate(connection, 0).queryForInt("SELECT COUNT(*) FROM " + schemaQuoted + ".test_user"));
} finally {
JdbcUtils.closeConnection(connection);
}
}
use of org.flywaydb.core.api.MigrationInfo in project flyway by flyway.
the class OracleMigrationMediumTest 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/oracle/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());
}
}
use of org.flywaydb.core.api.MigrationInfo in project solr-document-store by DBCDK.
the class DatabaseMigrator method migrate.
@PostConstruct
public void migrate() {
final Flyway flyway = new Flyway();
flyway.setTable("schema_version");
flyway.setBaselineOnMigrate(true);
flyway.setDataSource(dataSource);
for (MigrationInfo i : flyway.info().all()) {
log.info("db task {} : {} from file '{}'", i.getVersion(), i.getDescription(), i.getScript());
}
flyway.migrate();
dk.dbc.search.solrdocstore.queue.DatabaseMigrator.migrate(dataSource);
}
use of org.flywaydb.core.api.MigrationInfo in project solr-document-store by DBCDK.
the class DatabaseMigrator method migrate.
public static void migrate(DataSource dataSource) {
final Flyway flyway = new Flyway();
flyway.setTable("solr_doc_store_queue_version");
flyway.setBaselineOnMigrate(true);
flyway.setDataSource(dataSource);
flyway.setLocations("solr-doc-store-queue/migration");
for (MigrationInfo i : flyway.info().all()) {
log.info("db task {} : {} from file '{}'", i.getVersion(), i.getDescription(), i.getScript());
}
flyway.migrate();
dk.dbc.pgqueue.DatabaseMigrator.migrate(dataSource);
}
use of org.flywaydb.core.api.MigrationInfo in project flyway by flyway.
the class DbRepair method alignAppliedMigrationsWithResolvedMigrations.
private boolean alignAppliedMigrationsWithResolvedMigrations() {
boolean repaired = false;
for (MigrationInfo migrationInfo : migrationInfoService.all()) {
MigrationInfoImpl migrationInfoImpl = (MigrationInfoImpl) migrationInfo;
ResolvedMigration resolved = migrationInfoImpl.getResolvedMigration();
AppliedMigration applied = migrationInfoImpl.getAppliedMigration();
// Repair versioned
if (resolved != null && resolved.getVersion() != null && applied != null && !applied.getType().isSynthetic() && migrationInfoImpl.getState() != MigrationState.IGNORED && updateNeeded(resolved, applied)) {
schemaHistory.update(applied, resolved);
repaired = true;
repairResult.migrationsAligned.add(CommandResultFactory.createRepairOutput(migrationInfo));
}
// Repair repeatable
if (resolved != null && resolved.getVersion() == null && applied != null && !applied.getType().isSynthetic() && migrationInfoImpl.getState() != MigrationState.IGNORED && resolved.checksumMatchesWithoutBeingIdentical(applied.getChecksum())) {
schemaHistory.update(applied, resolved);
repaired = true;
repairResult.migrationsAligned.add(CommandResultFactory.createRepairOutput(migrationInfo));
}
}
return repaired;
}
Aggregations