From 1eac4d60463892fb8c8fb0514db8379584ecb880 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 18 Jan 2019 12:44:08 -0500 Subject: [PATCH] Support configuration of Flyway's Pro properties Closes gh-14989 --- .../flyway/FlywayAutoConfiguration.java | 13 +++ .../flyway/FlywayProperties.java | 99 ++++++++++++++++++- .../flyway/FlywayAutoConfigurationTests.java | 90 +++++++++++++++++ .../flyway/FlywayPropertiesTests.java | 11 +-- 4 files changed, 206 insertions(+), 7 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java index 30aec63961..917c7ff82a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java @@ -221,6 +221,19 @@ public class FlywayAutoConfiguration { .to(configuration::skipDefaultResolvers); map.from(properties.isValidateOnMigrate()) .to(configuration::validateOnMigrate); + // Pro properties + map.from(properties.getBatch()).whenNonNull().to(configuration::batch); + map.from(properties.getDryRunOutput()).whenNonNull() + .to(configuration::dryRunOutput); + map.from(properties.getErrorOverrides()).whenNonNull() + .to(configuration::errorOverrides); + map.from(properties.getLicenseKey()).whenNonNull() + .to(configuration::licenseKey); + map.from(properties.getOracleSqlplus()).whenNonNull() + .to(configuration::oracleSqlplus); + map.from(properties.getStream()).whenNonNull().to(configuration::stream); + map.from(properties.getUndoSqlMigrationPrefix()).whenNonNull() + .to(configuration::undoSqlMigrationPrefix); } private void configureCallbacks(FluentConfiguration configuration, diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayProperties.java index 8e9f484455..74bc4d9593 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * 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. @@ -16,6 +16,7 @@ package org.springframework.boot.autoconfigure.flyway; +import java.io.File; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -224,6 +225,46 @@ public class FlywayProperties { */ private boolean validateOnMigrate = true; + /** + * Whether to batch SQL statements when executing them. Requires Flyway Pro or Flyway + * Enterprise. + */ + private Boolean batch = null; + + /** + * File to which the SQL statements of a migration dry run should be output. Requires + * Flyway Pro or Flyway Enterprise. + */ + private File dryRunOutput = null; + + /** + * Rules for the built-in error handling to override specific SQL states and error + * codes. Requires Flyway Pro or Flyway Enterprise. + */ + private String[] errorOverrides; + + /** + * Licence key for Flyway Pro or Flyway Enterprise. + */ + private String licenseKey; + + /** + * Whether to enable support for Oracle SQL*Plus commands. Requires Flyway Pro or + * Flyway Enterprise. + */ + private Boolean oracleSqlplus = null; + + /** + * Whether to stream SQL migrarions when executing them. Requires Flyway Pro or Flyway + * Enterprise. + */ + private Boolean stream = null; + + /** + * File name prefix for undo SQL migrations. Requires Flyway Pro or Flyway Enterprise. + */ + private String undoSqlMigrationPrefix = null; + public boolean isEnabled() { return this.enabled; } @@ -516,4 +557,60 @@ public class FlywayProperties { this.validateOnMigrate = validateOnMigrate; } + public Boolean getBatch() { + return this.batch; + } + + public void setBatch(Boolean batch) { + this.batch = batch; + } + + public File getDryRunOutput() { + return this.dryRunOutput; + } + + public void setDryRunOutput(File dryRunOutput) { + this.dryRunOutput = dryRunOutput; + } + + public String[] getErrorOverrides() { + return this.errorOverrides; + } + + public void setErrorOverrides(String[] errorOverrides) { + this.errorOverrides = errorOverrides; + } + + public String getLicenseKey() { + return this.licenseKey; + } + + public void setLicenseKey(String licenseKey) { + this.licenseKey = licenseKey; + } + + public Boolean getOracleSqlplus() { + return this.oracleSqlplus; + } + + public void setOracleSqlplus(Boolean oracleSqlplus) { + this.oracleSqlplus = oracleSqlplus; + } + + public Boolean getStream() { + return this.stream; + } + + public void setStream(Boolean stream) { + this.stream = stream; + } + + public String getUndoSqlMigrationPrefix() { + return this.undoSqlMigrationPrefix; + } + + public void setUndoSqlMigrationPrefix(String undoSqlMigrationPrefix) { + this.undoSqlMigrationPrefix = undoSqlMigrationPrefix; + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java index cd0bf14afe..036ca2b998 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java @@ -31,6 +31,7 @@ import org.flywaydb.core.api.callback.Callback; import org.flywaydb.core.api.callback.Context; import org.flywaydb.core.api.callback.Event; import org.flywaydb.core.api.callback.FlywayCallback; +import org.flywaydb.core.internal.license.FlywayProUpgradeRequiredException; import org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform; import org.junit.Test; import org.mockito.InOrder; @@ -380,6 +381,95 @@ public class FlywayAutoConfigurationTests { }); } + @Test + public void batchIsCorrectlyMapped() { + this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) + .withPropertyValues("spring.flyway.batch=true").run((context) -> { + assertThat(context).hasFailed(); + Throwable failure = context.getStartupFailure(); + assertThat(failure).hasRootCauseInstanceOf( + FlywayProUpgradeRequiredException.class); + assertThat(failure).hasMessageContaining(" batch "); + }); + } + + @Test + public void dryRunOutputIsCorrectlyMapped() { + this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) + .withPropertyValues("spring.flyway.dryRunOutput=dryrun.sql") + .run((context) -> { + assertThat(context).hasFailed(); + Throwable failure = context.getStartupFailure(); + assertThat(failure).hasRootCauseInstanceOf( + FlywayProUpgradeRequiredException.class); + assertThat(failure).hasMessageContaining(" dryRunOutput "); + }); + } + + @Test + public void errorOverridesIsCorrectlyMapped() { + this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) + .withPropertyValues("spring.flyway.errorOverrides=D12345") + .run((context) -> { + assertThat(context).hasFailed(); + Throwable failure = context.getStartupFailure(); + assertThat(failure).hasRootCauseInstanceOf( + FlywayProUpgradeRequiredException.class); + assertThat(failure).hasMessageContaining(" errorOverrides "); + }); + } + + @Test + public void licenseKeyIsCorrectlyMapped() { + this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) + .withPropertyValues("spring.flyway.license-key=<>") + .run((context) -> { + assertThat(context).hasFailed(); + Throwable failure = context.getStartupFailure(); + assertThat(failure).hasRootCauseInstanceOf( + FlywayProUpgradeRequiredException.class); + assertThat(failure).hasMessageContaining(" licenseKey "); + }); + } + + @Test + public void oracleSqlplusIsCorrectlyMapped() { + this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) + .withPropertyValues("spring.flyway.oracle-sqlplus=true") + .run((context) -> { + assertThat(context).hasFailed(); + Throwable failure = context.getStartupFailure(); + assertThat(failure).hasRootCauseInstanceOf( + FlywayProUpgradeRequiredException.class); + assertThat(failure).hasMessageContaining(" oracle.sqlplus "); + }); + } + + @Test + public void streamIsCorrectlyMapped() { + this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) + .withPropertyValues("spring.flyway.stream=true").run((context) -> { + assertThat(context).hasFailed(); + Throwable failure = context.getStartupFailure(); + assertThat(failure).hasRootCauseInstanceOf( + FlywayProUpgradeRequiredException.class); + assertThat(failure).hasMessageContaining(" stream "); + }); + } + + @Test + public void undoSqlMigrationPrefix() { + this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) + .withPropertyValues("spring.flyway.undo-sql-migration-prefix=undo") + .run((context) -> { + assertThat(context).hasFailed(); + Throwable failure = context.getStartupFailure(); + assertThat(failure).hasRootCauseInstanceOf( + FlywayProUpgradeRequiredException.class); + assertThat(failure).hasMessageContaining(" undoSqlMigrationPrefix "); + }); + } + @Configuration(proxyBeanMethods = false) protected static class FlywayDataSourceConfiguration { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayPropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayPropertiesTests.java index f58d912a9e..99260a1f86 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayPropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * 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. @@ -127,11 +127,10 @@ public class FlywayPropertiesTests { // Handled as initSql array ignoreProperties(configuration, "initSql"); ignoreProperties(properties, "initSqls"); - // Pro version only - ignoreProperties(configuration, "batch", "dryRunOutput", "dryRunOutputAsFile", - "dryRunOutputAsFileName", "errorHandlers", "errorHandlersAsClassNames", - "errorOverrides", "licenseKey", "oracleSqlplus", "stream", - "undoSqlMigrationPrefix"); + // Handled as dryRunOutput + ignoreProperties(configuration, "dryRunOutputAsFile", "dryRunOutputAsFileName"); + // Deprecated + ignoreProperties(configuration, "errorHandlers", "errorHandlersAsClassNames"); List configurationKeys = new ArrayList<>(configuration.keySet()); Collections.sort(configurationKeys); List propertiesKeys = new ArrayList<>(properties.keySet());