spring boot集成liquibase,

liquibase是一个升级脚本工具,且可以进行前置条件的约束

spring boot集成liquibase

步骤1、添加依赖

<!--liquibase-->
        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
        </dependency>
<!--mysql-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>

步骤2:配置application.properties

#### datasource  不配置这个?serverTimezone=UTC 会报错如下错误
# The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone
server.port=9090
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.max-idle=10
spring.datasource.max-wait=10000
spring.datasource.min-idle=5
spring.datasource.initial-size=5
# LIQUIBASE (LiquibaseProperties)
spring.liquibase.check-change-log-location=true
spring.liquibase.drop-first=false
spring.liquibase.enabled=true
spring.liquibase.change-log=classpath:/liqubase/changeLog.xml

步骤3:在liqubase/changeLog.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.4.xsd"><property name="now" value="now()" dbms="mysql"/>

<!-- runOnChange ="false"是如果id+author+内容 md5加密之后不改变是不变得-->    <changeSet id="init-schema" author="jhh" runOnChange="false">
 <preConditions onFail="MARK_RAN">
    <sqlCheck expectedResult="0">
        select count(*) from user_name where user_name = 22;
    </sqlCheck>
</preConditions>
<comment>新增脚本</comment>       <sql>
           INSERT INTO `user_name` ( `user_name`, `phone`, `address`) VALUES ( '22', '33', '22');
       </sql>
 <rollback>
 DELETE from  user_name where user_name = 22;
 </rollback>
    </changeSet>
</databaseChangeLog>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值