springboot集成liquibase
简介
Liquibase社区是一个开源项目,帮助数百万开发人员快速管理数据库模式更改。
官网地址
链接: liquibase.
springboot集成
依赖
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
application.yml
server:
port: 8080
spring:
datasource:
username: root
password: Qloud@dev?666
url: jdbc:mysql://192.168.2.42:32430/test?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
driver-class-name: com.mysql.jdbc.Driver
liquibase:
enabled: true
change-log: "classpath:/db/changelog/db.changelog-master.yaml"
contexts: dev
db.changelog-master.yaml
这个有很多种配置方式
配置方式一
databaseChangeLog:
- changeSet:
id: 1
author: nvoxland
changes:
- createTable:
tableName: person
columns:
- column:
name: id
type: int
autoIncrement: true
constraints:
primaryKey: true
nullable: false
- column:
name: firstname
type: varchar(50)
- column:
name: lastname
type: varchar(50)
constraints:
nullable: false
- column:
name: state
type: char(2)
配置方式二
#databaseChangeLog:
# - include:
# file: db/changelog/01-create-test-schema.xml
# - include:
# file: db/changelog/02-insert-test-data.xml
配置方式三
<?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"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<include file="db/changelog/01-create-test-schema.xml" relativeToChangelogFile="false"></include>
<include file="db/changelog/02-insert-test-data.xml" relativeToChangelogFile="false"></include>
</databaseChangeLog>
示例 github地址
https://github.com/hkj123/liquibase.git
官方例子地址
https://docs.liquibase.com/tools-integrations/springboot/using-springboot-with-maven.html