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>
三、目录结构
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?