强制设置 liquibase 变更日志参数
Force liquibase changelog parameters to be set
我在我的 liquibase 变更日志中也定义了授权语句。我还需要用户和主机是可变的,所以我使用 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
但是当我忘记定义这些参数时,它并没有给出任何关于此的错误。
MySQL 在 GRANT 语句中使用它之前不需要用户存在吗?
我可以添加一个先决条件来检查用户是否存在,但这并不能完全解决问题,因为主机参数可能未设置。
有什么方法可以在使用更改日志文件之前强制设置参数吗?
编辑
好的,我修复了它,感谢以下答案:
在我添加的更改日志文件的顶部
<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.
中实现任何自定义逻辑
我在我的 liquibase 变更日志中也定义了授权语句。我还需要用户和主机是可变的,所以我使用 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
但是当我忘记定义这些参数时,它并没有给出任何关于此的错误。 MySQL 在 GRANT 语句中使用它之前不需要用户存在吗? 我可以添加一个先决条件来检查用户是否存在,但这并不能完全解决问题,因为主机参数可能未设置。
有什么方法可以在使用更改日志文件之前强制设置参数吗?
编辑
好的,我修复了它,感谢以下答案:
在我添加的更改日志文件的顶部
<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.
中实现任何自定义逻辑