Skip to content

Commit

Permalink
Merge branch '2.3.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Sep 18, 2020
2 parents d2fae6e + 55bfef9 commit 1c6e37b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Expand Up @@ -145,10 +145,6 @@ private DataSource configureDataSource(FluentConfiguration configuration, Flyway
String user = getProperty(properties::getUser, dataSourceProperties::determineUsername);
String password = getProperty(properties::getPassword, dataSourceProperties::determinePassword);
configuration.dataSource(url, user, password);
if (!CollectionUtils.isEmpty(properties.getInitSqls())) {
String initSql = StringUtils.collectionToDelimitedString(properties.getInitSqls(), "\n");
configuration.initSql(initSql);
}
}
else if (flywayDataSource != null) {
configuration.dataSource(flywayDataSource);
Expand Down Expand Up @@ -210,6 +206,9 @@ private void configureProperties(FluentConfiguration configuration, FlywayProper
map.from(properties.isSkipDefaultResolvers()).to(configuration::skipDefaultResolvers);
configureValidateMigrationNaming(configuration, properties.isValidateMigrationNaming());
map.from(properties.isValidateOnMigrate()).to(configuration::validateOnMigrate);
map.from(properties.getInitSqls()).whenNot(CollectionUtils::isEmpty)
.as((initSqls) -> StringUtils.collectionToDelimitedString(initSqls, "\n"))
.to(configuration::initSql);
// Pro properties
map.from(properties.getBatch()).whenNonNull().to(configuration::batch);
map.from(properties.getDryRunOutput()).whenNonNull().to(configuration::dryRunOutput);
Expand Down
Expand Up @@ -502,6 +502,24 @@ void customFlywayClassLoader() {
});
}

@Test
void initSqlsWithDataSource() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.init-sqls=SELECT 1").run((context) -> {
Flyway flyway = context.getBean(Flyway.class);
assertThat(flyway.getConfiguration().getInitSql()).isEqualTo("SELECT 1");
});
}

@Test
void initSqlsWithFlywayUrl() {
this.contextRunner.withPropertyValues("spring.flyway.url:jdbc:h2:mem:" + UUID.randomUUID(),
"spring.flyway.init-sqls=SELECT 1").run((context) -> {
Flyway flyway = context.getBean(Flyway.class);
assertThat(flyway.getConfiguration().getInitSql()).isEqualTo("SELECT 1");
});
}

@Configuration(proxyBeanMethods = false)
static class FlywayDataSourceConfiguration {

Expand Down

0 comments on commit 1c6e37b

Please sign in to comment.