12

As far as I understand, Liquibase execute the changesets according to the order they are written in the change log. I want the changeset to be ran in another order. Is there any way to change the execution order of changesets?

A prompt response for my question would be highly appreciated.

Nava
  • 121
  • 1
  • 1
  • 3
  • 4
    Why don't you just reorder them in the XML file? –  Jan 27 '15 at 08:33
  • we don't reorder them in the xml because we orginize our changelog to be in separated xml files per each table that include the changesets of create table, create index, create foreighn key etc. and because we have some circular dependence tables we want the changeset to be ran in different order than they are written with. is it possible? – Nava Jan 28 '15 at 09:29
  • Then change the order of including them: first all `create table` XMLs (assuming that they do include the PK definition), then all `create index` XMLs and finally all foreign key XMLs (because at that time all tables will be created). That's the only way to break up scripts that deal with circular foreign key references –  Jan 28 '15 at 09:32

2 Answers2

4

The order of your changelog in Liquibase is the order that changes should be deployed (executed) if needed.

Liquibase relies on you to setup the correct order.

In order to use a dynamic order that matches the current situation you should use a compare & sync tools that will generate the relevant DDL based on your source control repository and your target environment.

Dbmaestro (for which I work) offers this feature

DBAstep
  • 61
  • 4
2

We had a smiliar approach. We had one xml file per table to have a good overview over every table and its columns. But when we needed to refactor(e.g. add new columns, move some data, add new FKs) our db, it was revealed, that this approach comes with some problems. The possibility to see what belongs to one table and the execution order are in conflict with each other. My best(but still dirty) solution was to start a single new xml file named migration_X.xml with all changeSets to add columns, copy some data, add new constraints or FKs. If I want to see the definition of one table, I generate the DDL.

lrxw
  • 3,576
  • 7
  • 32
  • 46