liquibase---SpringBoot+Maven+liquibase

博客介绍了SpringBoot、Maven和liquibase的相关配置。展示了配置文件中liquibase的配置,代码里LiquibaseConfig类的编写,以及master.xml和20190626reportdata_addcloumn.xml文件内容,用于数据库变更管理,后续加文件可继续追加。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

SpringBoot+Maven+liquibase

配置文件中

spring:
liquibase:
change-log: classpath:conf/liquibase/master.xml
enabled: true
drop-first: false
contexts: dev,prod
1
2
3
4
5
6
代码中

import liquibase.integration.spring.SpringLiquibase;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
public class LiquibaseConfig {

@Value("${spring.liquibase.enabled}")
private Boolean enable;

@Value("${spring.liquibase.drop-first}")
private Boolean deopFirst;

@Value("${spring.liquibase.contexts}")
private String contexts;

@Bean(name = "liquibase")
public SpringLiquibase springLiquibase(DataSource dataSource) {

SpringLiquibase springLiquibase = new SpringLiquibase();

springLiquibase.setDataSource(dataSource);
springLiquibase.setChangeLog("classpath:/conf/liquibase/master.xml");
springLiquibase.setShouldRun(enable);
springLiquibase.setDropFirst(deopFirst);
springLiquibase.setContexts(contexts);
return springLiquibase;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
master.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.6.xsd">

<property name="now" value="now()" dbms="h2"/>
<property name="now" value="now()" dbms="mysql"/>

<property name="floatType" value="float4" dbms="postgresql, h2"/>
<property name="floatType" value="float" dbms="mysql, oracle, mssql, mariadb"/>

<include file="classpath:conf/liquibase/changelog/20190626reportdata_addcloumn.xml" relativeToChangelogFile="false"/>
</databaseChangeLog>
后续加文件时,继续追加就行了
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
20190626reportdata_addcloumn.xml

<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
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.6.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">

<property name="autoIncrement" value="true"/>

<changeSet id="20190626reportdata_addcloumn" author="zzh">
<addColumn tableName="report_data">
<column name="status" type="int" remarks="状态" ></column>
</addColumn>
<addColumn tableName="report_data">
<column name="create_user_id" type="int" remarks="创建人id" ></column>
</addColumn>
<addColumn tableName="report_data">
<column name="check_user_id" type="int" remarks="确认人id" ></column>
</addColumn>
<addColumn tableName="report_data">
<column name="check_time" type="datetime" remarks="确认时间" ></column>
</addColumn>
</changeSet>
</databaseChangeLog>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

---------------------

转载于:https://www.cnblogs.com/liyanyan665/p/11183019.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值