changeset with multiple context

Hi all,

I have a changeset that i would like to execute when a pair of contexts are allowed. For example:


       
           
           
       
   

According the documentation, http://www.liquibase.org/documentation/contexts.html, we can configure a changeset to be executed only when multiple contexts are satisfied.

context=”!qa and !master”


I execute the liquibase update by Java code as follow:

       connection = DriverManager.getConnection(url + schema, userName, password);
            Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
            database.setDatabaseChangeLogTableName(“databasechangelog”);
            database.setDatabaseChangeLogLockTableName(“databasechangeloglock”);
            liquibase = new Liquibase(changeLogPath, new ClassLoaderResourceAccessor(), database);
            liquibase.update(“local,TEST”);


But this changeset is never executed…do you know what i am doing wrong?


Thanks!

Which version of Liquibase are you using? If you are not using a version that you have built yourself from github, then you do not have this feature yet. The docs got a bit ahead of the code. 


It will be in the next release of Liquibase (3.2.0), which should be Real Soon Now.

Steve Donie
Principal Software Engineer
Datical, Inc. http://www.datical.com/

Thanks for your fast response Steve.

I am using 3.0.5 version. But when I read in the documentation that the context combination are available, i thought this feature was available.

With the current liquibase version, do you know some way to mix several contexts in the same changeset?

Thanks again

Hi Nathan,

Thanks for your response.

In my current case I will have to wait to the 3.2.0 release.

Or maybe implement some particular just for controlling that all changeset’s contexts are used in the liquibase update(“local,test”);


With the current version, you can comma separate contexts in your changeSet which acts as an OR. So 


  1. Nathan

Unfortunately with 3.1 your custom precondion will not work either because there is no reference to the running contexts in the objects available to the precondition check method. That is something else that is new in 3.2 as well :slight_smile:


You could use a custom precondition that checks system properties, hostnames, or other things that may give you the info you need, though.


Nathan

Note: 3.2.0 is now available.


Nathan

Hi,

do the context combinations work in sql-changesets? I could not get it working, tried different ways:
– changeset erik.petzold:1 context:A and B
this one is executed, even when only context A is specified

– changeset erik.petzold:2 context:(A and B)
this one cannot be parsed: Unexpected error running Liquibase: Cannot parse context pattern (A

– changeset erik.petzold:3 context:“A and B”
– changeset erik.petzold:4 context:'A and B’
these ones are never executed, even if both contexts are active

Is there another syntax or is this feature not implemented?
Thank you

Hi,

in xml it works fine for me too (calling liquibase from command line).
But I don’t get it running in liquibase formatted sql files.
http://www.liquibase.org/documentation/sql_format.html

Thanks Nathan

Hi Erik,

I used the liquibase version 3.2.0 and works.

The syntax would be something like you have:


       
           
           
       
   



And when i call the liquibase library i use the method update(contexts);

Where contexts is a string splitted by , with all the available contexts.

I hope this can help you

Could you send an example?

Maybe you need “convert” those sql files to XML format?

I would prefer not to convert them. Our developers are used to sql files and we don’t need db-vendor independence or something like this, so the annotated sql files are a good way for us.
As the simple contexts work there, it would be nice if the combined would also.


I see where the problem with formatted sql and context expressions happens. 

I created https://liquibase.jira.com/browse/CORE-1969 to track the fix.

Nathan