Skip to content

Commit 1eac4d6

Browse files
committed
Support configuration of Flyway's Pro properties
Closes gh-14989
1 parent d3541fa commit 1eac4d6

File tree

4 files changed

+206
-7
lines changed

4 files changed

+206
-7
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,19 @@ private void configureProperties(FluentConfiguration configuration,
221221
.to(configuration::skipDefaultResolvers);
222222
map.from(properties.isValidateOnMigrate())
223223
.to(configuration::validateOnMigrate);
224+
// Pro properties
225+
map.from(properties.getBatch()).whenNonNull().to(configuration::batch);
226+
map.from(properties.getDryRunOutput()).whenNonNull()
227+
.to(configuration::dryRunOutput);
228+
map.from(properties.getErrorOverrides()).whenNonNull()
229+
.to(configuration::errorOverrides);
230+
map.from(properties.getLicenseKey()).whenNonNull()
231+
.to(configuration::licenseKey);
232+
map.from(properties.getOracleSqlplus()).whenNonNull()
233+
.to(configuration::oracleSqlplus);
234+
map.from(properties.getStream()).whenNonNull().to(configuration::stream);
235+
map.from(properties.getUndoSqlMigrationPrefix()).whenNonNull()
236+
.to(configuration::undoSqlMigrationPrefix);
224237
}
225238

226239
private void configureCallbacks(FluentConfiguration configuration,

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayProperties.java

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.autoconfigure.flyway;
1818

19+
import java.io.File;
1920
import java.nio.charset.Charset;
2021
import java.nio.charset.StandardCharsets;
2122
import java.util.ArrayList;
@@ -224,6 +225,46 @@ public class FlywayProperties {
224225
*/
225226
private boolean validateOnMigrate = true;
226227

228+
/**
229+
* Whether to batch SQL statements when executing them. Requires Flyway Pro or Flyway
230+
* Enterprise.
231+
*/
232+
private Boolean batch = null;
233+
234+
/**
235+
* File to which the SQL statements of a migration dry run should be output. Requires
236+
* Flyway Pro or Flyway Enterprise.
237+
*/
238+
private File dryRunOutput = null;
239+
240+
/**
241+
* Rules for the built-in error handling to override specific SQL states and error
242+
* codes. Requires Flyway Pro or Flyway Enterprise.
243+
*/
244+
private String[] errorOverrides;
245+
246+
/**
247+
* Licence key for Flyway Pro or Flyway Enterprise.
248+
*/
249+
private String licenseKey;
250+
251+
/**
252+
* Whether to enable support for Oracle SQL*Plus commands. Requires Flyway Pro or
253+
* Flyway Enterprise.
254+
*/
255+
private Boolean oracleSqlplus = null;
256+
257+
/**
258+
* Whether to stream SQL migrarions when executing them. Requires Flyway Pro or Flyway
259+
* Enterprise.
260+
*/
261+
private Boolean stream = null;
262+
263+
/**
264+
* File name prefix for undo SQL migrations. Requires Flyway Pro or Flyway Enterprise.
265+
*/
266+
private String undoSqlMigrationPrefix = null;
267+
227268
public boolean isEnabled() {
228269
return this.enabled;
229270
}
@@ -516,4 +557,60 @@ public void setValidateOnMigrate(boolean validateOnMigrate) {
516557
this.validateOnMigrate = validateOnMigrate;
517558
}
518559

560+
public Boolean getBatch() {
561+
return this.batch;
562+
}
563+
564+
public void setBatch(Boolean batch) {
565+
this.batch = batch;
566+
}
567+
568+
public File getDryRunOutput() {
569+
return this.dryRunOutput;
570+
}
571+
572+
public void setDryRunOutput(File dryRunOutput) {
573+
this.dryRunOutput = dryRunOutput;
574+
}
575+
576+
public String[] getErrorOverrides() {
577+
return this.errorOverrides;
578+
}
579+
580+
public void setErrorOverrides(String[] errorOverrides) {
581+
this.errorOverrides = errorOverrides;
582+
}
583+
584+
public String getLicenseKey() {
585+
return this.licenseKey;
586+
}
587+
588+
public void setLicenseKey(String licenseKey) {
589+
this.licenseKey = licenseKey;
590+
}
591+
592+
public Boolean getOracleSqlplus() {
593+
return this.oracleSqlplus;
594+
}
595+
596+
public void setOracleSqlplus(Boolean oracleSqlplus) {
597+
this.oracleSqlplus = oracleSqlplus;
598+
}
599+
600+
public Boolean getStream() {
601+
return this.stream;
602+
}
603+
604+
public void setStream(Boolean stream) {
605+
this.stream = stream;
606+
}
607+
608+
public String getUndoSqlMigrationPrefix() {
609+
return this.undoSqlMigrationPrefix;
610+
}
611+
612+
public void setUndoSqlMigrationPrefix(String undoSqlMigrationPrefix) {
613+
this.undoSqlMigrationPrefix = undoSqlMigrationPrefix;
614+
}
615+
519616
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.flywaydb.core.api.callback.Context;
3232
import org.flywaydb.core.api.callback.Event;
3333
import org.flywaydb.core.api.callback.FlywayCallback;
34+
import org.flywaydb.core.internal.license.FlywayProUpgradeRequiredException;
3435
import org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform;
3536
import org.junit.Test;
3637
import org.mockito.InOrder;
@@ -380,6 +381,95 @@ public void configurationCustomizersAreConfiguredAndOrdered() {
380381
});
381382
}
382383

384+
@Test
385+
public void batchIsCorrectlyMapped() {
386+
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
387+
.withPropertyValues("spring.flyway.batch=true").run((context) -> {
388+
assertThat(context).hasFailed();
389+
Throwable failure = context.getStartupFailure();
390+
assertThat(failure).hasRootCauseInstanceOf(
391+
FlywayProUpgradeRequiredException.class);
392+
assertThat(failure).hasMessageContaining(" batch ");
393+
});
394+
}
395+
396+
@Test
397+
public void dryRunOutputIsCorrectlyMapped() {
398+
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
399+
.withPropertyValues("spring.flyway.dryRunOutput=dryrun.sql")
400+
.run((context) -> {
401+
assertThat(context).hasFailed();
402+
Throwable failure = context.getStartupFailure();
403+
assertThat(failure).hasRootCauseInstanceOf(
404+
FlywayProUpgradeRequiredException.class);
405+
assertThat(failure).hasMessageContaining(" dryRunOutput ");
406+
});
407+
}
408+
409+
@Test
410+
public void errorOverridesIsCorrectlyMapped() {
411+
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
412+
.withPropertyValues("spring.flyway.errorOverrides=D12345")
413+
.run((context) -> {
414+
assertThat(context).hasFailed();
415+
Throwable failure = context.getStartupFailure();
416+
assertThat(failure).hasRootCauseInstanceOf(
417+
FlywayProUpgradeRequiredException.class);
418+
assertThat(failure).hasMessageContaining(" errorOverrides ");
419+
});
420+
}
421+
422+
@Test
423+
public void licenseKeyIsCorrectlyMapped() {
424+
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
425+
.withPropertyValues("spring.flyway.license-key=<<secret>>")
426+
.run((context) -> {
427+
assertThat(context).hasFailed();
428+
Throwable failure = context.getStartupFailure();
429+
assertThat(failure).hasRootCauseInstanceOf(
430+
FlywayProUpgradeRequiredException.class);
431+
assertThat(failure).hasMessageContaining(" licenseKey ");
432+
});
433+
}
434+
435+
@Test
436+
public void oracleSqlplusIsCorrectlyMapped() {
437+
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
438+
.withPropertyValues("spring.flyway.oracle-sqlplus=true")
439+
.run((context) -> {
440+
assertThat(context).hasFailed();
441+
Throwable failure = context.getStartupFailure();
442+
assertThat(failure).hasRootCauseInstanceOf(
443+
FlywayProUpgradeRequiredException.class);
444+
assertThat(failure).hasMessageContaining(" oracle.sqlplus ");
445+
});
446+
}
447+
448+
@Test
449+
public void streamIsCorrectlyMapped() {
450+
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
451+
.withPropertyValues("spring.flyway.stream=true").run((context) -> {
452+
assertThat(context).hasFailed();
453+
Throwable failure = context.getStartupFailure();
454+
assertThat(failure).hasRootCauseInstanceOf(
455+
FlywayProUpgradeRequiredException.class);
456+
assertThat(failure).hasMessageContaining(" stream ");
457+
});
458+
}
459+
460+
@Test
461+
public void undoSqlMigrationPrefix() {
462+
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
463+
.withPropertyValues("spring.flyway.undo-sql-migration-prefix=undo")
464+
.run((context) -> {
465+
assertThat(context).hasFailed();
466+
Throwable failure = context.getStartupFailure();
467+
assertThat(failure).hasRootCauseInstanceOf(
468+
FlywayProUpgradeRequiredException.class);
469+
assertThat(failure).hasMessageContaining(" undoSqlMigrationPrefix ");
470+
});
471+
}
472+
383473
@Configuration(proxyBeanMethods = false)
384474
protected static class FlywayDataSourceConfiguration {
385475

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayPropertiesTests.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -127,11 +127,10 @@ public void expectedPropertiesAreManaged() {
127127
// Handled as initSql array
128128
ignoreProperties(configuration, "initSql");
129129
ignoreProperties(properties, "initSqls");
130-
// Pro version only
131-
ignoreProperties(configuration, "batch", "dryRunOutput", "dryRunOutputAsFile",
132-
"dryRunOutputAsFileName", "errorHandlers", "errorHandlersAsClassNames",
133-
"errorOverrides", "licenseKey", "oracleSqlplus", "stream",
134-
"undoSqlMigrationPrefix");
130+
// Handled as dryRunOutput
131+
ignoreProperties(configuration, "dryRunOutputAsFile", "dryRunOutputAsFileName");
132+
// Deprecated
133+
ignoreProperties(configuration, "errorHandlers", "errorHandlersAsClassNames");
135134
List<String> configurationKeys = new ArrayList<>(configuration.keySet());
136135
Collections.sort(configurationKeys);
137136
List<String> propertiesKeys = new ArrayList<>(properties.keySet());

0 commit comments

Comments
 (0)