Different paramaters in one liquibase .properties file possible?

Hey all I am wondering if its possible to place different .properties inside just one .properties file so that I do not have to make a seprate .praperties file for each of my database?

This site here is doing what I would like to do but it doesnt explain how to go about sending those contexts to the .properties file. And it also seems to be using seprate .properties files. As in, it doesnt show me how it should look inside the .properties file. Another good example is here but again, it doesnt do it in the .properties file.

Let’s say I have the following inside my .properties file:

#liquibase.properties file content
url: jdbc:oracle:thin:@xxxxxxxx.str3.xxxxx.xxxxx:1511/xxxxxx.xxxxx.xxxxx.xxxxx
username: SEPRATE_1PEGA_BASEDA
password: XXXXXXXXXXXXX
referenceUrl: jdbc:oracle:thin:@xxxxxxxx.str2.xxxxx.xxxxx:1511/xxxxxx.xxxxx.xxxxx.xxxxx
referenceUsername: SEPRATE_1PEGA_BASEDB
referencePassword: YYYYYYYYYYYYYY
changeLogFile: diff_change.txt
diffTypes: tables, views, columns, indexes, foreignkeys, primarykeys, uniqueconstraints

And I am wanting to send a paramater to replace the “str2” and “SEPRATE_1PEGA_BASEDB” varibles currently hard-coded inside the .properties file. So I write the .properties file like so:

#liquibase.properties file content
url: jdbc:oracle:thin:@xxxxxxxx.str3.xxxxx.xxxxx:1511/xxxxxx.xxxxx.xxxxx.xxxxx
username: SEPRATE_1PEGA_BASEDA
password: XXXXXXXXXXXXX
referenceUrl: jdbc:oracle:thin:@xxxxxxxx.${liquibase.properties.str}.xxxxx.xxxxx:1511/xxxxxx.xxxxx.xxxxx.xxxxx
referenceUsername: ${liquibase.properties.un}
referencePassword: YYYYYYYYYYYYYY
changeLogFile: diff_change.txt
diffTypes: tables, views, columns, indexes, foreignkeys, primarykeys, uniqueconstraints

So would the CLI for this look like:

liquibase --str=str5 --un=BobBarker diff

My liquibase version is Liquibase-3.6.2.

just bumping in hopes someone knows how to do this. :grinning:

hey tdgfbi,

I think this thought: " This site here is doing what I would like to do but it doesnt explain how to go about sending those contexts to the .properties file."
is super close to your answer.

further down in that same page, the author mentions using TWO properties files, suffixed based on context, and passing the right one in via the command line.

When running liquibase command, we need to tell the relevant properties file to use:

liquibase --defaultsFile=liquibase_development.properties --contexts=development update
liquibase --defaultsFile=liquibase_production.properties --contexts=production update

you could certainly automate this with a variable equal to context and using that in the CLI, for example say you were calling it from a bash script:

CONTEXTVAR=“production”
liquibase --defaultsFile=liquibase_$CONTEXTVAR.properties --contexts=$CONTEXTVAR update

but obviously you could tweak that for whatever scripting language you need.

you could also do the same drawing the var from ENVironment variables, too, if you are building liquibase calls to the cli from an external source like bash or python, etc.

hope this helps,
mario

1 Like