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..6365e655c5 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. @@ -206,6 +206,7 @@ public class FlywayAutoConfiguration { map.from(properties.isOutOfOrder()).to(configuration::outOfOrder); map.from(properties.isSkipDefaultCallbacks()).to(configuration::skipDefaultCallbacks); map.from(properties.isSkipDefaultResolvers()).to(configuration::skipDefaultResolvers); + configureValidateMigrationNaming(configuration, properties.isValidateMigrationNaming()); map.from(properties.isValidateOnMigrate()).to(configuration::validateOnMigrate); // Pro properties map.from(properties.getBatch()).whenNonNull().to(configuration::batch); @@ -220,6 +221,16 @@ public class FlywayAutoConfiguration { map.from(properties.getUndoSqlMigrationPrefix()).whenNonNull().to(configuration::undoSqlMigrationPrefix); } + private void configureValidateMigrationNaming(FluentConfiguration configuration, + boolean validateMigrationNaming) { + try { + configuration.validateMigrationNaming(validateMigrationNaming); + } + catch (NoSuchMethodError ex) { + // Flyway < 6.2 + } + } + private void configureCallbacks(FluentConfiguration configuration, List callbacks) { if (!callbacks.isEmpty()) { configuration.callbacks(callbacks.toArray(new Callback[0])); 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..b1557e1444 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. @@ -230,6 +230,12 @@ public class FlywayProperties { */ private boolean skipDefaultResolvers; + /** + * Whether to validate migrations and callbacks whose scripts do not obey the correct + * naming convention. + */ + private boolean validateMigrationNaming = false; + /** * Whether to automatically call validate when performing a migration. */ @@ -581,6 +587,14 @@ public class FlywayProperties { this.skipDefaultResolvers = skipDefaultResolvers; } + public boolean isValidateMigrationNaming() { + return this.validateMigrationNaming; + } + + public void setValidateMigrationNaming(boolean validateMigrationNaming) { + this.validateMigrationNaming = validateMigrationNaming; + } + public boolean isValidateOnMigrate() { return this.validateOnMigrate; } 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..1c23e3cb53 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. @@ -84,6 +84,7 @@ class FlywayPropertiesTests { assertThat(configuration.isOutOfOrder()).isEqualTo(properties.isOutOfOrder()); assertThat(configuration.isSkipDefaultCallbacks()).isEqualTo(properties.isSkipDefaultCallbacks()); assertThat(configuration.isSkipDefaultResolvers()).isEqualTo(properties.isSkipDefaultResolvers()); + assertThat(configuration.isValidateMigrationNaming()).isEqualTo(properties.isValidateMigrationNaming()); assertThat(configuration.isValidateOnMigrate()).isEqualTo(properties.isValidateOnMigrate()); } 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"