当前位置: 首页> 汽车> 维修 > Springboot集成Liquibase笔记整理

Springboot集成Liquibase笔记整理

时间:2025/8/26 6:56:59来源:https://blog.csdn.net/yichengjie_c/article/details/141305431 浏览次数: 0次
  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>
    
关键字:Springboot集成Liquibase笔记整理

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: