Merge pull request #19316 from eddumelendez

* pr/19316:
  Polish "Add support for configuring Liquibase tag property"
  Add support for configuring Liquibase tag property

Closes gh-19316
This commit is contained in:
Stephane Nicoll 2020-02-17 09:56:52 +01:00
commit d4c7315369
3 changed files with 25 additions and 1 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -112,6 +112,7 @@ public class LiquibaseAutoConfiguration {
liquibase.setChangeLogParameters(this.properties.getParameters()); liquibase.setChangeLogParameters(this.properties.getParameters());
liquibase.setRollbackFile(this.properties.getRollbackFile()); liquibase.setRollbackFile(this.properties.getRollbackFile());
liquibase.setTestRollbackOnUpdate(this.properties.isTestRollbackOnUpdate()); liquibase.setTestRollbackOnUpdate(this.properties.isTestRollbackOnUpdate());
liquibase.setTag(this.properties.getTag());
return liquibase; return liquibase;
} }

View File

@ -28,6 +28,7 @@ import org.springframework.util.Assert;
* Configuration properties to configure {@link SpringLiquibase}. * Configuration properties to configure {@link SpringLiquibase}.
* *
* @author Marcel Overdijk * @author Marcel Overdijk
* @author Eddú Meléndez
* @since 1.1.0 * @since 1.1.0
*/ */
@ConfigurationProperties(prefix = "spring.liquibase", ignoreUnknownFields = false) @ConfigurationProperties(prefix = "spring.liquibase", ignoreUnknownFields = false)
@ -114,6 +115,13 @@ public class LiquibaseProperties {
*/ */
private boolean testRollbackOnUpdate; private boolean testRollbackOnUpdate;
/**
* Tag name to use when applying database changes. Can also be used with
* "rollbackFile" to generate a rollback script for all existing changes associated
* with that tag.
*/
private String tag;
public String getChangeLog() { public String getChangeLog() {
return this.changeLog; return this.changeLog;
} }
@ -243,4 +251,12 @@ public class LiquibaseProperties {
this.testRollbackOnUpdate = testRollbackOnUpdate; this.testRollbackOnUpdate = testRollbackOnUpdate;
} }
public String getTag() {
return this.tag;
}
public void setTag(String tag) {
this.tag = tag;
}
} }

View File

@ -343,6 +343,13 @@ class LiquibaseAutoConfigurationTests {
}); });
} }
@Test
void overrideTag() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.liquibase.tag:1.0.0")
.run(assertLiquibase((liquibase) -> assertThat(liquibase.getTag()).isEqualTo("1.0.0")));
}
private ContextConsumer<AssertableApplicationContext> assertLiquibase(Consumer<SpringLiquibase> consumer) { private ContextConsumer<AssertableApplicationContext> assertLiquibase(Consumer<SpringLiquibase> consumer) {
return (context) -> { return (context) -> {
assertThat(context).hasSingleBean(SpringLiquibase.class); assertThat(context).hasSingleBean(SpringLiquibase.class);