一个liquibase .properties文件中的不同参数可能吗? [英] Different paramaters in one liquibase .properties file possible?

查看:145
本文介绍了一个liquibase .properties文件中的不同参数可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我想知道是否有可能将不同的.properties放在一个.properties文件中,这样我就不必为每个数据库创建一个单独的.praperties文件?

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?

此网站这里正在做我想做的事情,但没有说明如何将这些上下文发送到.properties文件.而且它似乎也正在使用单独的.properties文件.如上所示,它没有向我展示它在.properties文件中的外观.另一个很好的示例在这里,但是再次它不会在.properties文件中执行此操作.

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.

假设我的.properties文件中包含以下内容:

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

我想发送一个参数来代替"str2".和"SEPRATE_1PEGA_BASEDB";当前在.properties文件中进行硬编码的变量.所以我这样写.properties文件:

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

CLI如下所示:

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

我的liquibase版本是Liquibase-3.6.2.

My liquibase version is Liquibase-3.6.2.

推荐答案

因此,如果我正确理解您的需求,则希望替换属性文件中的占位符.

So if I understand your need properly, you would like to replace placeholders inside your property files.

您应该想到两件事:

  • changelog参数替换-我没有测试过,但是如果您定义属性parameter.testproperty=originalvalue然后放在命令行-Dtestproperty=overridenvalue上,它可能会替换您的值,并且您将能够在changelogs中使用它
  • liquibase配置参数替换-Liquibase不会这样做,因为它正在读取属性
  • 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.

这篇关于一个liquibase .properties文件中的不同参数可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆