diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java index a393ce3309..004ddc5066 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java @@ -64,6 +64,7 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; * @author Dominic Gunn * @author Dan Zheng * @author András Deák + * @author Ferenc Gratzer * @since 1.1.0 */ @Configuration(proxyBeanMethods = false) @@ -100,6 +101,7 @@ public class LiquibaseAutoConfiguration { SpringLiquibase liquibase = createSpringLiquibase(liquibaseDataSource.getIfAvailable(), dataSource.getIfUnique(), dataSourceProperties); liquibase.setChangeLog(this.properties.getChangeLog()); + liquibase.setClearCheckSums(this.properties.isClearChecksums()); liquibase.setContexts(this.properties.getContexts()); liquibase.setDefaultSchema(this.properties.getDefaultSchema()); liquibase.setLiquibaseSchema(this.properties.getLiquibaseSchema()); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseProperties.java index 78f486e2f4..dd183c9ef7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseProperties.java @@ -29,6 +29,7 @@ import org.springframework.util.Assert; * * @author Marcel Overdijk * @author Eddú Meléndez + * @author Ferenc Gratzer * @since 1.1.0 */ @ConfigurationProperties(prefix = "spring.liquibase", ignoreUnknownFields = false) @@ -39,6 +40,12 @@ public class LiquibaseProperties { */ private String changeLog = "classpath:/db/changelog/db.changelog-master.yaml"; + /** + * Whether to clear all checksums in the current changelog, so they will be + * recalculated upon the next update. + */ + private boolean clearChecksums; + /** * Comma-separated list of runtime contexts to use. */ @@ -187,6 +194,14 @@ public class LiquibaseProperties { this.dropFirst = dropFirst; } + public boolean isClearChecksums() { + return this.clearChecksums; + } + + public void setClearChecksums(boolean clearChecksums) { + this.clearChecksums = clearChecksums; + } + public boolean isEnabled() { return this.enabled; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java index 9dc0709601..6ab18e54fa 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java @@ -69,6 +69,7 @@ import static org.assertj.core.api.Assertions.contentOf; * @author Dominic Gunn * @author András Deák * @author Andrii Hrytsiuk + * @author Ferenc Gratzer */ @ExtendWith(OutputCaptureExtension.class) class LiquibaseAutoConfigurationTests { @@ -106,6 +107,7 @@ class LiquibaseAutoConfigurationTests { assertThat(liquibase.getContexts()).isNull(); assertThat(liquibase.getDefaultSchema()).isNull(); assertThat(liquibase.isDropFirst()).isFalse(); + assertThat(liquibase.isClearCheckSums()).isFalse(); })); } @@ -143,6 +145,7 @@ class LiquibaseAutoConfigurationTests { assertThat(liquibase.getDatabaseChangeLogLockTable()) .isEqualTo(properties.getDatabaseChangeLogLockTable()); assertThat(liquibase.isDropFirst()).isEqualTo(properties.isDropFirst()); + assertThat(liquibase.isClearCheckSums()).isEqualTo(properties.isClearChecksums()); assertThat(liquibase.isTestRollbackOnUpdate()).isEqualTo(properties.isTestRollbackOnUpdate()); })); } @@ -189,6 +192,13 @@ class LiquibaseAutoConfigurationTests { .run(assertLiquibase((liquibase) -> assertThat(liquibase.isDropFirst()).isTrue())); } + @Test + void overrideClearChecksums() { + this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) + .withPropertyValues("spring.liquibase.clear-checksums:true") + .run(assertLiquibase((liquibase) -> assertThat(liquibase.isClearCheckSums()).isTrue())); + } + @Test void overrideDataSource() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)