gpt4 book ai didi

mysql - 强制设置 liquibase 更新日志参数

转载 作者:行者123 更新时间:2023-11-29 01:53:36 25 4
gpt4 key购买 nike

我在我的 liquibase 更新日志中也定义了 grant 语句。我还需要用户和主机是可变的,所以我使用 changelog 参数将其定义如下:

    <changeSet id="exampleuser_grants_tbl_example" author="me">
<preConditions onFail="MARK_RAN">
<tableExists tableName="tbl_example" />
</preConditions>
<sql>
GRANT INSERT, UPDATE, DELETE
ON `tbl_example` TO '${grants.user}'@'${grants.host}';
</sql>
</changeSet>

然后我可以在命令行中运行 liquibase 时定义参数:

-Dgrants.user=exampleuser -Dgrants.host=examplehost

但是当我忘记定义这些参数时,它不会给出任何关于此的错误。在 GRANT 语句中使用它之前,MySQL 不需要用户存在吗?我可以添加一个先决条件来检查用户是否存在,但这并不能真正完全解决问题,因为可能未设置主机参数。

有没有办法在使用更新日志文件之前强制设置参数?

编辑

好的所以我修复了它感谢下面的答案如下:

在我添加的更改日志文件的顶部

<preConditions>
<changeLogPropertyDefined property="grants.user" />
<changeLogPropertyDefined property="grants.host" />
</preConditions>

如果未设置主机参数,现在会出现以下错误:

1 个先决条件失败

.../changelog-master.xml : Changelog property 'grants.host' was not set


至于为什么我的 MySQL 服务器在为名为 ${grants.user}@${grants.host} 的用户创建授权时没有生成任何错误的问题:

http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_no_auto_create_user

最佳答案

在这里查看 changeLogPropertyDefined 前提条件 http://www.liquibase.org/documentation/preconditions.html .还有一个 customPrecondition 标记,因此您可以在 Java 中实现任何自定义逻辑。

关于mysql - 强制设置 liquibase 更新日志参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34808932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com