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());
}
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);
}
}
}
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());
}
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());
}
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());
}
Aggregations