From 5920b27b57f56c33d9dbf53553252d58a64e2acb Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 24 Jun 2024 14:08:39 +0100 Subject: [PATCH] Upgrade to Flyway 10.15.0 Closes gh-41217 --- .../flyway/FlywayAutoConfiguration.java | 2 + .../flyway/FlywayProperties.java | 13 +++++ ...itional-spring-configuration-metadata.json | 3 ++ .../Flyway100AutoConfigurationTests.java | 54 +++++++++++++++++++ .../flyway/FlywayPropertiesTests.java | 8 +++ .../spring-boot-dependencies/build.gradle | 2 +- 6 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/Flyway100AutoConfigurationTests.java diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java index dbc566977da..36a73262410 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java @@ -302,6 +302,8 @@ public class FlywayAutoConfiguration { .to((suffix) -> configuration.scriptPlaceholderSuffix(suffix)); configureExecuteInTransaction(configuration, properties, map); map.from(properties::getLoggers).to((loggers) -> configuration.loggers(loggers)); + map.from(properties::getCommunityDbSupportEnabled) + .to((communityDbSupportEnabled) -> configuration.communityDBSupportEnabled(communityDbSupportEnabled)); // Flyway Teams properties map.from(properties.getBatch()).to((batch) -> configuration.batch(batch)); map.from(properties.getDryRunOutput()).to((dryRunOutput) -> configuration.dryRunOutput(dryRunOutput)); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayProperties.java index b64f6c6dfb9..ad9c25864a6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayProperties.java @@ -330,6 +330,11 @@ public class FlywayProperties { */ private Boolean detectEncoding; + /** + * Whether to enable community database support. + */ + private Boolean communityDbSupportEnabled; + private final Oracle oracle = new Oracle(); private final Postgresql postgresql = new Postgresql(); @@ -823,6 +828,14 @@ public class FlywayProperties { this.detectEncoding = detectEncoding; } + public Boolean getCommunityDbSupportEnabled() { + return this.communityDbSupportEnabled; + } + + public void setCommunityDbSupportEnabled(Boolean communityDbSupportEnabled) { + this.communityDbSupportEnabled = communityDbSupportEnabled; + } + public Oracle getOracle() { return this.oracle; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 08c1e78c146..ac7ab276f80 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -1346,6 +1346,9 @@ "level": "error", "reason": "Removed in Flyway 10" } + },{ + "name": "spring.flyway.community-db-support-enabled", + "defaultValue": false }, { "name": "spring.flyway.dry-run-output", diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/Flyway100AutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/Flyway100AutoConfigurationTests.java new file mode 100644 index 00000000000..047e37c40b9 --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/Flyway100AutoConfigurationTests.java @@ -0,0 +1,54 @@ +/* + * Copyright 2012-2024 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.flyway; + +import org.flywaydb.core.Flyway; +import org.flywaydb.core.api.Location; +import org.junit.jupiter.api.Test; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.ClassPathExclusions; +import org.springframework.boot.testsupport.classpath.ClassPathOverrides; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link FlywayAutoConfiguration} with Flyway 10.0. + * + * @author Andy Wilkinson + */ +@ClassPathExclusions({ "flyway-core-*.jar", "flyway-sqlserver-*.jar" }) +@ClassPathOverrides({ "org.flywaydb:flyway-core:10.0.0", "com.h2database:h2:2.1.210" }) +class Flyway100AutoConfigurationTests { + + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(FlywayAutoConfiguration.class)) + .withPropertyValues("spring.datasource.generate-unique-name=true"); + + @Test + void defaultFlyway() { + this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class).run((context) -> { + assertThat(context).hasSingleBean(Flyway.class); + Flyway flyway = context.getBean(Flyway.class); + assertThat(flyway.getConfiguration().getLocations()) + .containsExactly(new Location("classpath:db/migration")); + }); + } + +} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayPropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayPropertiesTests.java index 8deaf5056a7..5a2c2c7b07f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayPropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayPropertiesTests.java @@ -93,6 +93,7 @@ class FlywayPropertiesTests { assertThat(properties.getScriptPlaceholderPrefix()).isEqualTo(configuration.getScriptPlaceholderPrefix()); assertThat(properties.getScriptPlaceholderSuffix()).isEqualTo(configuration.getScriptPlaceholderSuffix()); assertThat(properties.isExecuteInTransaction()).isEqualTo(configuration.isExecuteInTransaction()); + assertThat(properties.getCommunityDbSupportEnabled()).isNull(); } @Test @@ -140,6 +141,7 @@ class FlywayPropertiesTests { ignoreProperties(configuration, "failOnMissingTarget"); // Properties managed by a proprietary extension ignoreProperties(configuration, "cherryPick"); + aliasProperty(configuration, "communityDBSupportEnabled", "communityDbSupportEnabled"); List configurationKeys = new ArrayList<>(configuration.keySet()); Collections.sort(configurationKeys); List propertiesKeys = new ArrayList<>(properties.keySet()); @@ -154,6 +156,12 @@ class FlywayPropertiesTests { } } + private void aliasProperty(Map index, String originalName, String alias) { + PropertyDescriptor descriptor = index.remove(originalName); + assertThat(descriptor).describedAs("Property to alias should be present " + originalName).isNotNull(); + index.put(alias, descriptor); + } + private Map indexProperties(BeanWrapper beanWrapper) { Map descriptor = new HashMap<>(); for (PropertyDescriptor propertyDescriptor : beanWrapper.getPropertyDescriptors()) { diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index 71959673470..1251a02de30 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -373,7 +373,7 @@ bom { releaseNotes("https://www.elastic.co/guide/en/elasticsearch/reference/current/release-notes-{version}.html") } } - library("Flyway", "10.10.0") { + library("Flyway", "10.15.0") { group("org.flywaydb") { modules = [ "flyway-commandline",