运行 liquibase 脚本的环境特定更改

Run Environment specific changes from liquibase script

我们正在使用 liquibase 进行数据库版本控制。我们使用它来将数据库更改部署到任何层,例如 TST、AT 和 PROD.We 构建一次并将相同的更改部署到所有地方但是我们有某些东西应该部署到特定的 layer.I 我不确定是否这可能与否

例如

假设我们将应用程序 URL 存储在数据库中,并且每个环境(INT、UAT、PROD)都有自己不同的应用程序 URL。我们如何使用 liquibase 脚本来做到这一点?

您可以使用可用于变更集和命令的 contextslabels 属性来完成您想要的。

This Liquibase blog post goes into detail.引用描述上下文的那篇文章:

Contexts in Liquibase have been available for quite a while, and they started out primarily as a way of “tagging” changeSets so they can be chosen at runtime. One common use is to mark changeSets that insert test data as context=”test” so that in your development and QA environments you you can run liquibase with –contexts=test to get the test data and in production you run with –contexts=prod to not have test data. Contexts are also helpful for marking changeSets based on feature sets to include (context=”shoppingCart”) or bundle (context=”pro”) or even customer (context=”acme_inc”). For complex cases, multiple contexts can be applied to a changeSet such as context=”acme_inc, pro” and multiple contexts can be chosen at runtime such as –contexts=free,qa.

With Liquibase 3.2, support was added to for context expressions in changeSets. Now, when you are defining your changeSet you can specify complex logic such as context=”!test” or context=”qa or (acme_inc and dev)”. The context logic can only be specified in your changeSet definition, however. When running Liquibase, you can still specify multiple contexts, but you are just listing out all the contexts that apply to the current Liquibase run.