Skip to content

Commit b9b21cf

Browse files
treclouxtomix26
authored andcommitted
#122 Support Flyway 7.0 and 7.1
1 parent c5be9f9 commit b9b21cf

File tree

5 files changed

+112
-11
lines changed

5 files changed

+112
-11
lines changed

build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ext {
2323
[core: '4.0.3', test: '5.0.0'],
2424
[core: '4.1.2', test: '5.0.0'],
2525
[core: '4.2.0', test: '5.0.0'],
26-
26+
2727
[core: '5.1.4', test: '5.1.0'],
2828
[core: '5.2.4', test: '5.2.4'],
2929
[core: '6.0.2', test: '6.0.0'],
@@ -34,6 +34,8 @@ ext {
3434
[core: '6.3.3', test: '6.3.3'],
3535
[core: '6.4.4', test: '6.4.0'],
3636
[core: '6.5.3', test: '6.4.0'],
37+
[core: '7.0.4', test: '7.0.0'],
38+
[core: '7.1.1', test: '7.0.0'],
3739

3840
[core: '5.0.7', test: '5.0.0'] // default version
3941
]

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.zonky.test.db.provider.DatabaseDescriptor;
2020
import io.zonky.test.db.provider.DatabasePreparer;
2121
import io.zonky.test.db.provider.GenericDatabaseProvider;
22+
import io.zonky.test.db.util.ReflectionUtils;
2223
import org.apache.commons.lang3.exception.ExceptionUtils;
2324
import org.flywaydb.core.Flyway;
2425
import org.springframework.beans.factory.annotation.Autowired;
@@ -170,7 +171,8 @@ public FlywayDatabasePreparer(Flyway flyway) {
170171
public void prepare(DataSource ds) {
171172
preparerDataSourceHolder.set(ds);
172173
try {
173-
flyway.migrate();
174+
// Return type changed in v7, breaking static call
175+
ReflectionUtils.invokeMethod(flyway, "migrate");
174176
} finally {
175177
preparerDataSourceHolder.remove();
176178
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ public class FlywayClassUtils {
4646
try {
4747
if (flywayVersion >= 60) {
4848
Object flywayConfig = invokeStaticMethod(Flyway.class, "configure");
49-
invokeMethod(flywayConfig, "getUndoSqlMigrationPrefix");
49+
invokeMethod(flywayConfig, "undoSqlMigrationPrefix", "U");
5050
} else if (flywayVersion >= 51) {
5151
Object flywayConfig = getField(new Flyway(), "configuration");
52-
invokeMethod(flywayConfig, "getUndoSqlMigrationPrefix");
52+
invokeMethod(flywayConfig, "setUndoSqlMigrationPrefix", "U");
5353
} else {
54-
new Flyway().getUndoSqlMigrationPrefix();
54+
new Flyway().setUndoSqlMigrationPrefix("U");
5555
}
5656
isCommercial = true;
5757
} catch (FlywayException e) {

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

Lines changed: 93 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public class FlywayConfigSnapshot {
4848
private final List<Class<?>> javaMigrations;
4949
private final List<String> errorOverrides;
5050
private final Map<String, String> placeholders;
51+
private final Map<String, String> jdbcProperties;
52+
private final List<Object> cherryPick;
5153
private final String table;
5254
private final String tablespace;
5355
private final String defaultSchemaName;
@@ -61,8 +63,12 @@ public class FlywayConfigSnapshot {
6163
private final Object encoding;
6264
private final String initSql;
6365
private final String licenseKey;
66+
private final String url;
67+
private final String user;
68+
private final String password;
6469
private final boolean skipDefaultResolvers;
6570
private final boolean skipDefaultCallbacks;
71+
private final boolean skipExecutingMigrations;
6672
private final boolean placeholderReplacement;
6773
private final boolean baselineOnMigrate;
6874
private final boolean outOfOrder;
@@ -84,8 +90,11 @@ public class FlywayConfigSnapshot {
8490
private final boolean batch;
8591
private final boolean oracleSqlPlus;
8692
private final boolean oracleSqlplusWarn;
93+
private final String oracleKerberosConfigFile;
94+
private final String oracleKerberosCacheFile;
8795
private final boolean outputQueryResults;
8896
private final int connectRetries;
97+
private final int lockRetryCount;
8998

9099
public FlywayConfigSnapshot(Flyway flyway) {
91100
final Object config;
@@ -259,6 +268,36 @@ public FlywayConfigSnapshot(Flyway flyway) {
259268
this.javaMigrationClassProvider = null;
260269
this.createSchemas = true;
261270
}
271+
272+
if (flywayVersion >= 70) {
273+
this.url = getValue(config, "getUrl");
274+
this.user = getValue(config, "getUser");
275+
this.password = getValue(config, "getPassword");
276+
} else {
277+
this.url = null;
278+
this.user = null;
279+
this.password = null;
280+
}
281+
282+
if (flywayVersion >= 70 && isFlywayPro) {
283+
this.jdbcProperties = ImmutableMap.copyOf(getMap(config, "getJdbcProperties"));
284+
this.cherryPick = ImmutableList.copyOf(getArray(config, "getCherryPick"));
285+
this.skipExecutingMigrations = getValue(config, "isSkipExecutingMigrations");
286+
this.oracleKerberosConfigFile = getValue(config, "getOracleKerberosConfigFile");
287+
this.oracleKerberosCacheFile = getValue(config, "getOracleKerberosCacheFile");
288+
} else {
289+
this.jdbcProperties = ImmutableMap.of();;
290+
this.cherryPick = ImmutableList.of();;
291+
this.skipExecutingMigrations = false;
292+
this.oracleKerberosConfigFile = "";
293+
this.oracleKerberosCacheFile = "";
294+
}
295+
296+
if (flywayVersion >= 71) {
297+
this.lockRetryCount = getValue(config, "getLockRetryCount");
298+
} else {
299+
this.lockRetryCount = 50;
300+
}
262301
}
263302

264303
private static <T> T getValue(Object target, String method) {
@@ -313,6 +352,10 @@ public boolean isSkipDefaultCallbacks() {
313352
return skipDefaultCallbacks;
314353
}
315354

355+
public boolean isSkipExecutingMigrations() {
356+
return skipExecutingMigrations;
357+
}
358+
316359
public List<String> getSqlMigrationSuffixes() {
317360
return sqlMigrationSuffixes;
318361
}
@@ -353,6 +396,14 @@ public Map<String, String> getPlaceholders() {
353396
return placeholders;
354397
}
355398

399+
public Map<String, String> getJdbcProperties() {
400+
return jdbcProperties;
401+
}
402+
403+
public List<Object> getCherryPick() {
404+
return cherryPick;
405+
}
406+
356407
public MigrationVersion getTarget() {
357408
return target;
358409
}
@@ -385,6 +436,18 @@ public String getLicenseKey() {
385436
return licenseKey;
386437
}
387438

439+
public String getUrl() {
440+
return url;
441+
}
442+
443+
public String getUser() {
444+
return user;
445+
}
446+
447+
public String getPassword() {
448+
return password;
449+
}
450+
388451
public List<Object> getLocations() {
389452
return locations;
390453
}
@@ -477,6 +540,14 @@ public boolean isOracleSqlplusWarn() {
477540
return oracleSqlplusWarn;
478541
}
479542

543+
public String getOracleKerberosConfigFile() {
544+
return oracleKerberosConfigFile;
545+
}
546+
547+
public String getOracleKerberosCacheFile() {
548+
return oracleKerberosCacheFile;
549+
}
550+
480551
public boolean isOutputQueryResults() {
481552
return outputQueryResults;
482553
}
@@ -485,13 +556,18 @@ public int getConnectRetries() {
485556
return connectRetries;
486557
}
487558

559+
public int getLockRetryCount() {
560+
return lockRetryCount;
561+
}
562+
488563
@Override
489564
public boolean equals(Object o) {
490565
if (this == o) return true;
491566
if (o == null || getClass() != o.getClass()) return false;
492567
FlywayConfigSnapshot that = (FlywayConfigSnapshot) o;
493568
return skipDefaultResolvers == that.skipDefaultResolvers &&
494569
skipDefaultCallbacks == that.skipDefaultCallbacks &&
570+
skipExecutingMigrations == that.skipExecutingMigrations &&
495571
placeholderReplacement == that.placeholderReplacement &&
496572
baselineOnMigrate == that.baselineOnMigrate &&
497573
outOfOrder == that.outOfOrder &&
@@ -514,6 +590,7 @@ public boolean equals(Object o) {
514590
oracleSqlplusWarn == that.oracleSqlplusWarn &&
515591
outputQueryResults == that.outputQueryResults &&
516592
connectRetries == that.connectRetries &&
593+
lockRetryCount == that.lockRetryCount &&
517594
Objects.equals(resolvers, that.resolvers) &&
518595
Objects.equals(errorHandlers, that.errorHandlers) &&
519596
Objects.equals(resourceProvider, that.resourceProvider) &&
@@ -526,6 +603,8 @@ public boolean equals(Object o) {
526603
Objects.equals(javaMigrations, that.javaMigrations) &&
527604
Objects.equals(errorOverrides, that.errorOverrides) &&
528605
Objects.equals(placeholders, that.placeholders) &&
606+
Objects.equals(jdbcProperties, that.jdbcProperties) &&
607+
Objects.equals(cherryPick, that.cherryPick) &&
529608
Objects.equals(table, that.table) &&
530609
Objects.equals(tablespace, that.tablespace) &&
531610
Objects.equals(defaultSchemaName, that.defaultSchemaName) &&
@@ -539,23 +618,31 @@ public boolean equals(Object o) {
539618
Objects.equals(encoding, that.encoding) &&
540619
Objects.equals(initSql, that.initSql) &&
541620
Objects.equals(licenseKey, that.licenseKey) &&
542-
Objects.equals(installedBy, that.installedBy);
621+
Objects.equals(installedBy, that.installedBy) &&
622+
Objects.equals(url, that.url) &&
623+
Objects.equals(user, that.user) &&
624+
Objects.equals(password, that.password) &&
625+
Objects.equals(oracleKerberosConfigFile, that.oracleKerberosConfigFile) &&
626+
Objects.equals(oracleKerberosCacheFile, that.oracleKerberosCacheFile);
543627
}
544628

545629
@Override
546630
public int hashCode() {
547631
return Objects.hash(
548632
resolvers, errorHandlers, resourceProvider, javaMigrationClassProvider,
549633
baselineVersion, target, locations, schemas, sqlMigrationSuffixes,
550-
javaMigrations, errorOverrides, placeholders, table, tablespace, defaultSchemaName,
634+
javaMigrations, errorOverrides, placeholders, jdbcProperties, cherryPick,
635+
table, tablespace, defaultSchemaName,
551636
baselineDescription, undoSqlMigrationPrefix, repeatableSqlMigrationPrefix,
552637
sqlMigrationSeparator, sqlMigrationPrefix, placeholderPrefix,
553-
placeholderSuffix, encoding, initSql, licenseKey,
554-
skipDefaultResolvers, skipDefaultCallbacks, placeholderReplacement, baselineOnMigrate,
555-
outOfOrder, ignoreMissingMigrations, ignoreIgnoredMigrations, ignorePendingMigrations,
638+
placeholderSuffix, encoding, initSql, licenseKey, url, user, password,
639+
skipDefaultResolvers, skipDefaultCallbacks, skipExecutingMigrations,
640+
placeholderReplacement, baselineOnMigrate, outOfOrder,
641+
ignoreMissingMigrations, ignoreIgnoredMigrations, ignorePendingMigrations,
556642
ignoreFutureMigrations, validateMigrationNaming, validateOnMigrate,
557643
cleanOnValidationError, cleanDisabled, allowMixedMigrations, createSchemas,
558644
mixed, group, installedBy, dryRun, stream, batch,
559-
oracleSqlPlus, oracleSqlplusWarn, outputQueryResults, connectRetries);
645+
oracleSqlPlus, oracleSqlplusWarn, oracleKerberosConfigFile, oracleKerberosCacheFile,
646+
outputQueryResults, connectRetries, lockRetryCount);
560647
}
561648
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,16 @@ protected static MigrationResolver createMigrationResolver(Flyway flyway, String
286286
protected static Object createScanner(Flyway flyway) throws ClassNotFoundException {
287287
Object configuration = getField(flyway, "configuration");
288288

289+
if (flywayVersion >= 70) {
290+
return invokeConstructor("org.flywaydb.core.internal.scanner.Scanner",
291+
ClassUtils.forName("org.flywaydb.core.api.migration.JavaMigration", classLoader),
292+
Arrays.asList((Object[]) invokeMethod(configuration, "getLocations")),
293+
invokeMethod(configuration, "getClassLoader"),
294+
invokeMethod(configuration, "getEncoding"),
295+
false,
296+
getField(flyway, "resourceNameCache"),
297+
getField(flyway, "locationScannerCache"));
298+
}
289299
if (flywayVersion >= 63) {
290300
try {
291301
// this code is only for version 6.3.3 and above

0 commit comments

Comments
 (0)