1

We are using liquibase for our database versioning. We use it to deploy the database changes to any layer e.g TST,AT and PROD.We build once and deploy the same changes to everywhere but we have certain things which should be deploy to specific layer.I am not sure whether this is possible or not

e.g.

Let’s say we store app URL in the DB and each environment (INT, UAT, PROD) has it’s own different app URL. How can we do this using liquibase script?

unknown
  • 1,815
  • 3
  • 26
  • 51

1 Answers1

5

You can use the contexts and labels attributes available to changesets and commands to accomplish what you want.

This Liquibase blog post goes into detail. Here is a quote from that article describing Contexts:

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.

SteveDonie
  • 8,700
  • 3
  • 43
  • 43