Branching Database Changes

We have a pretty big set of existing database changes.

Our initial schema creation script is over 1000 changeSet’s, and then we have 8 other “version” increments each stored in their own xml file, and consisting of between 30 and 100 changes each.

We managed this changeset during the development of our product, but recently have found that we need to make some major surgery.  To make this work we have created a new schema file that all NEW database created should run from.

But we do have a set of existing databases that we want to upgrade to match this structure.

I have all of the different upgrade statements, but I need to have liquibase selectivly run entire xml files based on the state of the system it is running against.

If I simplify this for an example lets say I have
 - file1.xml  (initial schema)
 - file2.xml
 - file3.xml
 - file4.xml
 - lastupgrade.xml
 - newschema.xml (the entire new schema)
 - anotherchange.xml

The scenarios I need to support are:
 * Any new database (ie has had NO changesets run against it) should run newschema.xml, then anotherchange.xml
 * A database that has run up to file2.xml should run, file3, file4, lastupgrade, then skip new schemea but run anotherchange.

Basically I created a new schema and put it in the ‘newschema.xml’ file, and created an upgrade from the old structure to new and put it in the ‘lastupgrade.xml’ file.

Hopefully this makes sense.  So now to what I’ve tried.

I’ve tried to add a preCondition to the top of file1 --> file4 saying don’t run this is file1-change1 has not been run.
But that doesn’t seem to work.

Is there anyother way do do this?  I don’t want to add a precondition to each changeSet as I have lots and lots of changeSets that I don’t want to bloat.

Sorry for the slow response.

Preconditions at the top of each file are collected into one master “before everything” precondition, so that is why that approach will probably not work for you. 

One option is to do 3 independent executions of liquibase. One for file1-4+lastupgrade, one for newschema, one for anotherchange. If you can make what executes liquibase conditional on querying the database, that would be easiest.

An alternate option could be to create a custom ChangeLogParser ( which overrides the default XmlChangeLogParser. It would call the parent paser to get the DatabaseChangeLog object, then check the state of the database and trim the object down based on the current state. I haven’t tried doing this, but it should be possible.