Liquibase changelog parameters in liquibase.properties

冷暖自知 提交于 2019-12-22 05:15:24

问题


As per documentation parameter values are looked up in the following order:

Passed as a parameter to your Liquibase runner (see Ant, command_line, etc. documentation for how to pass them)

As a JVM system property

In the parameters block ( Tag) of the DatabaseChangeLog file itself.

Can I set these parameters in the standard properties file?


回答1:


It is possible to put changelog parameters in liquibase.properties, or a custom --defaultsFile. Reading the source indicates that you must prefix the properties with "parameter.".

Your error probably looks something like this:

SEVERE 11/4/16 10:26 AM: liquibase: Unknown parameter: 'read_only_user'
liquibase.exception.CommandLineParsingException: Unknown parameter: 'read_only_user'
    at liquibase.integration.commandline.Main.parsePropertiesFile(Main.java:453)

Example liquibase.properties:

driver=oracle.jdbc.driver.OracleDriver
url="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dbhost)(PORT=1600))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=devdb)))"
username=scott
password=tiger
defaultSchemaName=app_admin
promptOnNonLocalDatabase=false
parameter.read_only_user=app_read

Using the parameter in a changeset:

<changeset author="Ryan" id="1">
  <sql>GRANT SELECT ON APP.SOME_TABLE TO ${read_only_user}</sql>
</changeset>



回答2:


Yes, and is very usefull if you want to manage information under control...like passwords in differents enviroments: liquibase.properties:

parameter.pass_admin=idonthavepassword

and the changelog:

<changeSet author="rbs" id="create_user_admin" labels="inicial">
    <preConditions onFail="CONTINUE">
    <sqlCheck expectedResult="0">SELECT COUNT(1) FROM pg_roles WHERE rolname='admin'</sqlCheck>
    </preConditions>
    <sql>CREATE USER admin PASSWORD '${pass_admin}' LOGIN SUPERUSER NOCREATEDB NOCREATEROLE INHERIT NOREPLICATION CONNECTION LIMIT -1
        <comment>Creating admin user</comment>
    </sql>
</changeSet>



回答3:


Yes, it is possible: http://www.liquibase.org/documentation/liquibase.properties.html. And use --defaultsFile to pass property file.



来源:https://stackoverflow.com/questions/38915229/liquibase-changelog-parameters-in-liquibase-properties

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!