liquibase 数据库同步工具

记录在开发环境对数据库的变更操作,整理为sql文件后,发布测试环境或者生产环境时,自动执行配置的sql文件,不对生产环境进行直接操作

参考: https://blog.csdn.net/qq_41854273/article/details/124963965

官方文档: https://docs.liquibase.com/home.html

jar包

<dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
            <version>4.9.1</version>
        </dependency>

 

一、创建加载类

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

import javax.sql.DataSource;

/**
 * @author luwl
 */
@Configuration
public class LiQuiConfig {

    @Bean
    public SpringLiquibase liquibase(DataSource dataSource){
        SpringLiquibase liquibase = new SpringLiquibase();
        //设置数据源
        liquibase.setDataSource(dataSource);
        //sql文件位置
        liquibase.setChangeLog("classpath:liquibase/master.xml");
        return liquibase;
    }

}

二、进行sql文件配置

<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.1.xsd">

    <includeAll path="liquibase/sql/" relativeToChangelogFile="false"/>
<!--    <include file="liquibase/sql/20220914/service-v1.sql" relativeToChangelogFile="false"/>-->
<!--    <include file="liquibase/sql/20220916/test.sql" relativeToChangelogFile="false"/>-->

</databaseChangeLog>

三、目录结构

 

 

 

 

posted @ 2022-10-03 11:53  雨梦大木  阅读(144)  评论(0编辑  收藏  举报