Search in sources :

Example 11 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)

Example 12 with Flyway

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

the class MigrationTestCase method configureFlyway.

protected void configureFlyway() {
    flyway = new Flyway();
    flyway.setDataSource(dataSource);
}
Also used : Flyway(org.flywaydb.core.Flyway)

Example 13 with Flyway

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

the class AbstractFlywayTask method runTask.

@TaskAction
public Object runTask() {
    try {
        List<URL> extraURLs = new ArrayList<URL>();
        if (isJavaProject()) {
            JavaPluginConvention plugin = getProject().getConvention().getPlugin(JavaPluginConvention.class);
            for (SourceSet sourceSet : plugin.getSourceSets()) {
                URL classesUrl = sourceSet.getOutput().getClassesDir().toURI().toURL();
                getLogger().debug("Adding directory to Classpath: " + classesUrl);
                extraURLs.add(classesUrl);
                URL resourcesUrl = sourceSet.getOutput().getResourcesDir().toURI().toURL();
                getLogger().debug("Adding directory to Classpath: " + resourcesUrl);
                extraURLs.add(resourcesUrl);
            }
            addDependenciesWithScope(extraURLs, "compile");
            addDependenciesWithScope(extraURLs, "runtime");
            addDependenciesWithScope(extraURLs, "testCompile");
            addDependenciesWithScope(extraURLs, "testRuntime");
        }
        ClassLoader classLoader = new URLClassLoader(extraURLs.toArray(new URL[extraURLs.size()]), getProject().getBuildscript().getClassLoader());
        Flyway flyway = new Flyway();
        flyway.setClassLoader(classLoader);
        flyway.configure(createFlywayConfig());
        return run(flyway);
    } catch (Exception e) {
        handleException(e);
        return null;
    }
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) Flyway(org.flywaydb.core.Flyway) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) URLClassLoader(java.net.URLClassLoader) ArrayList(java.util.ArrayList) URLClassLoader(java.net.URLClassLoader) URL(java.net.URL) FlywayException(org.flywaydb.core.api.FlywayException) IOException(java.io.IOException) TaskAction(org.gradle.api.tasks.TaskAction)

Example 14 with Flyway

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

the class AbstractFlywayMojoSmallTest method skipExecute.

@Test
public void skipExecute() throws Exception {
    AbstractFlywayMojo mojo = new AbstractFlywayMojo() {

        @Override
        protected void doExecute(Flyway flyway) throws Exception {
            assertNull(flyway.getDataSource());
        }
    };
    mojo.skip = true;
    mojo.url = "jdbc:h2:mem:dummy";
    mojo.mavenProject = new MavenProject();
    mojo.execute();
}
Also used : Flyway(org.flywaydb.core.Flyway) MavenProject(org.apache.maven.project.MavenProject) Test(org.junit.Test)

Example 15 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)

Aggregations

Flyway (org.flywaydb.core.Flyway)51 Test (org.junit.Test)26 Connection (java.sql.Connection)7 Bean (org.springframework.context.annotation.Bean)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 ConditionalOnExpression (org.springframework.boot.autoconfigure.condition.ConditionalOnExpression)5 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)5 ConfigurationProperties (org.springframework.boot.context.properties.ConfigurationProperties)5 EnableConfigurationProperties (org.springframework.boot.context.properties.EnableConfigurationProperties)5 DependsOn (org.springframework.context.annotation.DependsOn)5 MetricRegistry (com.codahale.metrics.MetricRegistry)4 Statement (java.sql.Statement)4 FlywayException (org.flywaydb.core.api.FlywayException)4 FileInputStream (java.io.FileInputStream)3 ArrayList (java.util.ArrayList)3 MigrationInfo (org.flywaydb.core.api.MigrationInfo)3