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());
}
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);
}
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();
}
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();
}
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);
}
Aggregations