当前位置: 首页 > news >正文

Springboot集成Liquibase笔记整理

  1. 添加依赖
    <dependency><groupId>org.liquibase</groupId><artifactId>liquibase-core</artifactId>
    </dependency>
    
  2. 添加配置
    spring:liquibase:contexts: dev,testenabled: true
    
  3. 编写liquibase配置类
    @Configuration
    @EnableConfigurationProperties(LiquibaseProperties.class)
    public class LiquibaseConfig {@Beanpublic SpringLiquibase liquibase(DataSource dataSource, LiquibaseProperties properties) {SpringLiquibase liquibase = new SpringLiquibase();liquibase.setDataSource(dataSource);//指定changelog的位置,这里使用的一个master文件引用其他文件的方式liquibase.setChangeLog("classpath:liquibase/master.xml");liquibase.setContexts(properties.getContexts());liquibase.setDefaultSchema(properties.getDefaultSchema());liquibase.setDropFirst(properties.isDropFirst());liquibase.setShouldRun(properties.isEnabled());liquibase.setChangeLogParameters(properties.getParameters());liquibase.setRollbackFile(properties.getRollbackFile());liquibase.setShouldRun(true);return liquibase;}
    }
    
  4. 编写master.xml文件(注意includeAll配置的路径与changelog文件的路径)
    <?xml version="1.0" encoding="utf-8"?>
    <databaseChangeLogxmlns="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"/><property name="clobType" value="clob" dbms="h2"/><property name="clobType" value="clob" dbms="mysql, oracle, mssql, mariadb, postgresql"/><property name="uuidType" value="varchar(36)" dbms="h2, mysql, mariadb"/><includeAll path="liquibase/changelog/"/>
    </databaseChangeLog>
    
  5. 编写changelog文件 00000000000000_init_schema.xml
    <?xml version="1.0" encoding="utf-8"?>
    <databaseChangeLogxmlns="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.xsdhttp://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"><property name="autoIncrement" value="true"/><changeSet author="system" id="00000000000001" context="dev"><createTable tableName="hello_date_time_wrapper"><column  name="id" type="BIGINT"><constraints primaryKey="true" primaryKeyName="hello_date_time_wrapperPK"/></column><column name="instant" type="timestamp"/><column name="local_date_time" type="timestamp"/><column name="offset_date_time" type="timestamp"/><column name="zoned_date_time" type="timestamp"/><column name="local_time" type="time"/><column name="offset_time" type="time"/><column name="local_date" type="date"/></createTable></changeSet>
    </databaseChangeLog>
    
http://www.lryc.cn/news/427134.html

相关文章:

  • Python拆分无atlas图集(瑕疵版)
  • SQLALchemy 排序
  • 【iOS】Block底层分析
  • 复现dom破坏案例和靶场
  • 【高校科研前沿】南方科技大学冯炼教授等人在遥感顶刊RSE发文:全球人类改造的基塘系统制图
  • How to run angular CICD on gitlab-runner of wsl?
  • 搭建Java集成开发环境IntelliJ IDEA
  • JS逆向浏览器脱环境专题:事件学习和编写、DOM和BOM结构、指纹验证排查、代理自吐环境通杀环境检测、脱环境框架、脱环境插件解决
  • 驾校预约学习系统--论文pf
  • 交叉编译ARM平台的OpenCV1.0
  • 牛客周赛 Round 56 AK
  • LeetCode 热题 HOT 100 (038/100)【宇宙最简单版】
  • SQLALchemy ORM 的关联关系之 ORM 中的一对一
  • 模型部署 - docker
  • 学懂C++(三十四):深入详解 C++ 高级多线程编程技术中的并发设计模式
  • 大数据产业链图谱_产业链全景图_大数据行业市场分析
  • photonserver 部署相关教程
  • GEE训练:sentinel-1数据的投影、显示和导出
  • 后端学习笔记(七)--MyBatis参数传递
  • uniapp 网络请求自动处理loading
  • 【Solidity】函数的使用
  • 详解golang内存管理
  • C++ 线程 一些同步方式
  • 【开发语言】编译型语言和解释性语言有啥区别?
  • 将A服务器上指定文件夹中的文件,批量同步到B服务器上
  • 2024.8.17
  • 十分钟搭建一个RTMP服务器
  • Spring Boot解决循环注入问题
  • 《数据挖掘》期末考核重点
  • Golang | Leetcode Golang题解之第334题递增的三元子序列