Search in sources :

Example 16 with DriverDataSource

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

the class FlywayMediumTest method repeatable.

@Test
public void repeatable() {
    DriverDataSource dataSource = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_repeatable;DB_CLOSE_DELAY=-1", "sa", "", null);
    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    flyway.setTargetAsString("1.1");
    flyway.setLocations("migration/sql", "migration/repeatable");
    assertEquals(4, flyway.migrate());
    assertEquals(0, flyway.info().pending().length);
    MigrationInfo[] all = flyway.info().all();
    assertEquals(MigrationState.SUCCESS, all[0].getState());
    assertEquals(MigrationState.SUCCESS, all[1].getState());
    assertEquals(MigrationState.SUCCESS, all[2].getState());
    assertEquals(MigrationState.SUCCESS, all[3].getState());
    assertEquals(MigrationState.ABOVE_TARGET, all[4].getState());
    assertEquals(MigrationState.ABOVE_TARGET, all[5].getState());
    flyway.setTarget(MigrationVersion.LATEST);
    flyway.setLocations("migration/sql", "migration/repeatable2");
    all = flyway.info().all();
    assertEquals(MigrationState.SUCCESS, all[0].getState());
    assertEquals(MigrationState.SUCCESS, all[1].getState());
    assertEquals(MigrationState.OUTDATED, all[2].getState());
    assertEquals(MigrationState.OUTDATED, all[3].getState());
    assertEquals(MigrationState.PENDING, all[4].getState());
    assertEquals(MigrationState.PENDING, all[5].getState());
    assertEquals(MigrationState.PENDING, all[6].getState());
    assertEquals(MigrationState.PENDING, all[7].getState());
    assertNotNull(all[0].getVersion());
    assertNotNull(all[1].getVersion());
    assertNull(all[2].getVersion());
    assertNull(all[3].getVersion());
    assertNotNull(all[4].getVersion());
    assertNotNull(all[5].getVersion());
    assertNull(all[6].getVersion());
    assertNull(all[7].getVersion());
    assertEquals(4, flyway.info().pending().length);
    assertEquals(4, flyway.migrate());
    assertEquals(0, flyway.info().pending().length);
    all = flyway.info().all();
    assertEquals(MigrationState.SUCCESS, all[0].getState());
    assertEquals(MigrationState.SUCCESS, all[1].getState());
    assertEquals(MigrationState.SUPERSEEDED, all[2].getState());
    assertEquals(MigrationState.SUPERSEEDED, all[3].getState());
    assertEquals(MigrationState.SUCCESS, all[4].getState());
    assertEquals(MigrationState.SUCCESS, all[5].getState());
    assertEquals(MigrationState.SUCCESS, all[6].getState());
    assertEquals(MigrationState.SUCCESS, all[7].getState());
    assertNotNull(all[0].getVersion());
    assertNotNull(all[1].getVersion());
    assertNull(all[2].getVersion());
    assertNull(all[3].getVersion());
    assertNotNull(all[4].getVersion());
    assertNotNull(all[5].getVersion());
    assertNull(all[6].getVersion());
    assertNull(all[7].getVersion());
    assertEquals(0, flyway.migrate());
    // Revert to original repeatable migrations, which should now be reapplied
    flyway.setLocations("migration/sql", "migration/repeatable");
    all = flyway.info().all();
    assertEquals(MigrationState.SUCCESS, all[0].getState());
    assertEquals(MigrationState.SUCCESS, all[1].getState());
    assertEquals(MigrationState.SUPERSEEDED, all[2].getState());
    assertEquals(MigrationState.SUPERSEEDED, all[3].getState());
    assertEquals(MigrationState.SUCCESS, all[4].getState());
    assertEquals(MigrationState.SUCCESS, all[5].getState());
    assertEquals(MigrationState.OUTDATED, all[6].getState());
    assertEquals(MigrationState.OUTDATED, all[7].getState());
    assertEquals(MigrationState.PENDING, all[8].getState());
    assertEquals(MigrationState.PENDING, all[9].getState());
    assertEquals(2, flyway.migrate());
    assertEquals(0, flyway.info().pending().length);
    all = flyway.info().all();
    assertEquals(MigrationState.SUCCESS, all[0].getState());
    assertEquals(MigrationState.SUCCESS, all[1].getState());
    assertEquals(MigrationState.SUPERSEEDED, all[2].getState());
    assertEquals(MigrationState.SUPERSEEDED, all[3].getState());
    assertEquals(MigrationState.SUCCESS, all[4].getState());
    assertEquals(MigrationState.SUCCESS, all[5].getState());
    assertEquals(MigrationState.SUPERSEEDED, all[6].getState());
    assertEquals(MigrationState.SUPERSEEDED, all[7].getState());
    assertEquals(MigrationState.SUCCESS, all[8].getState());
    assertEquals(MigrationState.SUCCESS, all[9].getState());
    assertNotNull(all[0].getVersion());
    assertNotNull(all[1].getVersion());
    assertNull(all[2].getVersion());
    assertNull(all[3].getVersion());
    assertNotNull(all[4].getVersion());
    assertNotNull(all[5].getVersion());
    assertNull(all[6].getVersion());
    assertNull(all[7].getVersion());
    assertNull(all[8].getVersion());
    assertNull(all[9].getVersion());
}
Also used : MigrationInfo(org.flywaydb.core.api.MigrationInfo) DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) Test(org.junit.Test)

Example 17 with DriverDataSource

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

the class VerticaDbSupportMediumTest method createDataSource.

/**
     * Creates a datasource for use in tests.
     *
     * @return The new datasource.
     */
private DataSource createDataSource() throws Exception {
    File customPropertiesFile = new File(System.getProperty("user.home") + "/flyway-mediumtests.properties");
    Properties customProperties = new Properties();
    if (customPropertiesFile.canRead()) {
        customProperties.load(new FileInputStream(customPropertiesFile));
    }
    String user = customProperties.getProperty("vertica.user", "dbadmin");
    String password = customProperties.getProperty("vertica.password", "flyway");
    String url = customProperties.getProperty("vertica.url", "jdbc:vertica://localhost/flyway");
    return new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, url, user, password, null);
}
Also used : DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 18 with DriverDataSource

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

the class VerticaMigrationMediumTest method emptySearchPath.

@Test
public void emptySearchPath() {
    Flyway flyway1 = new Flyway();
    DriverDataSource driverDataSource = (DriverDataSource) dataSource;
    flyway1.setDataSource(new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, driverDataSource.getUrl(), driverDataSource.getUser(), driverDataSource.getPassword(), null) {

        @Override
        public Connection getConnection() throws SQLException {
            Connection connection = super.getConnection();
            Statement statement = null;
            try {
                statement = connection.createStatement();
                statement.execute("SET search_path = v_catalog");
            } finally {
                JdbcUtils.closeStatement(statement);
            }
            return connection;
        }
    });
    flyway1.setLocations(getBasedir());
    flyway1.setSchemas("public");
    flyway1.migrate();
}
Also used : Flyway(org.flywaydb.core.Flyway) DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) Test(org.junit.Test)

Example 19 with DriverDataSource

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

the class PostgreSQLMigrationMediumTest method emptySearchPath.

@Test
public void emptySearchPath() {
    Flyway flyway1 = new Flyway();
    DriverDataSource driverDataSource = (DriverDataSource) dataSource;
    flyway1.setDataSource(new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, driverDataSource.getUrl(), driverDataSource.getUser(), driverDataSource.getPassword(), null) {

        @Override
        public Connection getConnection() throws SQLException {
            Connection connection = super.getConnection();
            Statement statement = null;
            try {
                statement = connection.createStatement();
                statement.execute("SELECT set_config('search_path', '', false)");
            } finally {
                JdbcUtils.closeStatement(statement);
            }
            return connection;
        }
    });
    flyway1.setLocations(getBasedir());
    flyway1.setSchemas("public");
    flyway1.migrate();
}
Also used : Flyway(org.flywaydb.core.Flyway) DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) Test(org.junit.Test)

Example 20 with DriverDataSource

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

the class PostgreSQLMigrationMediumTest method createDataSource.

@Override
protected DataSource createDataSource(Properties customProperties) {
    String user = customProperties.getProperty("postgresql.user", "flyway");
    String password = customProperties.getProperty("postgresql.password", "flyway");
    String url = customProperties.getProperty("postgresql.url", "jdbc:postgresql://localhost/flyway_db");
    return new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, url, user, password, null);
}
Also used : DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

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