Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Liquibase changelog parameters in liquibase.properties

Tags:

liquibase

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?

like image 892
Amit Avatar asked Aug 12 '16 10:08

Amit


2 Answers

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>
like image 184
ryanhos Avatar answered Nov 05 '22 03:11

ryanhos


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>
like image 40
hsurfer Avatar answered Nov 05 '22 03:11

hsurfer