Search in sources :

Example 21 with DriverDataSource

use of org.flywaydb.core.internal.util.jdbc.DriverDataSource in project flyway by flyway.

the class MigrationTestCase method testAutoCommit.

private void testAutoCommit(boolean autoCommit) {
    DriverDataSource dataSource = (DriverDataSource) flyway.getDataSource();
    dataSource.setAutoCommit(autoCommit);
    flyway.setLocations(BASEDIR);
    flyway.migrate();
    assertEquals("2.0", flyway.info().current().getVersion().getVersion());
}
Also used : DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource)

Example 22 with DriverDataSource

use of org.flywaydb.core.internal.util.jdbc.DriverDataSource in project flyway by flyway.

the class Flyway method configure.

/**
     * Configures Flyway with these properties. This overwrites any existing configuration. Property names are
     * documented in the flyway maven plugin.
     * <p/>
     * <p>To use a custom ClassLoader, setClassLoader() must be called prior to calling this method.</p>
     *
     * @param props Properties used for configuration.
     * @throws FlywayException when the configuration failed.
     */
public void configure(Map<String, String> props) {
    String driverProp = getValueAndRemoveEntry(props, "flyway.driver");
    String urlProp = getValueAndRemoveEntry(props, "flyway.url");
    String userProp = getValueAndRemoveEntry(props, "flyway.user");
    String passwordProp = getValueAndRemoveEntry(props, "flyway.password");
    if (StringUtils.hasText(urlProp)) {
        setDataSource(new DriverDataSource(classLoader, driverProp, urlProp, userProp, passwordProp, null));
    } else if (!StringUtils.hasText(urlProp) && (StringUtils.hasText(driverProp) || StringUtils.hasText(userProp) || StringUtils.hasText(passwordProp))) {
        LOG.warn("Discarding INCOMPLETE dataSource configuration! flyway.url must be set.");
    }
    String locationsProp = getValueAndRemoveEntry(props, "flyway.locations");
    if (locationsProp != null) {
        setLocations(StringUtils.tokenizeToStringArray(locationsProp, ","));
    }
    String placeholderReplacementProp = getValueAndRemoveEntry(props, "flyway.placeholderReplacement");
    if (placeholderReplacementProp != null) {
        setPlaceholderReplacement(Boolean.parseBoolean(placeholderReplacementProp));
    }
    String placeholderPrefixProp = getValueAndRemoveEntry(props, "flyway.placeholderPrefix");
    if (placeholderPrefixProp != null) {
        setPlaceholderPrefix(placeholderPrefixProp);
    }
    String placeholderSuffixProp = getValueAndRemoveEntry(props, "flyway.placeholderSuffix");
    if (placeholderSuffixProp != null) {
        setPlaceholderSuffix(placeholderSuffixProp);
    }
    String sqlMigrationPrefixProp = getValueAndRemoveEntry(props, "flyway.sqlMigrationPrefix");
    if (sqlMigrationPrefixProp != null) {
        setSqlMigrationPrefix(sqlMigrationPrefixProp);
    }
    String repeatableSqlMigrationPrefixProp = getValueAndRemoveEntry(props, "flyway.repeatableSqlMigrationPrefix");
    if (repeatableSqlMigrationPrefixProp != null) {
        setRepeatableSqlMigrationPrefix(repeatableSqlMigrationPrefixProp);
    }
    String sqlMigrationSeparatorProp = getValueAndRemoveEntry(props, "flyway.sqlMigrationSeparator");
    if (sqlMigrationSeparatorProp != null) {
        setSqlMigrationSeparator(sqlMigrationSeparatorProp);
    }
    String sqlMigrationSuffixProp = getValueAndRemoveEntry(props, "flyway.sqlMigrationSuffix");
    if (sqlMigrationSuffixProp != null) {
        setSqlMigrationSuffix(sqlMigrationSuffixProp);
    }
    String encodingProp = getValueAndRemoveEntry(props, "flyway.encoding");
    if (encodingProp != null) {
        setEncoding(encodingProp);
    }
    String schemasProp = getValueAndRemoveEntry(props, "flyway.schemas");
    if (schemasProp != null) {
        setSchemas(StringUtils.tokenizeToStringArray(schemasProp, ","));
    }
    String tableProp = getValueAndRemoveEntry(props, "flyway.table");
    if (tableProp != null) {
        setTable(tableProp);
    }
    String cleanOnValidationErrorProp = getValueAndRemoveEntry(props, "flyway.cleanOnValidationError");
    if (cleanOnValidationErrorProp != null) {
        setCleanOnValidationError(Boolean.parseBoolean(cleanOnValidationErrorProp));
    }
    String cleanDisabledProp = getValueAndRemoveEntry(props, "flyway.cleanDisabled");
    if (cleanDisabledProp != null) {
        setCleanDisabled(Boolean.parseBoolean(cleanDisabledProp));
    }
    String validateOnMigrateProp = getValueAndRemoveEntry(props, "flyway.validateOnMigrate");
    if (validateOnMigrateProp != null) {
        setValidateOnMigrate(Boolean.parseBoolean(validateOnMigrateProp));
    }
    String baselineVersionProp = getValueAndRemoveEntry(props, "flyway.baselineVersion");
    if (baselineVersionProp != null) {
        setBaselineVersion(MigrationVersion.fromVersion(baselineVersionProp));
    }
    String baselineDescriptionProp = getValueAndRemoveEntry(props, "flyway.baselineDescription");
    if (baselineDescriptionProp != null) {
        setBaselineDescription(baselineDescriptionProp);
    }
    String baselineOnMigrateProp = getValueAndRemoveEntry(props, "flyway.baselineOnMigrate");
    if (baselineOnMigrateProp != null) {
        setBaselineOnMigrate(Boolean.parseBoolean(baselineOnMigrateProp));
    }
    String ignoreMissingMigrationsProp = getValueAndRemoveEntry(props, "flyway.ignoreMissingMigrations");
    if (ignoreMissingMigrationsProp != null) {
        setIgnoreMissingMigrations(Boolean.parseBoolean(ignoreMissingMigrationsProp));
    }
    String ignoreFutureMigrationsProp = getValueAndRemoveEntry(props, "flyway.ignoreFutureMigrations");
    if (ignoreFutureMigrationsProp != null) {
        setIgnoreFutureMigrations(Boolean.parseBoolean(ignoreFutureMigrationsProp));
    }
    String ignoreFailedFutureMigrationProp = getValueAndRemoveEntry(props, "flyway.ignoreFailedFutureMigration");
    if (ignoreFailedFutureMigrationProp != null) {
        setIgnoreFailedFutureMigration(Boolean.parseBoolean(ignoreFailedFutureMigrationProp));
    }
    String targetProp = getValueAndRemoveEntry(props, "flyway.target");
    if (targetProp != null) {
        setTarget(MigrationVersion.fromVersion(targetProp));
    }
    String outOfOrderProp = getValueAndRemoveEntry(props, "flyway.outOfOrder");
    if (outOfOrderProp != null) {
        setOutOfOrder(Boolean.parseBoolean(outOfOrderProp));
    }
    String resolversProp = getValueAndRemoveEntry(props, "flyway.resolvers");
    if (StringUtils.hasLength(resolversProp)) {
        setResolversAsClassNames(StringUtils.tokenizeToStringArray(resolversProp, ","));
    }
    String skipDefaultResolversProp = getValueAndRemoveEntry(props, "flyway.skipDefaultResolvers");
    if (skipDefaultResolversProp != null) {
        setSkipDefaultResolvers(Boolean.parseBoolean(skipDefaultResolversProp));
    }
    String callbacksProp = getValueAndRemoveEntry(props, "flyway.callbacks");
    if (StringUtils.hasLength(callbacksProp)) {
        setCallbacksAsClassNames(StringUtils.tokenizeToStringArray(callbacksProp, ","));
    }
    String skipDefaultCallbacksProp = getValueAndRemoveEntry(props, "flyway.skipDefaultCallbacks");
    if (skipDefaultCallbacksProp != null) {
        setSkipDefaultCallbacks(Boolean.parseBoolean(skipDefaultCallbacksProp));
    }
    Map<String, String> placeholdersFromProps = new HashMap<String, String>(placeholders);
    Iterator<Map.Entry<String, String>> iterator = props.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<String, String> entry = iterator.next();
        String propertyName = entry.getKey();
        if (propertyName.startsWith(PLACEHOLDERS_PROPERTY_PREFIX) && propertyName.length() > PLACEHOLDERS_PROPERTY_PREFIX.length()) {
            String placeholderName = propertyName.substring(PLACEHOLDERS_PROPERTY_PREFIX.length());
            String placeholderValue = entry.getValue();
            placeholdersFromProps.put(placeholderName, placeholderValue);
            iterator.remove();
        }
    }
    setPlaceholders(placeholdersFromProps);
    String allowMixedMigrationsProp = getValueAndRemoveEntry(props, "flyway.allowMixedMigrations");
    if (allowMixedMigrationsProp != null) {
        setAllowMixedMigrations(Boolean.parseBoolean(allowMixedMigrationsProp));
    }
    String installedByProp = getValueAndRemoveEntry(props, "flyway.installedBy");
    if (installedByProp != null) {
        setInstalledBy(installedByProp);
    }
    for (String key : props.keySet()) {
        if (key.startsWith("flyway.")) {
            LOG.warn("Unknown configuration property: " + key);
        }
    }
}
Also used : DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 23 with DriverDataSource

use of org.flywaydb.core.internal.util.jdbc.DriverDataSource in project flyway by flyway.

the class FlywayMediumTest method cleanOnValidate.

@Test
public void cleanOnValidate() throws Exception {
    DriverDataSource dataSource = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_db_clean_validate;DB_CLOSE_DELAY=-1", "sa", "", null);
    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    flyway.setSchemas("new1");
    flyway.setLocations("migration/validate");
    flyway.migrate();
    flyway.setCleanOnValidationError(true);
    flyway.setValidateOnMigrate(true);
    flyway.setSqlMigrationPrefix("CheckValidate");
    flyway.migrate();
    assertEquals("1", flyway.info().current().getVersion().toString());
}
Also used : DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) Test(org.junit.Test)

Example 24 with DriverDataSource

use of org.flywaydb.core.internal.util.jdbc.DriverDataSource in project flyway by flyway.

the class FlywayMediumTest method baselineOnMigrateCheck.

@Test
public void baselineOnMigrateCheck() throws Exception {
    DriverDataSource dataSource = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_db_baseline_migrate_check;DB_CLOSE_DELAY=-1", "sa", "", null);
    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    flyway.setSchemas("new1");
    flyway.setLocations("migration/sql");
    flyway.setBaselineVersionAsString("3");
    flyway.setBaselineOnMigrate(true);
    flyway.migrate();
    assertEquals("2.0", flyway.info().current().getVersion().toString());
    assertEquals(MigrationType.SQL, flyway.info().current().getType());
}
Also used : DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) Test(org.junit.Test)

Example 25 with DriverDataSource

use of org.flywaydb.core.internal.util.jdbc.DriverDataSource in project flyway by flyway.

the class FlywayMediumTest method repairFirst.

@Test
public void repairFirst() throws Exception {
    DriverDataSource dataSource = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_db_repair;DB_CLOSE_DELAY=-1", "sa", "", null, "SET AUTOCOMMIT OFF");
    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    Map<String, String> placeholders = new HashMap<String, String>();
    placeholders.put("tableName", "aaa");
    flyway.setPlaceholders(placeholders);
    flyway.setLocations("migration/failed");
    assertEquals(1, flyway.info().all().length);
    try {
        flyway.migrate();
    } catch (FlywayException e) {
    //Should happen
    }
    assertEquals("1", flyway.info().current().getVersion().toString());
    assertEquals(MigrationState.FAILED, flyway.info().current().getState());
    flyway.repair();
    assertNull(flyway.info().current());
}
Also used : FlywayException(org.flywaydb.core.api.FlywayException) DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

DriverDataSource (org.flywaydb.core.internal.util.jdbc.DriverDataSource)45 Test (org.junit.Test)29 Properties (java.util.Properties)11 File (java.io.File)6 FileInputStream (java.io.FileInputStream)6 Connection (java.sql.Connection)6 Flyway (org.flywaydb.core.Flyway)6 MigrationInfo (org.flywaydb.core.api.MigrationInfo)5 SQLException (java.sql.SQLException)4 Statement (java.sql.Statement)4 FlywayException (org.flywaydb.core.api.FlywayException)4 DataSource (javax.sql.DataSource)3 HashMap (java.util.HashMap)2 JdbcTemplate (org.flywaydb.core.internal.dbsupport.JdbcTemplate)2 Before (org.junit.Before)2 LocalRdbmsServiceTestConfig (com.google.appengine.tools.development.testing.LocalRdbmsServiceTestConfig)1 LocalServiceTestHelper (com.google.appengine.tools.development.testing.LocalServiceTestHelper)1 PrintWriter (java.io.PrintWriter)1 Map (java.util.Map)1 HBaseTestingUtility (org.apache.hadoop.hbase.HBaseTestingUtility)1