-
添加依赖
text<dependency> <groupId>org.liquibase</groupId> <artifactId>liquibase-core</artifactId> </dependency> -
添加配置
ymlspring: liquibase: contexts: dev,test enabled: true -
编写liquibase配置类
java@Configuration @EnableConfigurationProperties(LiquibaseProperties.class) public class LiquibaseConfig { @Bean public 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; } } -
编写master.xml文件(注意includeAll配置的路径与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.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> -
编写changelog文件 00000000000000_init_schema.xml
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 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>
Springboot集成Liquibase笔记整理
yicj2024-08-20 11:46
相关推荐
Coder_Boy_4 分钟前
基于SpringAI企业级智能教学考试平台考试模块全业务闭环方案微爱帮监所写信寄信6 分钟前
微爱帮监狱寄信写信小程序信件内容实时保存技术方案沛沛老爹7 分钟前
Web开发者实战A2A智能体交互协议:从Web API到AI Agent通信新范式shizhenshide8 分钟前
物联网(IoT)设备如何应对验证码?探讨无头浏览器与协议级解决方案七夜zippoe9 分钟前
响应式编程基石 Project Reactor源码解读独自归家的兔12 分钟前
基于 豆包大模型 Doubao-Seed-1.6-thinking 的前后端分离项目 - 图文问答(后端)IT 行者19 分钟前
Spring Framework 6.x 异常国际化完全指南:让错误信息“说“多国语言ss27319 分钟前
CompletionService:Java并发工具包晓131324 分钟前
后端篇——第一章 Maven基础全面教程二进制_博客26 分钟前
JWT权限认证快速入门