如 property-substitution 中所写,您可以使用
-D
前缀将属性传递给 liquibase 命令 CLI(或者您可以使用其他方法),因此类似 -Dproperty-name=somevalue
的内容,然后在您的 changeSet/sql 中将其用作 ${property-name}
.
cmd:
liquibase update -Dpguser=myuser
<changeSet author="xxxxx" id="1682329977552-1" context="unittest">
<preConditions onFail="CONTINUE">
<sqlCheck expectedResult="1"> SELECT COUNT(*) FROM pg_roles WHERE rolname='${pguser}';</sqlCheck>
</preConditions>
<sqlFile dbms="!h2, oracle, mysql, postgresql"
encoding="UTF-8"
endDelimiter="\nGO"
path="db_grants.sql"
relativeToChangelogFile="true"
splitStatements="true"
stripComments="true"/>
</changeSet>
grant select on all tables in schema public to ${pguser};
grant insert on all tables in schema public to ${pguser};
grant delete on all tables in schema public to ${pguser};
grant update on all tables in schema public to ${pguser};