Fix @FlywayDataSource with multiple data sources

See gh-20617
pull/20629/head
Shimbo Takaaki 5 years ago committed by Stephane Nicoll
parent 7be3db2d4d
commit 2410d6bbd1

@ -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());

@ -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 {

Loading…
Cancel
Save