Search in sources :

Example 16 with Flyway

use of org.flywaydb.core.Flyway in project flyway by flyway.

the class OsgiActivator method start.

public void start(BundleContext context) throws Exception {
    System.out.println("Starting Flyway Sample OSGi");
    try {
        Properties properties = new Properties();
        properties.setProperty("flyway.driver", "org.h2.Driver");
        properties.setProperty("flyway.url", "jdbc:h2:mem:flyway_db;DB_CLOSE_DELAY=-1");
        properties.setProperty("flyway.user", "sa");
        properties.setProperty("flyway.password", "");
        Flyway flyway = new Flyway();
        flyway.configure(properties);
        flyway.setLocations("db.migration", "org.flywaydb.sample.osgi.fragment");
        flyway.migrate();
        System.out.println("New schema version: " + flyway.info().current().getVersion());
        System.exit(0);
    } catch (Throwable t) {
        t.printStackTrace();
    // System.exit(0);
    }
}
Also used : Flyway(org.flywaydb.core.Flyway) Properties(java.util.Properties)

Example 17 with Flyway

use of org.flywaydb.core.Flyway in project flyway by flyway.

the class SQLiteMigrationMediumTest method singleConnectionInternalDataSource.

@Test
public void singleConnectionInternalDataSource() {
    Flyway flyway = new Flyway();
    flyway.setDataSource("jdbc:sqlite:target/single_internal", "", "");
    flyway.setDataSource(dataSource);
    flyway.setLocations("migration/sql");
    flyway.clean();
    flyway.migrate();
}
Also used : Flyway(org.flywaydb.core.Flyway) Test(org.junit.Test)

Example 18 with Flyway

use of org.flywaydb.core.Flyway in project flyway by flyway.

the class ConcurrentMigrationTestCase method createFlyway.

private Flyway createFlyway() throws SQLException {
    Flyway newFlyway = new Flyway();
    newFlyway.setDataSource(concurrentMigrationDataSource);
    newFlyway.setLocations(getBasedir());
    newFlyway.setSchemas(schemaName);
    Map<String, String> placeholders = new HashMap<String, String>();
    placeholders.put("schema", schemaQuoted);
    newFlyway.setPlaceholders(placeholders);
    newFlyway.setBaselineVersionAsString("0.1");
    return newFlyway;
}
Also used : Flyway(org.flywaydb.core.Flyway) HashMap(java.util.HashMap)

Example 19 with Flyway

use of org.flywaydb.core.Flyway 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 20 with Flyway

use of org.flywaydb.core.Flyway 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)

Aggregations

Flyway (org.flywaydb.core.Flyway)44 Test (org.junit.Test)26 Connection (java.sql.Connection)7 DriverDataSource (org.flywaydb.core.internal.util.jdbc.DriverDataSource)6 File (java.io.File)5 SQLException (java.sql.SQLException)5 Properties (java.util.Properties)5 DataSource (javax.sql.DataSource)5 MetricRegistry (com.codahale.metrics.MetricRegistry)4 Statement (java.sql.Statement)4 FlywayException (org.flywaydb.core.api.FlywayException)4 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 MavenProject (org.apache.maven.project.MavenProject)2 MigrationInfo (org.flywaydb.core.api.MigrationInfo)2 DbSupport (org.flywaydb.core.internal.dbsupport.DbSupport)2 Before (org.junit.Before)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1