mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-05-02 19:30:23 +01:00
Add failure analyzer for Flyway's bootstrap failure
See gh-16015
This commit is contained in:
+5
-3
@@ -168,9 +168,11 @@ public class FlywayAutoConfiguration {
|
||||
Assert.state(locations.length != 0,
|
||||
"Migration script locations not configured");
|
||||
boolean exists = hasAtLeastOneLocation(resourceLoader, locations);
|
||||
Assert.state(exists, () -> "Cannot find migrations location in: "
|
||||
+ Arrays.asList(locations)
|
||||
+ " (please add migrations or check your Flyway configuration)");
|
||||
if (!exists) {
|
||||
throw new FlywayMigrationScriptNotFoundException(
|
||||
"Cannot find migrations in the specified location",
|
||||
Arrays.asList(locations));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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
|
||||
*
|
||||
* http://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.springframework.boot.diagnostics.AbstractFailureAnalyzer;
|
||||
import org.springframework.boot.diagnostics.FailureAnalysis;
|
||||
|
||||
/**
|
||||
* A {@code FailureAnalyzer} that performs analysis of failures caused by a
|
||||
* {@code FlywayMigrationScriptNotFoundException}.
|
||||
*
|
||||
* @author Anand Shastri
|
||||
*/
|
||||
public class FlywayMigrationScriptMissingFailureAnalyzer
|
||||
extends AbstractFailureAnalyzer<FlywayMigrationScriptNotFoundException> {
|
||||
|
||||
@Override
|
||||
protected FailureAnalysis analyze(Throwable rootFailure,
|
||||
FlywayMigrationScriptNotFoundException cause) {
|
||||
return new FailureAnalysis(
|
||||
"Cannot find migrations location in " + cause.getLocations(),
|
||||
" please add migrations or check your Flyway configuration", cause);
|
||||
}
|
||||
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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
|
||||
*
|
||||
* http://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 java.util.List;
|
||||
|
||||
/**
|
||||
* Exception thrown when no {@code flyway migration script} is available.
|
||||
*
|
||||
* @author Anand Shastri
|
||||
*/
|
||||
|
||||
public class FlywayMigrationScriptNotFoundException extends RuntimeException {
|
||||
|
||||
private final List<String> locations;
|
||||
|
||||
public FlywayMigrationScriptNotFoundException(String message,
|
||||
List<String> locations) {
|
||||
super(message);
|
||||
this.locations = locations;
|
||||
}
|
||||
|
||||
public List<String> getLocations() {
|
||||
return this.locations;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -209,7 +209,7 @@ public class FlywayAutoConfigurationTests {
|
||||
assertThat(context).getFailure()
|
||||
.isInstanceOf(BeanCreationException.class);
|
||||
assertThat(context).getFailure()
|
||||
.hasMessageContaining("Cannot find migrations location in");
|
||||
.hasMessageContaining("Cannot find migrations in");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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
|
||||
*
|
||||
* http://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 java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.diagnostics.FailureAnalysis;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link FlywayMigrationScriptMissingFailureAnalyzer}
|
||||
*
|
||||
* @author Anand Shastri
|
||||
*/
|
||||
public class FlywayMigrationScriptMissingFailureAnalyzerTests {
|
||||
|
||||
private final FlywayMigrationScriptMissingFailureAnalyzer analyzer = new FlywayMigrationScriptMissingFailureAnalyzer();
|
||||
|
||||
@Test
|
||||
public void analysisForFlywayScriptMissingFailure() {
|
||||
FailureAnalysis failureAnalysis = this.analyzer
|
||||
.analyze(new FlywayMigrationScriptNotFoundException(
|
||||
"Migration script locations not configured",
|
||||
Collections.singletonList("classpath:db/migration")));
|
||||
|
||||
assertThat(failureAnalysis.getDescription())
|
||||
.endsWith("Cannot find migrations location in [classpath:db/migration]");
|
||||
assertThat(failureAnalysis.getAction())
|
||||
.endsWith(" please add migrations or check your Flyway configuration");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -50,7 +50,8 @@ org.springframework.boot.diagnostics.analyzer.NoUniqueBeanDefinitionFailureAnaly
|
||||
org.springframework.boot.diagnostics.analyzer.PortInUseFailureAnalyzer,\
|
||||
org.springframework.boot.diagnostics.analyzer.ValidationExceptionFailureAnalyzer,\
|
||||
org.springframework.boot.diagnostics.analyzer.InvalidConfigurationPropertyNameFailureAnalyzer,\
|
||||
org.springframework.boot.diagnostics.analyzer.InvalidConfigurationPropertyValueFailureAnalyzer
|
||||
org.springframework.boot.diagnostics.analyzer.InvalidConfigurationPropertyValueFailureAnalyzer,\
|
||||
org.springframework.boot.diagnostics.analyzer.FlywayMigrationScriptMissingFailureAnalyzer
|
||||
|
||||
# FailureAnalysisReporters
|
||||
org.springframework.boot.diagnostics.FailureAnalysisReporter=\
|
||||
|
||||
Reference in New Issue
Block a user