Commit 62f696d5 authored by Stephane Nicoll's avatar Stephane Nicoll

Merge pull request #20617 from ta7uw

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

Closes gh-20617
parents 7be3db2d 8f265f8d
/*
* 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());
......
/*
* 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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment