Using context for development-only and production changesets

I have the following scenario:

Some changesets are only valid in the development environment. I do not want to run these changes in production environment. The rest of the changesets are valid both in development and production environment.

I had an idea of that I would mark the development changesets with context=“dev”. If I do not specify any context when running a liquibase command all changesets will be executed regardless of what context is set on changesets.

But, how do I do if I want to run only the changesets that are of interest for the production environment?
Do I have to mark all production-only changesets with context=“prod” to accomplish this?  Production-only changesets are in a vast majority which would mean a lot of work to mark all those.

If I understand this right, wouldn’t it be better that when giving no context all changesets with no context, i.e. default context so to say, would be run. But if I want both those with context specified and “default context” specified, I would specify “default,test” to be both to be run.

Best regards /Lasse

I just mark the development changeSets as “dev” and don’t specify a context on the changesets that run in both.  When I do an update on production, I will specify contexts=prod in the update even though there are no changesets marked as prod.  That will make it skip all the dev context ones but will still execute all the non-context-ed changeSets.  You are also then set up for some point in the future where you need to make a context=“prod” changeSet that does not run in dev but only run in prod.

Nathan

1 Like

Great… Now I see the light  8)

We have a bunch of developers adding changeSet’s. When they add changeSets to the test-specific xml-file that belong to context=“test” they have to remember to add context=“test” to each changeset they add (maybe they forget). If they don’t we risk to get it in production.

I was looking for a possibility to add context=“test” to the databasechangelog-tag.

Alternatively, that I could have an include-tag inside a changeset and in that way mark that changeset=“test”.

Any clues?

Adding it to databaseChangeLog is a good idea, but it is not supported currently. I added http://liquibase.jira.com/browse/CORE-793 for 2.1 possibly. runs outside a changeSet, so that won’t work either. 

The best I can come up with is having a pre-processing step that adds a context=“test” to all the changeSet tags in your test changelogs before passing them to liquibase.  Not the nicest, but it would work.  You could also create a custom  XMLChangeLogSAXHandler subclass that overrides the handleChangeSet() method and adds the context depending on the file.

Nathan

I am using 1.9.x maven plugin. I have tried to specify dev in my pom.xml.

I have marked some of my changeSet’s with context=“dev” like this.

    ....

When I run my maven command at the prompt (command = updateSQL) I get all my changesets into migrate.sql. Not only the once marked with context=“dev”.

Am I missing something?

Best regards
/Lasse

Any input for this one? Thx /Lasse

I don’t use maven to know for sure the syntax.  The javadoc says @parameter expression="${liquibase.contexts}" default-value=""

Nathan

Originally posted by: Nathan
I don't use maven to know for sure the syntax.  The javadoc says @parameter expression="${liquibase.contexts}" default-value=""

Nathan

Thank you, I think this is correct.
I discovered that the parameters need to be prefixed by “liquibase.” Thank you.

Then a question:
When looking at the page below I find parameters as contexts, driver, changeLogFile etc. Is it some kind of some convention to add something at beginning of each parameter as in this case contexts => liquibase.contexts. If this is not the case it is somehow confusing to name the parameters as driver at the beginning of the link below and then when you read the page more thoroughly you’ll find that each parameter is prepended with liquibase..

Best regards /Lasse
http://liquibase.org/manual/maven_updatesql

Lasse, I think liquibase maven support is not full complement with command line options.
you could see current state on that using maven help:describe command
Try to view full description of the currently implemented options:

    mvn help:describe -Dplugin=org.liquibase:liquibase-maven-plugin -Ddetail
Originally posted by: taranenko
Lasse, I think liquibase maven support is not full complement with command line options. you could see current state on that using maven help:describe command Try to view full description of the currently implemented options:
    mvn help:describe -Dplugin=org.liquibase:liquibase-maven-plugin -Ddetail

Yes, thx.

However, didn’t find the info on the comman line page but in the maven plugin docs  ::slight_smile: http://liquibase.org/manual/maven_updatesql

I am using 1.9.x so creating an extension of XMLChangeLogSAXHandler is only doable for 2.x-users right?