Good Morining,
We are using flyway with a Java API. flyway version: 6.5.0 Enterprise. database: h2 (version 1.4.197).
We are trying to apply undo operation programmatically setting a number of a version and applying undo until the current version would be equal. For example undoVersion from 03 to 02.
private void undoVersion(String lastVersion, Flyway flyway, int limit) {
MigrationInfoService info = flyway.info();
String currentVersion = info.current()!=null && info.current().getVersion()!=null ?
info.current().getVersion().getVersion() : null;
if (limit > 0 && !lastVersion.equals(currentVersion)) {
flyway.undo();
undoVersion(lastVersion, flyway, limit - 1);
}
}
If we create the flyway instance using dryRunOutput this way the undo operation is not truly executed and therefore the current version never changes. If I remove .dryRunOutput(outputFileName) the undo is performed fine but I can't get the report.
Flyway.configure()
.dataSource(countryConfig.getString("url"), flywayUser, countryConfig.getString("password"))
.licenseKey(FLYWAY_LICENSE)
.schemas(flyWayConfig.getString("schemas"))
.encoding(flyWayConfig.getString("encoding"))
.validateOnMigrate(flyWayConfig.getBoolean("validateOnMigrate"))
.cleanDisabled(flyWayConfig.getBoolean("cleanDisabled"))
.baselineOnMigrate(flyWayConfig.getBoolean("validateOnMigrate"))
.table(flyWayConfig.getString("table"))
.outOfOrder(flyWayConfig.getBoolean("outOfOrder"))
.placeholderReplacement(true)
.locations("filesystem:" + countryConfig.getString("flywayLocation"))
.dryRunOutput(outputFileName)
.load();
Is there a way to apply undo with dryRun in order to get the report with the undo queries applied in SQL ?
Thank you in advance.
Best regards Álvaro Navarro
Dry runs ought to work with
undo
. However, if you intend to undo one migration at a time (the default undo behaviour) that won't work, as the undo-with-dry-run doesn't update the Flyway schema history table and therefore Flyway will always think that the last actually applied migration is the one to be undone.What you can do is use the
target
parameter in order to define which migration you want to undo up to, and use that in conjunction with a single dry run.EDIT: This is now a case on our issue tracker: https://github.com/flyway/flyway/issues/2890