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.
create table table1 add foreign key references table2
table2.xml create table table2
Without change liquibase would do the following order:
table1.xml/2 (which fails)
With the deferedExecute:
What are your thoughts about this?