Idea Spring-boot maven下使用liquibase
官方文档#
https://docs.liquibase.com/tools-integrations/maven/home.html通过liquibase使用mysql#
https://docs.liquibase.com/workflows/database-setup-tutorials/mysql.html?Highlight=mysql 首先在pom.xml中引入liquibase的依赖<dependency> <groupId>org.liquibase</groupId> <artifactId>liquibase-core</artifactId> </dependency>
--driver=com.mysql.cj.jdbc.Driver --classpath=mysql-connector-java-8.0.22.jar --url="jdbc:mysql://bj-cdb-nivnaury.sql.tencentcdb.com:60991/lianmai?autoReconnect=true&useSSL=FALSE" --changeLogFile=db.changelog-1.0.xml --username=*****--password=*****


driver=com.mysql.cj.jdbc.Driver classpath=mysql-connector-java-8.0.22.jar url=jdbc:mysql://bj-cdb-nivnaury.sql.tencentcdb.com:*/lianmai?autoReconnect=true&useSSL=FALSE changeLogFile=src/main/resources/db/changelog/dbChangeLog.xml outputChangeLogFile=src/main/resources/db/changelog/outputChangeLog.xml username=* password=*
生成changelog命令#
https://docs.liquibase.com/commands/community/generatechangelog.html?Highlight=generateChangeLog踩坑过程#
首先要配置propertyFile属性,下面是我的目录结构以及propertyFile的属性配置
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<configuration>
<propertyFile>src/main/resources/liquibase.properties</propertyFile>
</configuration>
</plugin>






outputChangeLogFile=src/main/resources/db/changelog/outputChangeLog.xml




通过liquibase update命令使用changeLogFile文件更新数据库#
修改changeLog的路径

- 将changeset添加到变更日志。
- changeset由author和id属性唯一标识。
- Liquibase尝试执行事务中在最后提交的每个changeset。
<changeSet id="1" author="bob"> <createTable tableName="department"> <column name="id" type="int"> <constraints primaryKey="true" nullable="false"/> </column> <column name="name" type="varchar(50)"> <constraints nullable="false"/> </column> <column name="active" type="boolean" defaultValueBoolean="true"/> </createTable> </changeSet>
CREATE TABLE "department" ("id" number (*,0), "name" VARCHAR2 (50 BYTE), "active" NUMBER (1, 0) DEFAULT 1 );


DatabaseChangeLog 和 DatabaseChangeLogLock#




因为Liquibase只是从DATABASECHANGELOG表中读取数据以确定需要运行哪些变更集
所以如果对同一个数据库同时执行多个Liquibase实例,则会发生冲突。
如果多个开发人员使用同一个数据库实例,或者集群中有多个服务器在启动时自动运行Liquibase,则可能发生这种情况。
所以这个表是用来锁数据库的,避免多个开发人员同一时刻操作数据库的时候造成冲突 下图是四个字段的用途
回滚 maven Rollback#
官方地址 https://docs.liquibase.com/tools-integrations/maven/commands/maven-rollback.html?Highlight=rollback 三种回滚模式liquibase.rollbackCount
- 按顺序还原指定数量的变更集,从最新的变更开始,向后操作,直到达到指定的值liquibase.rollbackTag
- 还原被标记的数据库所做的所有更改liquibase.rollbackDate
- 恢复数据库所做的所有更改到指定的日期和时间
mvn liquibase:rollback -Dliquibase.rollbackCount=3
mvn liquibase:rollback -Dliquibase.rollbackTag=version1
<liquibase.tag>v3.2.1</liquibase.tag>
<liquibase.rollbackTag>${liquibase.tag}</liquibase.rollbackTag>
mvn liquibase:rollback -Dliquibase.rollbackDate=2020-11-26
作者:BigBender
出处:https://www.cnblogs.com/BigBender/p/14291077.html
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
2020-01-18 行列式的计算
2020-01-18 高中数学--圆锥曲线