mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Added liquibase autoconfiguration for database migrations
If Liquibase is on the classpath it will fire up on startup. Various config options are available (as well as the option to disable it). Liquibase uses a YAML format for changes (in classpath:db/changelog).
This commit is contained in:
parent
ed64640ea4
commit
68e33b25c1
@ -167,6 +167,11 @@
|
||||
<artifactId>jedis</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.liquibase</groupId>
|
||||
<artifactId>liquibase-core</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-acl</artifactId>
|
||||
|
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.liquibase;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
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.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for Liquibase.
|
||||
*
|
||||
* @author Marcel Overdijk
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(SpringLiquibase.class)
|
||||
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
|
||||
public class LiquibaseAutoConfiguration {
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnMissingBean(SpringLiquibase.class)
|
||||
@EnableConfigurationProperties(LiquibaseProperties.class)
|
||||
public static class LiquibaseConfiguration {
|
||||
|
||||
@Autowired
|
||||
private LiquibaseProperties properties = new LiquibaseProperties();
|
||||
|
||||
@Autowired
|
||||
private ResourceLoader resourceLoader = new DefaultResourceLoader();
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@PostConstruct
|
||||
public void checkChangelogExists() {
|
||||
if (this.properties.isCheckChangeLogLocation()) {
|
||||
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)");
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SpringLiquibase liquibase() {
|
||||
SpringLiquibase liquibase = new SpringLiquibase();
|
||||
liquibase.setChangeLog(this.properties.getChangeLog());
|
||||
liquibase.setContexts(this.properties.getContexts());
|
||||
liquibase.setDataSource(dataSource);
|
||||
liquibase.setDefaultSchema(this.properties.getDefaultSchema());
|
||||
liquibase.setDropFirst(this.properties.isDropFirst());
|
||||
liquibase.setShouldRun(this.properties.isShouldRun());
|
||||
return liquibase;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.liquibase;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import liquibase.integration.spring.SpringLiquibase;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* Configuration properties to configure {@link SpringLiquibase}.
|
||||
*
|
||||
* @author Marcel Overdijk
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "spring.liquibase", ignoreUnknownFields = false)
|
||||
public class LiquibaseProperties {
|
||||
|
||||
@NotNull
|
||||
private String changeLog = "classpath:/db/changelog/db.changelog-master.yaml";
|
||||
|
||||
private boolean checkChangeLogLocation = true;
|
||||
|
||||
private String contexts;
|
||||
|
||||
private String defaultSchema;
|
||||
|
||||
private boolean dropFirst = false;
|
||||
|
||||
private boolean shouldRun = true;
|
||||
|
||||
public String getChangeLog() {
|
||||
return changeLog;
|
||||
}
|
||||
|
||||
public void setChangeLog(String changeLog) {
|
||||
this.changeLog = changeLog;
|
||||
}
|
||||
|
||||
public boolean isCheckChangeLogLocation() {
|
||||
return checkChangeLogLocation;
|
||||
}
|
||||
|
||||
public void setCheckChangeLogLocation(boolean checkChangeLogLocation) {
|
||||
this.checkChangeLogLocation = checkChangeLogLocation;
|
||||
}
|
||||
|
||||
public String getContexts() {
|
||||
return contexts;
|
||||
}
|
||||
|
||||
public void setContexts(String contexts) {
|
||||
this.contexts = contexts;
|
||||
}
|
||||
|
||||
public String getDefaultSchema() {
|
||||
return defaultSchema;
|
||||
}
|
||||
|
||||
public void setDefaultSchema(String defaultSchema) {
|
||||
this.defaultSchema = defaultSchema;
|
||||
}
|
||||
|
||||
public boolean isDropFirst() {
|
||||
return dropFirst;
|
||||
}
|
||||
|
||||
public void setDropFirst(boolean dropFirst) {
|
||||
this.dropFirst = dropFirst;
|
||||
}
|
||||
|
||||
public boolean isShouldRun() {
|
||||
return shouldRun;
|
||||
}
|
||||
|
||||
public void setShouldRun(boolean shouldRun) {
|
||||
this.shouldRun = shouldRun;
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@ org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.jms.JmsTemplateAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.mobile.DeviceResolverAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.mongo.MongoDataAutoConfiguration,\
|
||||
|
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.liquibase;
|
||||
|
||||
import liquibase.integration.spring.SpringLiquibase;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
import org.springframework.boot.test.EnvironmentTestUtils;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for {@link LiquibaseAutoConfiguration}.
|
||||
*
|
||||
* @author Marcel Overdijk
|
||||
*/
|
||||
public class LiquibaseAutoConfigurationTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException expected = ExpectedException.none();
|
||||
|
||||
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();;
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
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();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultSpringLiquibase() throws Exception {
|
||||
this.context.register(EmbeddedDataSourceConfiguration.class,
|
||||
LiquibaseAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
SpringLiquibase liquibase = this.context.getBean(SpringLiquibase.class);
|
||||
assertEquals("classpath:/db/changelog/db.changelog-master.yaml", liquibase.getChangeLog());
|
||||
assertNull(liquibase.getContexts());
|
||||
assertNull(liquibase.getDefaultSchema());
|
||||
assertFalse(liquibase.isDropFirst());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverrideChangeLog() throws Exception {
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.liquibase.change-log:classpath:/db/changelog/db.changelog-override.xml");
|
||||
this.context.register(EmbeddedDataSourceConfiguration.class,
|
||||
LiquibaseAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
SpringLiquibase liquibase = this.context.getBean(SpringLiquibase.class);
|
||||
assertEquals("classpath:/db/changelog/db.changelog-override.xml", liquibase.getChangeLog());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverrideContexts() throws Exception {
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.liquibase.contexts:test, production");
|
||||
this.context.register(EmbeddedDataSourceConfiguration.class,
|
||||
LiquibaseAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
SpringLiquibase liquibase = this.context.getBean(SpringLiquibase.class);
|
||||
assertEquals("test, production", liquibase.getContexts());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverrideDefaultSchema() throws Exception {
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.liquibase.default-schema:public");
|
||||
this.context.register(EmbeddedDataSourceConfiguration.class,
|
||||
LiquibaseAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
SpringLiquibase liquibase = this.context.getBean(SpringLiquibase.class);
|
||||
assertEquals("public", liquibase.getDefaultSchema());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverrideDropFirst() throws Exception {
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.liquibase.drop-first:true");
|
||||
this.context.register(EmbeddedDataSourceConfiguration.class,
|
||||
LiquibaseAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
SpringLiquibase liquibase = this.context.getBean(SpringLiquibase.class);
|
||||
assertTrue(liquibase.isDropFirst());
|
||||
}
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
public void testChangeLogDoesNotExist() throws Exception {
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.liquibase.change-log:classpath:/no-such-changelog.yaml");
|
||||
this.context.register(EmbeddedDataSourceConfiguration.class,
|
||||
LiquibaseAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
databaseChangeLog:
|
||||
- changeSet:
|
||||
id: 1
|
||||
author: marceloverdijk
|
||||
changes:
|
||||
- createTable:
|
||||
tableName: customer
|
||||
columns:
|
||||
- column:
|
||||
name: id
|
||||
type: int
|
||||
autoIncrement: true
|
||||
constraints:
|
||||
primaryKey: true
|
||||
nullable: false
|
||||
- column:
|
||||
name: name
|
||||
type: varchar(50)
|
||||
constraints:
|
||||
nullable: false
|
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<databaseChangeLog
|
||||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
|
||||
|
||||
<changeSet id="1" author="marceloverdijk">
|
||||
<createTable tableName="customer">
|
||||
<column name="id" type="int" autoIncrement="true">
|
||||
<constraints primaryKey="true" nullable="false"/>
|
||||
</column>
|
||||
<column name="name" type="varchar(50)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</createTable>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
@ -158,6 +158,13 @@ content into your application; rather pick only the properties that you need.
|
||||
spring.jpa.hibernate.naming-strategy= # naming classname
|
||||
spring.jpa.hibernate.ddl-auto= # defaults to create-drop for embedded dbs
|
||||
|
||||
# LIQUIBASE ({sc-spring-boot-autoconfigure}/liquibase/LiquibaseProperties.{sc-ext}[LiquibaseProperties])
|
||||
spring.liquibase.change-log=classpath:/db/changelog/db.changelog-master.yaml
|
||||
spring.liquibase.contexts= # runtime contexts to use
|
||||
spring.liquibase.default-schema= # default database schema to use
|
||||
spring.liquibase.drop-first=false
|
||||
spring.liquibase.should-run=true
|
||||
|
||||
# JMX
|
||||
spring.jmx.enabled=true # Expose MBeans from Spring
|
||||
|
||||
@ -170,7 +177,6 @@ content into your application; rather pick only the properties that you need.
|
||||
spring.rabbitmq.virtualhost=
|
||||
spring.rabbitmq.dynamic=
|
||||
|
||||
|
||||
# REDIS ({sc-spring-boot-autoconfigure}/redis/RedisProperties.{sc-ext}[RedisProperties])
|
||||
spring.redis.host=localhost # server host
|
||||
spring.redis.password= # server password
|
||||
|
@ -56,6 +56,9 @@ The following auto-configuration classes are from the `spring-boot-autoconfigure
|
||||
|{sc-spring-boot-autoconfigure}/data/JpaRepositoriesAutoConfiguration.{sc-ext}[JpaRepositoriesAutoConfiguration]
|
||||
|{dc-spring-boot-autoconfigure}/data/JpaRepositoriesAutoConfiguration.{dc-ext}[javadoc]
|
||||
|
||||
|{sc-spring-boot-autoconfigure}/liquibase/LiquibaseAutoConfiguration.{sc-ext}[LiquibaseAutoConfiguration]
|
||||
|{dc-spring-boot-autoconfigure}/liquibase/LiquibaseAutoConfiguration.{dc-ext}[javadoc]
|
||||
|
||||
|{sc-spring-boot-autoconfigure}/MessageSourceAutoConfiguration.{sc-ext}[MessageSourceAutoConfiguration]
|
||||
|{dc-spring-boot-autoconfigure}/MessageSourceAutoConfiguration.{dc-ext}[javadoc]
|
||||
|
||||
|
@ -1097,6 +1097,21 @@ independence: usually only one or at most couple of platforms is needed.
|
||||
|
||||
|
||||
|
||||
[[howto-execute-liquibase-database-migrations-on-startup]]
|
||||
==== Execute Liquibase database migrations on startup
|
||||
To automatically run Liquibase database migrations on startup, add the
|
||||
`spring-boot-starter-liquibase` to your classpath.
|
||||
|
||||
The master change log is by default read from `db/changelog/db.changelog-master.yaml` but
|
||||
can be set using `spring.liquibase.change-log`. 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.
|
||||
|
||||
|
||||
|
||||
[[howto-batch-applications]]
|
||||
== Batch applications
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
= Spring Boot Reference Guide
|
||||
Phillip Webb; Dave Syer; Josh Long; Stéphane Nicoll; Rob Winch; Andy Wilkinson;
|
||||
Phillip Webb; Dave Syer; Josh Long; Stéphane Nicoll; Rob Winch; Andy Wilkinson; Marcel Overdijk;
|
||||
:doctype: book
|
||||
:toc:
|
||||
:toclevels: 4
|
||||
|
@ -238,6 +238,9 @@ and Hibernate.
|
||||
|`spring-boot-starter-jdbc`
|
||||
|JDBC Database support.
|
||||
|
||||
|`spring-boot-starter-liquibase`
|
||||
|Support for Liquibase database migrations.
|
||||
|
||||
|`spring-boot-starter-mobile`
|
||||
|Support for `spring-mobile`
|
||||
|
||||
|
@ -34,6 +34,7 @@
|
||||
<module>spring-boot-sample-data-rest</module>
|
||||
<module>spring-boot-sample-integration</module>
|
||||
<module>spring-boot-sample-jetty</module>
|
||||
<module>spring-boot-sample-liquibase</module>
|
||||
<module>spring-boot-sample-profile</module>
|
||||
<module>spring-boot-sample-secure</module>
|
||||
<module>spring-boot-sample-servlet</module>
|
||||
|
49
spring-boot-samples/spring-boot-sample-liquibase/pom.xml
Normal file
49
spring-boot-samples/spring-boot-sample-liquibase/pom.xml
Normal file
@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<!-- Your own application should inherit from spring-boot-starter-parent -->
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-samples</artifactId>
|
||||
<version>1.0.2.BUILD-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>spring-boot-sample-liquibase</artifactId>
|
||||
<name>Spring Boot Liquibase Sample</name>
|
||||
<description>Spring Boot Liquibase Sample</description>
|
||||
<url>http://projects.spring.io/spring-boot/</url>
|
||||
<organization>
|
||||
<name>Pivotal Software, Inc.</name>
|
||||
<url>http://www.spring.io</url>
|
||||
</organization>
|
||||
<properties>
|
||||
<main.basedir>${basedir}/../..</main.basedir>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-liquibase</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hsqldb</groupId>
|
||||
<artifactId>hsqldb</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample.liquibase;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan
|
||||
@EnableAutoConfiguration
|
||||
public class SampleLiquibaseApplication {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SpringApplication.run(SampleLiquibaseApplication.class, args);
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
spring.jpa.hibernate.ddl-auto: none
|
@ -0,0 +1,38 @@
|
||||
databaseChangeLog:
|
||||
- changeSet:
|
||||
id: 1
|
||||
author: marceloverdijk
|
||||
changes:
|
||||
- createTable:
|
||||
tableName: person
|
||||
columns:
|
||||
- column:
|
||||
name: id
|
||||
type: int
|
||||
autoIncrement: true
|
||||
constraints:
|
||||
primaryKey: true
|
||||
nullable: false
|
||||
- column:
|
||||
name: first_name
|
||||
type: varchar(255)
|
||||
constraints:
|
||||
nullable: false
|
||||
- column:
|
||||
name: last_name
|
||||
type: varchar(255)
|
||||
constraints:
|
||||
nullable: false
|
||||
- changeSet:
|
||||
id: 2
|
||||
author: marceloverdijk
|
||||
changes:
|
||||
- insert:
|
||||
tableName: person
|
||||
columns:
|
||||
- column:
|
||||
name: first_name
|
||||
value: Marcel
|
||||
- column:
|
||||
name: last_name
|
||||
value: Overdijk
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample.liquibase;
|
||||
|
||||
import java.net.ConnectException;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.test.OutputCapture;
|
||||
import org.springframework.core.NestedCheckedException;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class SampleLiquibaseApplicationTests {
|
||||
|
||||
@Rule
|
||||
public OutputCapture outputCapture = new OutputCapture();
|
||||
|
||||
@Test
|
||||
public void testDefaultSettings() throws Exception {
|
||||
try {
|
||||
SampleLiquibaseApplication.main(new String[0]);
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
if (serverNotRunning(ex)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Wrong output: " + output,
|
||||
output.contains("Successfully acquired change log lock") &&
|
||||
output.contains("Creating database history table with name: PUBLIC.DATABASECHANGELOG") &&
|
||||
output.contains("Table person created") &&
|
||||
output.contains("ChangeSet classpath:/db/changelog/db.changelog-master.yaml::1::marceloverdijk ran successfully") &&
|
||||
output.contains("New row inserted into person") &&
|
||||
output.contains("ChangeSet classpath:/db/changelog/db.changelog-master.yaml::2::marceloverdijk ran successfully") &&
|
||||
output.contains("Successfully released change log lock"));
|
||||
}
|
||||
|
||||
private boolean serverNotRunning(IllegalStateException ex) {
|
||||
@SuppressWarnings("serial")
|
||||
NestedCheckedException nested = new NestedCheckedException("failed", ex) {
|
||||
};
|
||||
if (nested.contains(ConnectException.class)) {
|
||||
Throwable root = nested.getRootCause();
|
||||
if (root.getMessage().contains("Connection refused")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -33,6 +33,7 @@
|
||||
<module>spring-boot-starter-integration</module>
|
||||
<module>spring-boot-starter-jdbc</module>
|
||||
<module>spring-boot-starter-jetty</module>
|
||||
<module>spring-boot-starter-liquibase</module>
|
||||
<module>spring-boot-starter-logging</module>
|
||||
<module>spring-boot-starter-log4j</module>
|
||||
<module>spring-boot-starter-mobile</module>
|
||||
|
31
spring-boot-starters/spring-boot-starter-liquibase/pom.xml
Normal file
31
spring-boot-starters/spring-boot-starter-liquibase/pom.xml
Normal file
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starters</artifactId>
|
||||
<version>1.0.2.BUILD-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>spring-boot-starter-liquibase</artifactId>
|
||||
<name>Spring Boot Liquibase Starter</name>
|
||||
<description>Spring Boot Liquibase Starter</description>
|
||||
<url>http://projects.spring.io/spring-boot/</url>
|
||||
<organization>
|
||||
<name>Pivotal Software, Inc.</name>
|
||||
<url>http://www.spring.io</url>
|
||||
</organization>
|
||||
<properties>
|
||||
<main.basedir>${basedir}/../..</main.basedir>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.liquibase</groupId>
|
||||
<artifactId>liquibase-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1 @@
|
||||
provides: liquibase-core
|
@ -121,6 +121,11 @@
|
||||
<artifactId>spring-boot-starter-jetty</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-liquibase</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
|
Loading…
Reference in New Issue
Block a user