Fix @FlywayDataSource with multiple data sources

See gh-20617
This commit is contained in:
Shimbo Takaaki
2020-03-23 22:07:11 +09:00
committed by Stephane Nicoll
parent 7be3db2d4d
commit 2410d6bbd1
2 changed files with 32 additions and 1 deletions

View File

@@ -125,7 +125,7 @@ public class FlywayAutoConfiguration {
ObjectProvider<JavaMigration> javaMigrations, ObjectProvider<Callback> callbacks) {
FluentConfiguration configuration = new FluentConfiguration(resourceLoader.getClassLoader());
DataSource dataSourceToMigrate = configureDataSource(configuration, properties, dataSourceProperties,
flywayDataSource.getIfAvailable(), dataSource.getIfAvailable());
flywayDataSource.getIfAvailable(), dataSource.getIfUnique());
checkLocationExists(dataSourceToMigrate, properties, resourceLoader);
configureProperties(configuration, properties);
List<Callback> orderedCallbacks = callbacks.orderedStream().collect(Collectors.toList());

View File

@@ -74,6 +74,7 @@ import static org.mockito.Mockito.mock;
* @author Stephane Nicoll
* @author Dominic Gunn
* @author András Deák
* @author Takaaki Shimbo
*/
class FlywayAutoConfigurationTests {
@@ -158,6 +159,15 @@ class FlywayAutoConfigurationTests {
});
}
@Test
void flywayMultipleDataSources() {
this.contextRunner.withUserConfiguration(FlywayMultipleDataSourcesConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(Flyway.class);
assertThat(context.getBean(Flyway.class).getConfiguration().getDataSource())
.isEqualTo(context.getBean("flywayDataSource"));
});
}
@Test
void schemaManagementProviderDetectsDataSource() {
this.contextRunner
@@ -509,6 +519,27 @@ class FlywayAutoConfigurationTests {
}
@Configuration(proxyBeanMethods = false)
static class FlywayMultipleDataSourcesConfiguration {
@Bean
DataSource mainDataSource() {
return DataSourceBuilder.create().url("jdbc:hsqldb:mem:main").username("sa").build();
}
@Bean
DataSource secondlyDataSource() {
return DataSourceBuilder.create().url("jdbc:hsqldb:mem:secondly").username("sa").build();
}
@FlywayDataSource
@Bean
DataSource flywayDataSource(DataSource mainDataSource) {
return mainDataSource;
}
}
@Configuration(proxyBeanMethods = false)
static class FlywayJavaMigrationsConfiguration {