1.引入liquibase和数据库驱动包
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
2.给application.yml添加配置
liquibase:
#启用liquibase,Spring boot 2.0之后使用spring.liquibase.enabled
enabled: true
change-log: classpath:db/changelog/db.changelog-master.yml #存储变化的xml文件的位置
database-change-log-table: DATABASECHANGELOG_${spring.application.name}
database-change-log-lock-table: DATABASECHANGELOGLOCK_${spring.application.name}
3.classpath下新建文件db/changelog/db.changelog-master.yml
databaseChangeLog:
- include:
file: db/changelog/appv1.0.yml
relative-to-changelog-file: false
changelog目录下新建appv1.0.yml
databaseChangeLog:
- changeSet:
id: app_table
author: 'xxx'
comment: '初始化app'
changes:
# 通过sql文件操作数据库
- sqlFile:
encoding: utf8
path: db/changelog/app_table.sql
- changeSet:
id: app_data
author: 'xxx'
comment: '初始化数据'
changes:
# 通过sql文件操作数据库
- sqlFile:
encoding: utf8
path: db/changelog/app_data.sql
新建app_table.sql文件
CREATE TABLE xxx (
ID VARCHAR(32) COMMENT '主键',
USER_ID VARCHAR(32) COMMENT '用户主键',
USER_NAME VARCHAR(50) COMMENT '用户姓名',
PRIMARY KEY (ID)
) COMMENT = '表';
新建app_data.sql文件
-- 数据初始化
INSERT INTO xxx
标签:集成,changelog,app,db,liquibase,sql,table
From: https://www.cnblogs.com/treasury/p/16993871.html