问题
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
.
回答1:
So if I understand your need properly, you would like to replace placeholders inside your property files.
There are 2 things you should think of:
- changelog parameter substitutions - I didn't tested that but if you define property
parameter.testproperty=originalvalue
and then you put on commandline-Dtestproperty=overridenvalue
it could probably replace your value and you will be able to use it in changelogs - liquibase configuration parameters substitution - Liquibase is not doing this, because it's reading properties just like they are in file (method
parsePropertiesFile
last if/else) and it's trying to fill fields in java with that values. So for this you will need to replace placeholders before calling liquibase command or use different property file.
来源:https://stackoverflow.com/questions/64471150/different-paramaters-in-one-liquibase-properties-file-possible