Search in sources :

Example 36 with Flyway

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

the class PostgreSQLSuperUserMigrationMediumTest 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("postgresql.password", "flyway");
    String url = customProperties.getProperty("postgresql.url", "jdbc:postgresql://localhost/flyway_db");
    flyway = new Flyway();
    flyway.setSchemas("super_user_test");
    flyway.setDataSource(new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, url, "postgres", password, null));
    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 37 with Flyway

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

the class RedshiftMigrationMediumTest 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 38 with Flyway

use of org.flywaydb.core.Flyway in project ninja by ninjaframework.

the class MigrationEngineFlyway method migrate.

@Override
public void migrate() {
    // Get the connection credentials from application.conf
    String connectionUrl = ninjaProperties.getOrDie(NinjaConstant.DB_CONNECTION_URL);
    String connectionUsername = ninjaProperties.getOrDie(NinjaConstant.DB_CONNECTION_USERNAME);
    String connectionPassword = ninjaProperties.getOrDie(NinjaConstant.DB_CONNECTION_PASSWORD);
    // We migrate automatically => if you do not want that (eg in production)
    // set ninja.migration.run=false in application.conf
    Flyway flyway = new Flyway();
    flyway.setDataSource(connectionUrl, connectionUsername, connectionPassword);
    // get a fresh database.
    if (ninjaProperties.getBooleanWithDefault(NinjaConstant.NINJA_MIGRATION_DROP_SCHEMA, ninjaProperties.isTest() ? true : false)) {
        flyway.clean();
    }
    flyway.migrate();
}
Also used : Flyway(org.flywaydb.core.Flyway)

Example 39 with Flyway

use of org.flywaydb.core.Flyway in project keywhiz by square.

the class MigrationsRule method apply.

@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            File yamlFile = new File(Resources.getResource("keywhiz-test.yaml").getFile());
            Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
            ObjectMapper objectMapper = KeywhizService.customizeObjectMapper(Jackson.newObjectMapper());
            KeywhizConfig config = new ConfigurationFactory<>(KeywhizConfig.class, validator, objectMapper, "dw").build(yamlFile);
            DataSource dataSource = config.getDataSourceFactory().build(new MetricRegistry(), "db-migrations");
            Flyway flyway = new Flyway();
            flyway.setDataSource(dataSource);
            flyway.setLocations(config.getMigrationsDir());
            flyway.clean();
            flyway.migrate();
            DSLContext dslContext = DSLContexts.databaseAgnostic(dataSource);
            DbSeedCommand.doImport(dslContext);
            base.evaluate();
        }
    };
}
Also used : Flyway(org.flywaydb.core.Flyway) Statement(org.junit.runners.model.Statement) MetricRegistry(com.codahale.metrics.MetricRegistry) DSLContext(org.jooq.DSLContext) File(java.io.File) Validator(javax.validation.Validator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataSource(javax.sql.DataSource)

Example 40 with Flyway

use of org.flywaydb.core.Flyway in project spring-boot by spring-projects.

the class FlywayAutoConfigurationTests method callbacksAreConfiguredAndOrdered.

@Test
public void callbacksAreConfiguredAndOrdered() throws Exception {
    registerAndRefresh(EmbeddedDataSourceConfiguration.class, FlywayAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, CallbackConfiguration.class);
    assertThat(this.context.getBeansOfType(Flyway.class)).hasSize(1);
    Flyway flyway = this.context.getBean(Flyway.class);
    FlywayCallback callbackOne = this.context.getBean("callbackOne", FlywayCallback.class);
    FlywayCallback callbackTwo = this.context.getBean("callbackTwo", FlywayCallback.class);
    assertThat(flyway.getCallbacks()).containsExactly(callbackTwo, callbackOne);
    InOrder orderedCallbacks = inOrder(callbackOne, callbackTwo);
    orderedCallbacks.verify(callbackTwo).beforeMigrate(any(Connection.class));
    orderedCallbacks.verify(callbackOne).beforeMigrate(any(Connection.class));
}
Also used : Flyway(org.flywaydb.core.Flyway) InOrder(org.mockito.InOrder) FlywayCallback(org.flywaydb.core.api.callback.FlywayCallback) 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