Option to execute changeSets at last (e.g. for ForeignKeyCreate)

When a changeSet is created to add a foreignKey the target table has to exist. Depending on the organization of the changeSets it is possible (and often the case at our site) that the target table is not existing.

At our site we are using one file per table and using the includeAll-tag in the master.xml. This often leads to problems when a whole bunch of changesets is run against an older database (e.g. the one on the testing or production machines) because of foreignKeys to not-yet-existing tables.

We should have an option to defer the creation of the foreignkeys to the end of the execution.

We could do that using the context-feature but it is bad on handling. We thought about moving all foreignKey-changesets to a separate changelog but this is not very comfortable and hard to read.

The best way in my opinion is to add an option to the changeSet ‘deferedExecute’ (true/false).

Such a changeSet would be reordered to the end and get executed after all not deferCreated changeset had run.

Example:

master.xml:


table1.xml:

 create table table1


  add foreign key references table2

table2.xml

  create table table2

Without change liquibase would do the following order:
table1.xml/1
table1.xml/2 (which fails)
table2.xml/1

With the deferedExecute:

table1.xml/1
table2.xml/1
table1.xml/2 (reordered)

What are your thoughts about this?

Regards

Michael

It is an interesting idea.  I would probably make it a bet more general by adding some sort of a “executionPass” paramter that takes an int.  So you can set some as pass 1, some pass 2, some pass 3 etc.  When the the changeSet is parsed, it could group them by pass. 

I created a feature request for it (http://liquibase.jira.com/browse/CORE-550) though I won’t look at implementing it until at least teh 2.1 timeframe.

Nathan