Harmonize enabled flags for flyway and liquibase
This commit is contained in:
parent
2cd7b13096
commit
799f9edb0b
|
|
@ -22,7 +22,9 @@ import javax.sql.DataSource;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
|
|
@ -42,6 +44,8 @@ import com.googlecode.flyway.core.Flyway;
|
|||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(Flyway.class)
|
||||
@ConditionalOnBean(DataSource.class)
|
||||
@ConditionalOnExpression("${flyway.enabled:true}")
|
||||
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
|
||||
public class FlywayAutoConfiguration {
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import java.util.List;
|
|||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* Configuration properties to configure Flyway.
|
||||
* Configuration properties for Flyway database migrations.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
|
|
@ -40,7 +40,9 @@ public class FlywayProperties {
|
|||
|
||||
private String initVersion = "1";
|
||||
|
||||
private boolean checkLocation;
|
||||
private boolean checkLocation = false;
|
||||
|
||||
private boolean enabled = true;
|
||||
|
||||
public String getPrefix() {
|
||||
return this.prefix;
|
||||
|
|
@ -89,4 +91,12 @@ public class FlywayProperties {
|
|||
public boolean isCheckLocation() {
|
||||
return this.checkLocation;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,9 @@ import liquibase.integration.spring.SpringLiquibase;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
|
|
@ -42,6 +44,8 @@ import org.springframework.util.Assert;
|
|||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(SpringLiquibase.class)
|
||||
@ConditionalOnBean(DataSource.class)
|
||||
@ConditionalOnExpression("${liquibase.enabled:true}")
|
||||
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
|
||||
public class LiquibaseAutoConfiguration {
|
||||
|
||||
|
|
@ -62,9 +66,11 @@ public class LiquibaseAutoConfiguration {
|
|||
@PostConstruct
|
||||
public void checkChangelogExists() {
|
||||
if (this.properties.isCheckChangeLogLocation()) {
|
||||
Resource resource = this.resourceLoader.getResource(this.properties.getChangeLog());
|
||||
Resource resource = this.resourceLoader.getResource(this.properties
|
||||
.getChangeLog());
|
||||
Assert.state(resource.exists(), "Cannot find changelog location: "
|
||||
+ resource + " (please add changelog or check your Liquibase configuration)");
|
||||
+ resource
|
||||
+ " (please add changelog or check your Liquibase configuration)");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -73,10 +79,10 @@ public class LiquibaseAutoConfiguration {
|
|||
SpringLiquibase liquibase = new SpringLiquibase();
|
||||
liquibase.setChangeLog(this.properties.getChangeLog());
|
||||
liquibase.setContexts(this.properties.getContexts());
|
||||
liquibase.setDataSource(dataSource);
|
||||
liquibase.setDataSource(this.dataSource);
|
||||
liquibase.setDefaultSchema(this.properties.getDefaultSchema());
|
||||
liquibase.setDropFirst(this.properties.isDropFirst());
|
||||
liquibase.setShouldRun(this.properties.isShouldRun());
|
||||
liquibase.setShouldRun(this.properties.isEnabled());
|
||||
return liquibase;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public class LiquibaseProperties {
|
|||
|
||||
private boolean dropFirst = false;
|
||||
|
||||
private boolean shouldRun = true;
|
||||
private boolean enabled = true;
|
||||
|
||||
public String getChangeLog() {
|
||||
return this.changeLog;
|
||||
|
|
@ -83,11 +83,11 @@ public class LiquibaseProperties {
|
|||
this.dropFirst = dropFirst;
|
||||
}
|
||||
|
||||
public boolean isShouldRun() {
|
||||
return this.shouldRun;
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setShouldRun(boolean shouldRun) {
|
||||
this.shouldRun = shouldRun;
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,12 +16,11 @@
|
|||
|
||||
package org.springframework.boot.autoconfigure;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
import org.springframework.boot.autoconfigure.security.SecurityAutoConfigurationTests;
|
||||
import org.springframework.boot.autoconfigure.web.DefaultErrorViewIntegrationTests;
|
||||
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfigurationTests;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfigurationTests;
|
||||
|
||||
/**
|
||||
* A test suite for probing weird ordering problems in the tests.
|
||||
|
|
@ -29,9 +28,9 @@ import org.springframework.boot.autoconfigure.web.DefaultErrorViewIntegrationTes
|
|||
* @author Dave Syer
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({ DefaultErrorViewIntegrationTests.class,
|
||||
SecurityAutoConfigurationTests.class })
|
||||
@Ignore
|
||||
@SuiteClasses({ HibernateJpaAutoConfigurationTests.class,
|
||||
LiquibaseAutoConfigurationTests.class })
|
||||
// @Ignore
|
||||
public class AdhocTestSuite {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.flyway;
|
|||
import java.util.Arrays;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
|
@ -45,6 +46,12 @@ public class FlywayAutoConfigurationTests {
|
|||
|
||||
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.datasource.name:flywaytest");
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
if (this.context != null) {
|
||||
|
|
@ -56,10 +63,8 @@ public class FlywayAutoConfigurationTests {
|
|||
public void testNoDataSource() throws Exception {
|
||||
this.context.register(FlywayAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.expected.expect(BeanCreationException.class);
|
||||
this.expected.expectMessage("No qualifying bean");
|
||||
this.expected.expectMessage("DataSource");
|
||||
this.context.refresh();
|
||||
assertEquals(0, this.context.getBeanNamesForType(Flyway.class).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.liquibase;
|
|||
import liquibase.integration.spring.SpringLiquibase;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
|
@ -43,7 +44,13 @@ public class LiquibaseAutoConfigurationTests {
|
|||
@Rule
|
||||
public ExpectedException expected = ExpectedException.none();
|
||||
|
||||
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();;
|
||||
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.datasource.name:liquibasetest");
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
|
|
@ -56,10 +63,8 @@ public class LiquibaseAutoConfigurationTests {
|
|||
public void testNoDataSource() throws Exception {
|
||||
this.context.register(LiquibaseAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.expected.expect(BeanCreationException.class);
|
||||
this.expected.expectMessage("No qualifying bean");
|
||||
this.expected.expectMessage("DataSource");
|
||||
this.context.refresh();
|
||||
assertEquals(0, this.context.getBeanNamesForType(SpringLiquibase.class).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ import org.junit.runner.RunWith;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.DefaultErrorViewIntegrationTests.TestConfiguration;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
|
@ -68,7 +70,8 @@ public class DefaultErrorViewIntegrationTests {
|
|||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class,
|
||||
HibernateJpaAutoConfiguration.class })
|
||||
public static class TestConfiguration {
|
||||
|
||||
// For manual testing
|
||||
|
|
|
|||
|
|
@ -159,18 +159,19 @@ content into your application; rather pick only the properties that you need.
|
|||
spring.jpa.hibernate.ddl-auto= # defaults to create-drop for embedded dbs
|
||||
|
||||
# FLYWAY ({sc-spring-boot-autoconfigure}/flyway/FlywayProperties.{sc-ext}[FlywayProperties])
|
||||
flyway.change-log=classpath:/db/changelog/db.changelog-master.yaml
|
||||
flyway.contexts= # runtime contexts to use
|
||||
flyway.default-schema= # default database schema to use
|
||||
flyway.drop-first=false
|
||||
flyway.should-run=true
|
||||
flyway.locations=classpath:db/migrations # locations of migrations scripts
|
||||
flyway.schemas= # schemas to update
|
||||
flyway.initVersion= 1 # version to start migration
|
||||
flyway.prefix=V
|
||||
flyway.suffix=.sql
|
||||
flyway.enabled=true
|
||||
|
||||
# LIQUIBASE ({sc-spring-boot-autoconfigure}/liquibase/LiquibaseProperties.{sc-ext}[LiquibaseProperties])
|
||||
liquibase.change-log=classpath:/db/changelog/db.changelog-master.yaml
|
||||
liquibase.contexts= # runtime contexts to use
|
||||
liquibase.default-schema= # default database schema to use
|
||||
liquibase.drop-first=false
|
||||
liquibase.should-run=true
|
||||
liquibase.enabled=true
|
||||
|
||||
# JMX
|
||||
spring.jmx.enabled=true # Expose MBeans from Spring
|
||||
|
|
|
|||
Loading…
Reference in New Issue