Search in sources :

Example 21 with MigrationInfo

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);
    }
}
Also used : MigrationInfo(org.flywaydb.core.api.MigrationInfo) Connection(java.sql.Connection) JdbcTemplate(org.flywaydb.core.internal.dbsupport.JdbcTemplate) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 22 with MigrationInfo

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());
    }
}
Also used : MigrationInfo(org.flywaydb.core.api.MigrationInfo) MigrationVersion(org.flywaydb.core.api.MigrationVersion) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 23 with MigrationInfo

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);
}
Also used : Flyway(org.flywaydb.core.Flyway) MigrationInfo(org.flywaydb.core.api.MigrationInfo) PostConstruct(javax.annotation.PostConstruct)

Example 24 with MigrationInfo

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);
}
Also used : Flyway(org.flywaydb.core.Flyway) MigrationInfo(org.flywaydb.core.api.MigrationInfo)

Example 25 with MigrationInfo

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;
}
Also used : MigrationInfo(org.flywaydb.core.api.MigrationInfo) MigrationInfoImpl(org.flywaydb.core.internal.info.MigrationInfoImpl) AppliedMigration(org.flywaydb.core.internal.schemahistory.AppliedMigration) ResolvedMigration(org.flywaydb.core.api.resolver.ResolvedMigration)

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