Skip to content

Commit 38e54f0

Browse files
committed
#3 remove the restriction that flyway schema must always be set
1 parent 1333d94 commit 38e54f0

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ The primary goal of this project is to make it easier to write Spring-powered in
44

55
## Features
66

7-
* Integration with Spring TestContext Framework
8-
* Both `Spring` and `Spring Boot` Frameworks are supported
7+
* Integration with Spring TestContext framework
8+
* Context caching is fully supported
9+
* Both `Spring` and `Spring Boot` frameworks are supported
10+
* Supported versions are Spring 4.3.0+ and Spring Boot 1.4.0+
911
* Lightweight bundle of PostgreSQL database with reduced size
1012
* Integration with Flyway database migration tool
1113
* Optimized migration and cleaning of embedded database

embedded-database-spring-test-core/src/main/java/io/zonky/test/db/flyway/DefaultFlywayDataSourceContext.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.google.common.cache.LoadingCache;
2222
import com.opentable.db.postgres.embedded.DatabasePreparer;
2323
import com.opentable.db.postgres.embedded.PreparedDbProvider;
24-
import org.apache.commons.lang3.ArrayUtils;
2524
import org.apache.commons.lang3.exception.ExceptionUtils;
2625
import org.flywaydb.core.Flyway;
2726
import org.postgresql.ds.PGSimpleDataSource;
@@ -159,10 +158,7 @@ public void setBootstrapExecutor(TaskExecutor bootstrapExecutor) {
159158
}
160159

161160
protected FlywayConfigSnapshot createConfigSnapshot(Flyway flyway) {
162-
FlywayConfigSnapshot configSnapshot = new FlywayConfigSnapshot(flyway);
163-
checkState(ArrayUtils.isNotEmpty(configSnapshot.getSchemas()),
164-
"org.flywaydb.core.Flyway#schemaNames must be specified");
165-
return configSnapshot;
161+
return new FlywayConfigSnapshot(flyway);
166162
}
167163

168164
protected class FlywayDatabasePreparer implements DatabasePreparer {

embedded-database-spring-test-core/src/main/java/io/zonky/test/db/flyway/OptimizedFlywayTestExecutionListener.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.common.collect.ObjectArrays;
2121
import org.apache.commons.lang3.ArrayUtils;
2222
import org.flywaydb.core.Flyway;
23+
import org.flywaydb.core.api.FlywayException;
2324
import org.flywaydb.core.api.MigrationVersion;
2425
import org.flywaydb.core.api.resolver.MigrationResolver;
2526
import org.flywaydb.core.api.resolver.ResolvedMigration;
@@ -40,6 +41,7 @@
4041
import java.lang.annotation.Annotation;
4142
import java.lang.reflect.AnnotatedElement;
4243
import java.lang.reflect.Method;
44+
import java.sql.SQLException;
4345
import java.util.Collection;
4446
import java.util.Map;
4547

@@ -145,7 +147,17 @@ protected synchronized void optimizedDbReset(TestContext testContext, FlywayTest
145147
}
146148
}
147149

148-
ReflectionTestUtils.invokeMethod(this, dbResetMethodName, testContext, annotation);
150+
try {
151+
ReflectionTestUtils.invokeMethod(this, dbResetMethodName, testContext, annotation);
152+
} catch (FlywayException e) {
153+
if (e.getCause() instanceof SQLException) {
154+
String errorCode = ((SQLException) e.getCause()).getSQLState();
155+
if (errorCode != null && errorCode.matches("(42723|42P06|42P07|42712|42710)")) {
156+
logger.error("HINT: Check that you have correctly set org.flywaydb.core.Flyway#schemaNames property!!!");
157+
}
158+
}
159+
throw e;
160+
}
149161
}
150162

151163
protected static void prepareDataSourceContext(FlywayDataSourceContext dataSourceContext, Flyway flywayBean, FlywayTest annotation) throws Exception {

0 commit comments

Comments
 (0)