Merge pull request #20617 from ta7uw

* pr/20617:
  Polish "Fix @FlywayDataSource with multiple data sources"
  Fix @FlywayDataSource with multiple data sources

Closes gh-20617
This commit is contained in:
Stephane Nicoll
2020-03-23 14:37:42 +01:00
2 changed files with 34 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -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

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -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 firstDataSource() {
return DataSourceBuilder.create().url("jdbc:hsqldb:mem:first").username("sa").build();
}
@Bean
DataSource secondDataSource() {
return DataSourceBuilder.create().url("jdbc:hsqldb:mem:second").username("sa").build();
}
@FlywayDataSource
@Bean
DataSource flywayDataSource() {
return DataSourceBuilder.create().url("jdbc:hsqldb:mem:flywaytest").username("sa").build();
}
}
@Configuration(proxyBeanMethods = false)
static class FlywayJavaMigrationsConfiguration {