Search in sources :

Example 31 with Flyway

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

the class SQLiteMigrationMediumTest method singleConnectionExternalDataSource.

@Test
public void singleConnectionExternalDataSource() {
    SQLiteConfig config = new SQLiteConfig();
    config.setJournalMode(SQLiteConfig.JournalMode.WAL);
    config.setSynchronous(SQLiteConfig.SynchronousMode.NORMAL);
    SQLiteDataSource dataSource = new SQLiteDataSource(config);
    dataSource.setUrl("jdbc:sqlite:target/single_external");
    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    flyway.setLocations("migration/sql");
    flyway.clean();
    flyway.migrate();
}
Also used : SQLiteDataSource(org.sqlite.SQLiteDataSource) Flyway(org.flywaydb.core.Flyway) SQLiteConfig(org.sqlite.SQLiteConfig) Test(org.junit.Test)

Example 32 with Flyway

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

the class SQLServerCaseSensitiveMigrationTestCase method caseSensitiveCollation.

@Test
public void caseSensitiveCollation() 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));
    }
    DataSource dataSource = createDataSource(customProperties);
    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    flyway.setLocations("migration/sql");
    flyway.clean();
    flyway.migrate();
    assertEquals("2.0", flyway.info().current().getVersion().toString());
    assertEquals(0, flyway.migrate());
    assertEquals(4, flyway.info().applied().length);
    Connection connection = dataSource.getConnection();
    DbSupport dbSupport = DbSupportFactory.createDbSupport(connection, true);
    assertEquals(2, dbSupport.getJdbcTemplate().queryForInt("select count(*) from all_misters"));
    connection.close();
}
Also used : Flyway(org.flywaydb.core.Flyway) Connection(java.sql.Connection) DbSupport(org.flywaydb.core.internal.dbsupport.DbSupport) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 33 with Flyway

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

the class EnterpriseDBSuperUserMigrationMediumTest method setUp.

@Before
public void setUp() 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 password = customProperties.getProperty("enterprisedb.password", "flyway");
    String url = customProperties.getProperty("enterprisedb.url", "jdbc:edb://localhost/flyway_db");
    flyway = new Flyway();
    flyway.setSchemas("super_user_test");
    flyway.setDataSource(new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, url, "flyway", password, new Properties()));
    flyway.setValidateOnMigrate(true);
    flyway.clean();
}
Also used : Flyway(org.flywaydb.core.Flyway) DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream) Before(org.junit.Before)

Example 34 with Flyway

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

the class DerbyMigrationMediumTest method testFlyway1331.

@Test
public void testFlyway1331() throws Exception {
    try {
        Flyway flyway = new Flyway();
        flyway.setDataSource("jdbc:derby:memory:fw1331db;create=true", "sa", "sa");
        flyway.setLocations("migration/sql");
        flyway.setBaselineOnMigrate(true);
        flyway.migrate();
    } finally {
        try {
            JdbcUtils.closeConnection(DriverManager.getConnection("jdbc:derby:memory:fw1331db;shutdown=true", "sa", "sa"));
        } catch (Exception e) {
        // Suppress
        }
    }
}
Also used : Flyway(org.flywaydb.core.Flyway) FlywayException(org.flywaydb.core.api.FlywayException) Test(org.junit.Test)

Example 35 with Flyway

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

the class EnterpriseDBMigrationMediumTest 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(), new Properties()) {

        @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)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