Liquibase 根据表名前缀在 db 上生成更改日志



我可以根据表名前缀从数据库生成 Liquibase 更改日志吗?

例: 如果我有一个数据库架构并且它有以下表:

abc
abcd
abcdef
xyz

我只想为以"abc"开头的表生成更改日志。所以表的更新日志

ABC, ABCD, 阿克德夫

如果有办法做到这一点,有人可以帮助我吗?

这对我Windows 10有用:

liquibase.properties

changeLogFile=dbchangelog.xml
classpath=C:/Program Files/liquibase/lib/mysql-connector-java-8.0.20.jar
driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/liquibase?serverTimezone=UTC
username=root
password=password
schemas=liquibase
includeSchema=true
includeTablespace=true
includeObjects=table:persons

C:\用户\用户名\桌面>liquibase generateChangeLog

Liquibase Community 4.0.0 by Datical
Starting Liquibase at 11:34:35 (version 4.0.0 #19 built at 2020-07-13 19:45+0000)
Liquibase command 'generateChangeLog' was executed successfully.

您可以在此处下载mysql连接器,在此处查找generateChangeLog文档,在此处查找有关includeObjects的更多信息。

如果您使用的是 liquibase 版本 3.3.2,则可以使用 maven 或 liquibase 命令行>。

查看发行说明

Liquibase 3.3.2正式发布。它主要是一个错误修复 发布,但有一个主要的新功能:对象 diffChangeLog/generateChangeLog 对象过滤。 includeObjects/excludeObjects 逻辑

您现在可以在 命令行或 Ant。对于 maven,参数是 diffExcludeObjects 和 diffIncludeObjects。这些参数的格式为:

An object name (actually a regexp) will match any object whose name matches the regexp.
A type:name syntax that matches the regexp name for objects of the given type
If you want multiple expressions, comma separate them
The type:name logic will be applied to the tables containing columns, indexes, etc.

注意:名称比较区分大小写。如果你想要麻木不仁 逻辑,使用 (?i( 正则表达式标志。

示例筛选器:

“table_name” will match a table called “table_name” but not “other_table” or “TABLE_NAME”
“(i?)table_name” will match a table called “table_name” and “TABLE_NAME”
“table_name” will match all columns in the table table_name
“table:table_name” will match a table called table_name but not a column named table_name
“table:table_name, column:*._lock” will match a table called table_name and all columns that end with “_lock”

因此,请尝试使用excludeObjectsincludeObjects参数与generateChangeLog命令

一起使用更新

我使用了liquibase命令行,这个命令可以解决问题(对于mysql数据库(:

liquibase 
--changeLogFile=change.xml 
--username=username 
--password=password 
--driver=com.mysql.cj.jdbc.Driver 
--url=jdbc:mysql://localhost:3306/mydatabase
--classpath=mysql-connector-java-8.0.18.jar 
--includeObjects="table:abc.*" 
generateChangeLog

最新更新