From 7865233b167ba97b8398cd5fd2e40893fdff3fed Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 24 Jul 2018 10:31:53 +0200 Subject: [PATCH] Fix Flyway filesystem prefix location check Co-authored-by: Andy Bell Closes gh-13863 --- .../flyway/FlywayAutoConfiguration.java | 6 +++++- .../flyway/FlywayAutoConfigurationTests.java | 14 ++++++++++++-- spring-boot-docs/src/main/asciidoc/howto.adoc | 14 ++++++++++++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java index b9b7c431816..0b1790732ef 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java @@ -117,13 +117,17 @@ public class FlywayAutoConfiguration { private boolean hasAtLeastOneLocation() { for (String location : this.properties.getLocations()) { - if (this.resourceLoader.getResource(location).exists()) { + if (this.resourceLoader.getResource(normalizePrefix(location)).exists()) { return true; } } return false; } + private String normalizePrefix(String location) { + return location.replace("filesystem:", "file:"); + } + @Bean @ConfigurationProperties(prefix = "flyway") public Flyway flyway() { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java index 7f10d14a20e..8165ec0c671 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -153,7 +153,7 @@ public class FlywayAutoConfigurationTests { @Test public void changeLogDoesNotExist() throws Exception { EnvironmentTestUtils.addEnvironment(this.context, - "flyway.locations:file:no-such-dir"); + "flyway.locations:filesystem:no-such-dir"); this.thrown.expect(BeanCreationException.class); registerAndRefresh(EmbeddedDataSourceConfiguration.class, FlywayAutoConfiguration.class, @@ -192,6 +192,16 @@ public class FlywayAutoConfigurationTests { PropertyPlaceholderAutoConfiguration.class); } + @Test + public void checkLocationsAllExistWithImplicitFilesystemPrefix() { + EnvironmentTestUtils.addEnvironment(this.context, + "flyway.locations:filesystem:src/test/resources/db/migration", + "flyway.check-location:true"); + registerAndRefresh(EmbeddedDataSourceConfiguration.class, + FlywayAutoConfiguration.class, + PropertyPlaceholderAutoConfiguration.class); + } + @Test public void customFlywayMigrationStrategy() throws Exception { registerAndRefresh(EmbeddedDataSourceConfiguration.class, diff --git a/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-docs/src/main/asciidoc/howto.adoc index f23a5cbedd4..4fd50bc1cdc 100644 --- a/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -2246,8 +2246,18 @@ To automatically run Flyway database migrations on startup, add the The migrations are scripts in the form `V__.sql` (with `` an underscore-separated version, e.g. '`1`' or '`2_1`'). By default they live in a folder -`classpath:db/migration` but you can modify that using `flyway.locations`. You can also -add a special `{vendor}` placeholder to use vendor-specific scripts. Assume the following: +`classpath:db/migration` but you can modify that using `flyway.locations`. This is a +comma-separated list of one or more `classpath:` or `filesystem:` locations. For example, +the following configuration would search for scripts in both the default classpath +location and the `/opt/migration` directory: + +[source,properties,indent=0] +---- + spring.flyway.locations=classpath:db/migration,filesystem:/opt/migration +---- + +You can also add a special `{vendor}` placeholder to use vendor-specific scripts. Assume +the following: [source,properties,indent=0] ----