Liquibase入门介绍

简介Liquibase社区版是一个开源项目,可以帮助开发人员快速管理数据库架构更改。跟踪、版本化和部署数据库变更。目前基于Maven插件将Liquibase集成到项目中,可以使数据库可持续开发部署管理。Liquibase配置文件通过Maven的profile,不同环境的数据库使用不同的Liquibase配置文件( local,dev,stg,prod),如下图所示changeLogFile=src/main/resources/db/changelog/db.changelog-ma.
摘要由CSDN通过智能技术生成

简介

Liquibase社区版是一个开源项目,可以帮助开发人员快速管理数据库架构更改。跟踪、版本化和部署数据库变更。目前基于Maven插件将Liquibase集成到项目中,可以使数据库可持续开发部署管理。

 

Liquibase配置文件

通过Maven的profile,不同环境的数据库使用不同的Liquibase配置文件( local,dev,stg,prod),如下图所示

changeLogFile=src/main/resources/db/changelog/db.changelog-master.xml

driver=org.postgresql.Driver

defaultSchemaName=minefocus

url=jdbc:postgresql://localhost:5432/demo

username=postgres password=123456

outputChangeLogFile=/var/data/liquibase/changelog/db.changelog-export.xml

diffTypes=tables,columns,views,primaryKeys,indexes,foreignKeys,sequences,data dataDir=/var/data/liquibase/changelog/csv

outputDirectory=target/docs

 

Liquibase目录结构

Liquibase的changelog文件放在resources/db/changelog目录下,如下图所示,我们只需要追加更改这些文件来更新数据库。db.changelog-master.xml是主文件,只用于包含文件,一般不做更改。根据修改类型:增加,修改,删除表对象和数据导入分别在各自文件添加。数据文件以csv格式放到csv目录下。

 

如果多次release,可以通过文件夹加版本号增加新的changelog文件。如:

master.xml

--release1.0.0

----release.xml

----add.xml

----update.xml

----remove.xml

----data.xml

----csv

--release1.0.1

----release.xml

----add.xml

----update.xml

----remove.xml

----data.xml

----csv

 

中小项目如果对changgelog都非常熟悉,可以用一个xml定义changelog。

 

大型项目可以按照模块划分目录结构,如

master.xml

--release1.0.0

----release.xml

----user.xml

----user.csv

----company.xml

--release1.0.1

----release.xml

----user.xml

----user.csv

----company.xml

 

以上仅供参考,根据项目情况可以自定义目录结构。

 

数据库changelog

1. changelog

有xml、yaml,json结构,根据需要选择其中一种,xml易读;yaml简洁;json介于前两者之间。

 

Tag

Description

preConditions

Pre-conditions required to execute the changelog. Read More

property

Value to set property to, if not set by another means. Read More

changeSet

The changesets to execute. Read More

include

Additional files containing changesets to execute. Read More

context

Context to be appended (using AND) to all changesets since 3.5

 

 

<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
                   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog 
                   http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd 
                   http://www.liquibase.org/xml/ns/dbchangelog-ext 
                   
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值