Skip to content

Commit c2e2a24

Browse files
Chanwon-Seodhruv-15-03
authored andcommitted
Allow Flyway's Ignore Migration Patterns setting to be an empty string
See spring-projectsgh-46984 Signed-off-by: Chanwon-Seo <[email protected]>
1 parent e10efde commit c2e2a24

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

module/spring-boot-flyway/src/main/java/org/springframework/boot/flyway/autoconfigure/FlywayAutoConfiguration.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ private void configureProperties(FluentConfiguration configuration, FlywayProper
320320
map.from(properties.getSkipExecutingMigrations())
321321
.to((skipExecutingMigrations) -> configuration.skipExecutingMigrations(skipExecutingMigrations));
322322
map.from(properties.getIgnoreMigrationPatterns())
323-
.whenNot(List::isEmpty)
324323
.to((ignoreMigrationPatterns) -> configuration
325324
.ignoreMigrationPatterns(ignoreMigrationPatterns.toArray(new String[0])));
326325
map.from(properties.getDetectEncoding())

module/spring-boot-flyway/src/main/java/org/springframework/boot/flyway/autoconfigure/FlywayProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public class FlywayProperties {
323323
/**
324324
* List of patterns that identify migrations to ignore when performing validation.
325325
*/
326-
private @Nullable List<String> ignoreMigrationPatterns;
326+
private List<String> ignoreMigrationPatterns = Collections.singletonList("*:future");
327327

328328
/**
329329
* Whether to attempt to automatically detect SQL migration file encoding.

module/spring-boot-flyway/src/test/java/org/springframework/boot/flyway/autoconfigure/FlywayAutoConfigurationTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,21 @@ void ignoreMigrationPatternsCorrectlyMapped() {
897897
.containsExactly(ValidatePattern.fromPattern("*:missing")));
898898
}
899899

900+
@Test
901+
void ignoreMigrationPatternsUsesDefaultValuesWhenNotSet() {
902+
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
903+
.run((context) -> assertThat(context.getBean(Flyway.class).getConfiguration().getIgnoreMigrationPatterns())
904+
.containsExactly(new FluentConfiguration().getIgnoreMigrationPatterns()));
905+
}
906+
907+
@Test
908+
void ignoreMigrationPatternsWhenEmpty() {
909+
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
910+
.withPropertyValues("spring.flyway.ignore-migration-patterns=")
911+
.run((context) -> assertThat(context.getBean(Flyway.class).getConfiguration().getIgnoreMigrationPatterns())
912+
.isEmpty());
913+
}
914+
900915
private ContextConsumer<AssertableApplicationContext> validateFlywayTeamsPropertyOnly(String propertyName) {
901916
return (context) -> {
902917
assertThat(context).hasFailed();

module/spring-boot-flyway/src/test/java/org/springframework/boot/flyway/autoconfigure/FlywayPropertiesTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.flywaydb.core.api.configuration.ClassicConfiguration;
3131
import org.flywaydb.core.api.configuration.Configuration;
3232
import org.flywaydb.core.api.configuration.FluentConfiguration;
33+
import org.flywaydb.core.api.pattern.ValidatePattern;
3334
import org.junit.jupiter.api.Test;
3435

3536
import org.springframework.beans.BeanWrapper;
@@ -95,6 +96,8 @@ void defaultValuesAreConsistent() {
9596
assertThat(properties.getScriptPlaceholderSuffix()).isEqualTo(configuration.getScriptPlaceholderSuffix());
9697
assertThat(properties.isExecuteInTransaction()).isEqualTo(configuration.isExecuteInTransaction());
9798
assertThat(properties.getCommunityDbSupportEnabled()).isNull();
99+
assertThat(properties.getIgnoreMigrationPatterns().stream().map(ValidatePattern::fromPattern))
100+
.containsExactly(configuration.getIgnoreMigrationPatterns());
98101
}
99102

100103
@Test

0 commit comments

Comments
 (0)