Search in sources :

Example 6 with DriverDataSource

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());
}
Also used : FlywayException(org.flywaydb.core.api.FlywayException) DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) Test(org.junit.Test)

Example 7 with DriverDataSource

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();
}
Also used : H2DbSupport(org.flywaydb.core.internal.dbsupport.h2.H2DbSupport) DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) Schema(org.flywaydb.core.internal.dbsupport.Schema) Connection(java.sql.Connection) Test(org.junit.Test)

Example 8 with DriverDataSource

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());
}
Also used : DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) Test(org.junit.Test)

Example 9 with DriverDataSource

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);
}
Also used : DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) Test(org.junit.Test)

Example 10 with DriverDataSource

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());
}
Also used : DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) Properties(java.util.Properties) DataSource(javax.sql.DataSource) DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) Test(org.junit.Test)

Aggregations

DriverDataSource (org.flywaydb.core.internal.util.jdbc.DriverDataSource)45 Test (org.junit.Test)29 Properties (java.util.Properties)11 File (java.io.File)6 FileInputStream (java.io.FileInputStream)6 Connection (java.sql.Connection)6 Flyway (org.flywaydb.core.Flyway)6 MigrationInfo (org.flywaydb.core.api.MigrationInfo)5 SQLException (java.sql.SQLException)4 Statement (java.sql.Statement)4 FlywayException (org.flywaydb.core.api.FlywayException)4 DataSource (javax.sql.DataSource)3 HashMap (java.util.HashMap)2 JdbcTemplate (org.flywaydb.core.internal.dbsupport.JdbcTemplate)2 Before (org.junit.Before)2 LocalRdbmsServiceTestConfig (com.google.appengine.tools.development.testing.LocalRdbmsServiceTestConfig)1 LocalServiceTestHelper (com.google.appengine.tools.development.testing.LocalServiceTestHelper)1 PrintWriter (java.io.PrintWriter)1 Map (java.util.Map)1 HBaseTestingUtility (org.apache.hadoop.hbase.HBaseTestingUtility)1