use of org.flywaydb.core.internal.util.jdbc.DriverDataSource in project flyway by flyway.
the class FlywayMediumTest method repairDescription.
@Test
public void repairDescription() throws Exception {
DriverDataSource dataSource = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_db_repair_description;DB_CLOSE_DELAY=-1", "sa", "", null, "SET AUTOCOMMIT OFF");
Flyway flyway = new Flyway();
flyway.setDataSource(dataSource);
flyway.setLocations("migration/quote");
assertEquals(1, flyway.migrate());
// Switch out V1 for a different migration with a new description and checksum
flyway.setLocations("migration/placeholder");
try {
flyway.validate();
fail();
} catch (FlywayException e) {
//Should happen
}
flyway.repair();
assertEquals(0, flyway.migrate());
}
use of org.flywaydb.core.internal.util.jdbc.DriverDataSource in project flyway by flyway.
the class FlywayMediumTest method multipleSetDataSourceCalls.
@Test
public void multipleSetDataSourceCalls() throws Exception {
DriverDataSource dataSource1 = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_db_1;DB_CLOSE_DELAY=-1", "sa", "", null);
DriverDataSource dataSource2 = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_db_2;DB_CLOSE_DELAY=-1", "sa", "", null);
Connection connection1 = dataSource1.getConnection();
Connection connection2 = dataSource2.getConnection();
Schema schema1 = new H2DbSupport(connection1).getSchema("PUBLIC");
Schema schema2 = new H2DbSupport(connection2).getSchema("PUBLIC");
assertTrue(schema1.empty());
assertTrue(schema2.empty());
Flyway flyway = new Flyway();
flyway.setDataSource(dataSource1);
flyway.setDataSource(dataSource2);
flyway.setLocations("migration/sql");
flyway.migrate();
assertTrue(schema1.empty());
assertFalse(schema2.empty());
connection1.close();
connection2.close();
}
use of org.flywaydb.core.internal.util.jdbc.DriverDataSource in project flyway by flyway.
the class FlywayMediumTest method baselineOnMigrate.
@Test
public void baselineOnMigrate() throws Exception {
DriverDataSource dataSource = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_db_baseline_migrate;DB_CLOSE_DELAY=-1", "sa", "", null);
Flyway flyway = new Flyway();
flyway.setDataSource(dataSource);
flyway.setSchemas("new1");
flyway.setLocations("migration/sql");
flyway.setBaselineVersionAsString("3");
flyway.migrate();
assertEquals("2.0", flyway.info().current().getVersion().toString());
assertEquals(MigrationType.SQL, flyway.info().current().getType());
flyway.setTable("other_metadata");
flyway.setBaselineOnMigrate(true);
flyway.migrate();
assertEquals("3", flyway.info().current().getVersion().toString());
assertEquals(MigrationType.BASELINE, flyway.info().current().getType());
}
use of org.flywaydb.core.internal.util.jdbc.DriverDataSource in project flyway by flyway.
the class FlywayMediumTest method info.
@Test
public void info() throws Exception {
DriverDataSource dataSource = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_db_info;DB_CLOSE_DELAY=-1", "sa", null, null);
Flyway flyway = new Flyway();
flyway.setDataSource(dataSource);
flyway.setLocations("migration/sql");
assertEquals(4, flyway.info().all().length);
assertEquals(4, flyway.info().pending().length);
flyway.setTarget(MigrationVersion.fromVersion("1.1"));
assertEquals(4, flyway.info().all().length);
assertEquals(2, flyway.info().pending().length);
assertEquals(MigrationState.ABOVE_TARGET, flyway.info().all()[2].getState());
assertEquals(MigrationState.ABOVE_TARGET, flyway.info().all()[3].getState());
flyway.migrate();
assertEquals(-133051733, flyway.info().current().getChecksum().intValue());
assertEquals("1.1", flyway.info().current().getVersion().toString());
assertEquals(MigrationState.SUCCESS, flyway.info().current().getState());
assertEquals(4, flyway.info().all().length);
assertEquals(0, flyway.info().pending().length);
flyway.setTarget(MigrationVersion.LATEST);
assertEquals(4, flyway.info().all().length);
assertEquals(2, flyway.info().pending().length);
flyway.migrate();
assertEquals("2.0", flyway.info().current().getVersion().toString());
assertEquals(MigrationState.SUCCESS, flyway.info().current().getState());
assertEquals(4, flyway.info().all().length);
assertEquals(0, flyway.info().pending().length);
}
use of org.flywaydb.core.internal.util.jdbc.DriverDataSource in project flyway by flyway.
the class FlywaySmallTest method configureWithPartialDbConfigInProperties.
@Test
public void configureWithPartialDbConfigInProperties() {
DataSource dataSource = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_test;DB_CLOSE_DELAY=-1", "sa", "", null);
Properties properties = new Properties();
properties.setProperty("flyway.user", "dummy_user");
Flyway flyway = new Flyway();
flyway.setDataSource(dataSource);
flyway.configure(properties);
assertEquals(dataSource, flyway.getDataSource());
}
Aggregations