Why are all contexts executed when non specified on update?

This is just how Liquibase works - if you do an update and don't specify a context, then all changesets are considered as applicable to that update operation.

There were a couple of ways that this could have been implemented, and the development team had to pick one.

  1. if you don't specify a context during an update operation, then no changesets are considered.
  2. if you don't specify a context, then all changesets are considered.
  3. if you don't specify a context, then only changesets that have no context are considered.
  4. if you don't specify a context and none of the changesets have contexts on them, then all changesets are considered, but if some of the changesets do have contexts, go to option 1, 2, or 3 above.

The team could have gone with option 3 (which matches your expectation) but decided long ago to go with option 2, as that seemed like the 'best' way at the time. I wasn't on the team at that time, so I don't know any more than that.


I will add solution from me (from my perspective the default Liquibase behavior is not intuitive). In our project to deal with the "problem" we configured liquibase context in this way:

liquibase.setChangeLog("classpath*:liquibase/master.xml");
contexts = StringUtils.isBlank(contexts) ? "none" : contexts;
liquibase.setContexts(contexts);

It cause that liquibase will run all change-sets with context 'none' and all default change-sets (change-sets without context) - yes this is how it works.

So select the name which nobody on your team won't use ('none' in our case) as context name and then run the liquibase by default with that context (take a look at example). With that approach you will run the change-sets without any context what I assume should be default approach!

Tags:

Liquibase