Search in sources :

Example 26 with DriverDataSource

use of org.flywaydb.core.internal.util.jdbc.DriverDataSource in project flyway by flyway.

the class FlywayMediumTest method baselineRepair.

@Test
public void baselineRepair() throws Exception {
    DriverDataSource dataSource = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_db_baseline_repair;DB_CLOSE_DELAY=-1", "sa", "", null);
    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    flyway.setSchemas("new1");
    flyway.setLocations("migration/sql");
    flyway.setBaselineVersionAsString("2");
    flyway.baseline();
    assertEquals("2", flyway.info().current().getVersion().toString());
    assertEquals(MigrationType.BASELINE, flyway.info().current().getType());
    flyway.repair();
    assertEquals("2", flyway.info().current().getVersion().toString());
    assertEquals(MigrationType.BASELINE, flyway.info().current().getType());
    flyway.migrate();
    assertEquals("2", 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 27 with DriverDataSource

use of org.flywaydb.core.internal.util.jdbc.DriverDataSource in project flyway by flyway.

the class FlywayMediumTest method baselineAgainWithSameVersion.

@Test
public void baselineAgainWithSameVersion() throws Exception {
    DriverDataSource dataSource = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_db_init_same;DB_CLOSE_DELAY=-1", "sa", "", null);
    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    flyway.setLocations("migration/sql");
    flyway.setBaselineVersionAsString("0.5");
    flyway.baseline();
    flyway.baseline();
    assertEquals(1, flyway.info().applied().length);
    MigrationInfo current = flyway.info().current();
    assertEquals("0.5", current.getVersion().toString());
    assertEquals(MigrationType.BASELINE, current.getType());
    assertEquals(MigrationState.BASELINE, current.getState());
}
Also used : MigrationInfo(org.flywaydb.core.api.MigrationInfo) DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) Test(org.junit.Test)

Example 28 with DriverDataSource

use of org.flywaydb.core.internal.util.jdbc.DriverDataSource in project flyway by flyway.

the class FlywayMediumTest method baselineAfterInit.

@Test
public void baselineAfterInit() throws Exception {
    DriverDataSource dataSource = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_db_baseline_init;DB_CLOSE_DELAY=-1", "sa", "", null);
    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    flyway.setSchemas("new1");
    flyway.setLocations("migration/validate");
    flyway.baseline();
    new JdbcTemplate(dataSource.getConnection(), 0).executeStatement("UPDATE \"new1\".\"schema_version\" SET \"type\"='BASELINE' WHERE \"type\"='BASELINE'");
    assertEquals("1", flyway.info().current().getVersion().toString());
    assertEquals(MigrationType.BASELINE, flyway.info().current().getType());
    flyway.baseline();
    assertEquals("1", flyway.info().current().getVersion().toString());
    assertEquals(MigrationType.BASELINE, flyway.info().current().getType());
}
Also used : DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) JdbcTemplate(org.flywaydb.core.internal.dbsupport.JdbcTemplate) Test(org.junit.Test)

Example 29 with DriverDataSource

use of org.flywaydb.core.internal.util.jdbc.DriverDataSource in project flyway by flyway.

the class FlywayMediumTest method repeatableFailed.

@Test
public void repeatableFailed() {
    DriverDataSource dataSource = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_repeatable_failed;DB_CLOSE_DELAY=-1", "sa", "", null);
    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    flyway.setLocations("migration/repeatable_failed");
    try {
        flyway.migrate();
        fail();
    } catch (FlywayException e) {
        assertEquals(e.getMessage(), MigrationState.FAILED, flyway.info().current().getState());
    }
    try {
        flyway.validate();
        fail();
    } catch (FlywayException e) {
        assertTrue(e.getMessage(), e.getMessage().contains("failed repeatable migration"));
    }
    flyway.setLocations("migration/repeatable");
    try {
        flyway.migrate();
        fail();
    } catch (FlywayException e) {
        assertTrue(e.getMessage(), e.getMessage().contains("failed repeatable migration"));
    }
}
Also used : FlywayException(org.flywaydb.core.api.FlywayException) DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) Test(org.junit.Test)

Example 30 with DriverDataSource

use of org.flywaydb.core.internal.util.jdbc.DriverDataSource in project flyway by flyway.

the class FlywayMediumTest method cleanDisabled.

@Test(expected = FlywayException.class)
public void cleanDisabled() throws Exception {
    DriverDataSource dataSource = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_db_clean_disabled;DB_CLOSE_DELAY=-1", "sa", "", null);
    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    try {
        flyway.clean();
    } catch (FlywayException e) {
        fail("clean should succeed when cleanDisabled is false");
    }
    flyway.setCleanDisabled(true);
    flyway.clean();
}
Also used : FlywayException(org.flywaydb.core.api.FlywayException) 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