From 40351c40ed3d2f5ad1addcb1059a6cc21f805566 Mon Sep 17 00:00:00 2001 From: Vedran Pavic Date: Tue, 27 Oct 2015 20:15:29 +0100 Subject: [PATCH 1/2] Fix binding of Flyway's baselineVersion property See gh-4317 --- .../flyway/FlywayAutoConfiguration.java | 22 +++++++++++++++++++ .../flyway/FlywayAutoConfigurationTests.java | 12 ++++++++++ 2 files changed, 34 insertions(+) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java index 713faadb690..1f55bca728e 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java @@ -21,6 +21,7 @@ import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; import org.flywaydb.core.Flyway; +import org.flywaydb.core.api.MigrationVersion; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -33,9 +34,11 @@ import org.springframework.boot.autoconfigure.data.jpa.EntityManagerFactoryDepen import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.ConfigurationPropertiesBinding; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.convert.converter.Converter; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.ResourceLoader; import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean; @@ -47,6 +50,7 @@ import org.springframework.util.Assert; * * @author Dave Syer * @author Phillip Webb + * @author Vedran Pavic * @since 1.1.0 */ @Configuration @@ -57,6 +61,12 @@ import org.springframework.util.Assert; HibernateJpaAutoConfiguration.class }) public class FlywayAutoConfiguration { + @Bean + @ConfigurationPropertiesBinding + public StringToMigrationVersionConverter stringToMigrationVersionConverter() { + return new StringToMigrationVersionConverter(); + } + @Configuration @ConditionalOnMissingBean(Flyway.class) @EnableConfigurationProperties(FlywayProperties.class) @@ -158,4 +168,16 @@ public class FlywayAutoConfiguration { } + /** + * Converts a String to a {@link MigrationVersion}. + */ + private static class StringToMigrationVersionConverter implements Converter { + + @Override + public MigrationVersion convert(String source) { + return MigrationVersion.fromVersion(source); + } + + } + } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java index 0ef150342fe..8e0c4306b0b 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java @@ -23,6 +23,7 @@ import java.util.Map; import javax.sql.DataSource; import org.flywaydb.core.Flyway; +import org.flywaydb.core.api.MigrationVersion; import org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform; import org.junit.After; import org.junit.Before; @@ -56,6 +57,7 @@ import static org.junit.Assert.assertThat; * @author Dave Syer * @author Phillip Webb * @author Andy Wilkinson + * @author Vedran Pavic */ public class FlywayAutoConfigurationTests { @@ -195,6 +197,16 @@ public class FlywayAutoConfigurationTests { PropertyPlaceholderAutoConfiguration.class); } + @Test + public void overrideBaselineVersion() throws Exception { + EnvironmentTestUtils.addEnvironment(this.context, "flyway.baseline-version=0"); + registerAndRefresh(EmbeddedDataSourceConfiguration.class, + FlywayAutoConfiguration.class, + PropertyPlaceholderAutoConfiguration.class); + Flyway flyway = this.context.getBean(Flyway.class); + assertThat(flyway.getBaselineVersion(), equalTo(MigrationVersion.fromVersion("0"))); + } + private void registerAndRefresh(Class... annotatedClasses) { this.context.register(annotatedClasses); this.context.refresh(); From 90a4d1df2b672a4106d3e05e610148f82787f9b2 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 28 Oct 2015 18:11:00 +0100 Subject: [PATCH 2/2] Polish contribution Closes gh-4317 --- .../boot/autoconfigure/flyway/FlywayAutoConfiguration.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java index 1f55bca728e..ba248e1c26f 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java @@ -169,9 +169,10 @@ public class FlywayAutoConfiguration { } /** - * Converts a String to a {@link MigrationVersion}. + * Convert a String to a {@link MigrationVersion}. */ - private static class StringToMigrationVersionConverter implements Converter { + private static class StringToMigrationVersionConverter + implements Converter { @Override public MigrationVersion convert(String source) {