diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java index ecdf1e3e2c..8b3c07dc3d 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java @@ -42,6 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat; * Tests for {@link LiquibaseAutoConfiguration}. * * @author Marcel Overdijk + * @author Andy Wilkinson */ public class LiquibaseAutoConfigurationTests { @@ -90,7 +91,7 @@ public class LiquibaseAutoConfigurationTests { } @Test - public void testOverrideChangeLog() throws Exception { + public void testXmlChangeLog() throws Exception { EnvironmentTestUtils.addEnvironment(this.context, "liquibase.change-log:classpath:/db/changelog/db.changelog-override.xml"); this.context.register(EmbeddedDataSourceConfiguration.class, @@ -102,6 +103,32 @@ public class LiquibaseAutoConfigurationTests { .isEqualTo("classpath:/db/changelog/db.changelog-override.xml"); } + @Test + public void testJsonChangeLog() throws Exception { + EnvironmentTestUtils.addEnvironment(this.context, + "liquibase.change-log:classpath:/db/changelog/db.changelog-override.json"); + this.context.register(EmbeddedDataSourceConfiguration.class, + LiquibaseAutoConfiguration.class, + PropertyPlaceholderAutoConfiguration.class); + this.context.refresh(); + SpringLiquibase liquibase = this.context.getBean(SpringLiquibase.class); + assertThat(liquibase.getChangeLog()) + .isEqualTo("classpath:/db/changelog/db.changelog-override.json"); + } + + @Test + public void testSqlChangeLog() throws Exception { + EnvironmentTestUtils.addEnvironment(this.context, + "liquibase.change-log:classpath:/db/changelog/db.changelog-override.sql"); + this.context.register(EmbeddedDataSourceConfiguration.class, + LiquibaseAutoConfiguration.class, + PropertyPlaceholderAutoConfiguration.class); + this.context.refresh(); + SpringLiquibase liquibase = this.context.getBean(SpringLiquibase.class); + assertThat(liquibase.getChangeLog()) + .isEqualTo("classpath:/db/changelog/db.changelog-override.sql"); + } + @Test public void testOverrideContexts() throws Exception { EnvironmentTestUtils.addEnvironment(this.context, diff --git a/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-override.json b/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-override.json new file mode 100644 index 0000000000..0c8bf1ff7e --- /dev/null +++ b/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-override.json @@ -0,0 +1,39 @@ +{ + "databaseChangeLog": [ + { + "changeSet": { + "author": "awilkinson", + "id": "1", + "changes": [ + { + "createTable": { + "tableName": "customer", + "columns": [ + { + "column": { + "name": "id", + "type": "int", + "autoIncrement": true, + "constraints": { + "nullable": false, + "primaryKey": true + }, + } + }, + { + "column": { + "name": "name", + "type": "varchar(50)", + "constraints": { + "nullable": false + } + } + } + ], + } + } + ] + } + } + ] +} diff --git a/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-override.sql b/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-override.sql new file mode 100644 index 0000000000..cd68b45850 --- /dev/null +++ b/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-override.sql @@ -0,0 +1,8 @@ +--liquibase formatted sql + +--changeset author:awilkinson + +CREATE TABLE customer ( + id int AUTO_INCREMENT NOT NULL PRIMARY KEY, + name varchar(50) NOT NULL +); \ No newline at end of file diff --git a/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-docs/src/main/asciidoc/howto.adoc index a04182d8e3..2531f2fc02 100644 --- a/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -1847,11 +1847,9 @@ initialization explicitly using `spring.batch.initializer.enabled=false`. [[howto-use-a-higher-level-database-migration-tool]] -=== Use a higher level database migration tool -Spring Boot works fine with higher level migration tools http://flywaydb.org/[Flyway] -(SQL-based) and http://www.liquibase.org/[Liquibase] (XML). In general we prefer -Flyway because it is easier on the eyes, and it isn't very common to need platform -independence: usually only one or at most couple of platforms is needed. +=== Use a higher-level database migration tool +Spring Boot supports two higher-level migration tools: http://flywaydb.org/[Flyway] +and http://www.liquibase.org/[Liquibase]. [[howto-execute-flyway-database-migrations-on-startup]] ==== Execute Flyway database migrations on startup @@ -1890,12 +1888,15 @@ To automatically run Liquibase database migrations on startup, add the `org.liquibase:liquibase-core` to your classpath. The master change log is by default read from `db/changelog/db.changelog-master.yaml` but -can be set using `liquibase.change-log`. See +can be set using `liquibase.change-log`. In addition to YAML, Liquibase also supports +JSON, XML, and SQL change log formats. + +See {sc-spring-boot-autoconfigure}/liquibase/LiquibaseProperties.{sc-ext}[`LiquibaseProperties`] for details of available settings like contexts, default schema etc. -There is a {github-code}/spring-boot-samples/spring-boot-sample-liquibase[Liquibase sample] so -you can see how to set things up. +There is a {github-code}/spring-boot-samples/spring-boot-sample-liquibase[Liquibase sample] +so you can see how to set things up.