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 b159652197..49107b629e 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 @@ -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. @@ -218,6 +218,8 @@ public class FlywayAutoConfiguration { .to((oracleSqlplusWarn) -> configuration.oracleSqlplusWarn(oracleSqlplusWarn)); map.from(properties.getStream()).whenNonNull().to(configuration::stream); map.from(properties.getUndoSqlMigrationPrefix()).whenNonNull().to(configuration::undoSqlMigrationPrefix); + // No method reference for compatibility with Flyway version < 6.2 + configureValidateMigrationNaming(configuration, properties.isValidateMigrationNaming()); } private void configureCallbacks(FluentConfiguration configuration, List callbacks) { @@ -243,6 +245,15 @@ public class FlywayAutoConfiguration { } } + private void configureValidateMigrationNaming(FluentConfiguration flyway, boolean isValidateMigrationNaming) { + try { + flyway.validateMigrationNaming(isValidateMigrationNaming); + } + catch (NoSuchMethodError ex) { + // Flyway < v6.2 + } + } + private String getProperty(Supplier property, Supplier defaultValue) { String value = property.get(); return (value != null) ? value : defaultValue.get(); 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 d674320e22..e82c2bb1ed 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 @@ -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. @@ -209,6 +209,12 @@ public class FlywayProperties { */ private boolean ignoreFutureMigrations = true; + /** + * Whether to validate migrations and callbacks whose scripts do not obey the correct + * naming convention. + */ + private boolean validateMigrationNaming = false; + /** * Whether to allow mixing transactional and non-transactional statements within the * same migration. @@ -549,6 +555,14 @@ public class FlywayProperties { this.ignoreFutureMigrations = ignoreFutureMigrations; } + public boolean isValidateMigrationNaming() { + return this.validateMigrationNaming; + } + + public void setValidateMigrationNaming(boolean validateMigrationNaming) { + this.validateMigrationNaming = validateMigrationNaming; + } + public boolean isMixed() { return this.mixed; } 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 0fb2e902bc..894669ea81 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 @@ -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. @@ -80,6 +80,7 @@ class FlywayPropertiesTests { assertThat(configuration.isIgnoreIgnoredMigrations()).isEqualTo(properties.isIgnoreIgnoredMigrations()); assertThat(configuration.isIgnorePendingMigrations()).isEqualTo(properties.isIgnorePendingMigrations()); assertThat(configuration.isIgnoreFutureMigrations()).isEqualTo(properties.isIgnoreFutureMigrations()); + assertThat(configuration.isValidateMigrationNaming()).isEqualTo(properties.isValidateMigrationNaming()); assertThat(configuration.isMixed()).isEqualTo(properties.isMixed()); assertThat(configuration.isOutOfOrder()).isEqualTo(properties.isOutOfOrder()); assertThat(configuration.isSkipDefaultCallbacks()).isEqualTo(properties.isSkipDefaultCallbacks()); diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index bf4f8c3fd2..f61c364d13 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -335,7 +335,7 @@ bom { ] } } - library("Flyway", "6.1.3") { + library("Flyway", "6.2.0") { group("org.flywaydb") { modules = [ "flyway-core"