Liquibase problems, API and customization

Hi again.

My project is based on JPA (hibernate) + spring + spring web flow + richfaces + jboss as + MySQL

I’m using liquibase (built from trunk reverted before rc5) for 2 purposes:

  1. db migration. I have couple of problems here, some of them discussed in previous post:
  • some indexes for FK are not created (
  • diffdbtochangelog doesn’t work well with hibernate entities. Also it requires hibernate.cfg.xml file, but my project uses jpa (persistence.xml). Thats why I have an Ant target which uses the hbm2ddl to create a temporary schema from the entities and then I compare it with the current schema with diffdatabasetochangelog (works perfect)
  • I had to modify the ant task so I can specify the id and the author of the changesets.
  1. DB backup and restore
    The backup (dump) method uses code from ant the task GenerateChangeLogTask and diff.setDiffTypes(“data”);
    Here I have 3 problems with the existing code.
  • I need only one changeset for that changelog which I use as a dump file (currently there is a changeset for each table) and I need it to be alwaysRun=true.
    Btw there is a bug in XMLChangeLogSerializer#createNode: should be


    if (changeSet.isAlwaysRun()) {
               node.setAttribute(“runAlways”, “true”);

  • I need to specify my own id of the changeset so I have to add to DiffResult:
       public void setIdRoot(String idRoot) {        this.idRoot = idRoot;    }

       private String generateId() {
    return idRoot + (diffData ? “” : “-” + changeNumber++);

  • I have an issue with the generated changelog: I have a column which is ‘not null’ but on some entries it is empty. When I make the dump in generates :
and when I import the data from this file a mysql error occures that I cannot insert null into this column

To revert/restore data previously backed up with the described method above I do:

  1. delete all the data
  2. rollback to the changeset that the dump file is compatible with
  3. insert the data from the dump file
  4. migrate to the current schema (run the changeset that were rolled back on step 2)

For step 2 I need special method that rollbacks to a changeset with specified id wich is very similar to rollback(Date dateToRollBackTo, String contexts) except that I have to use my own ChangeSetFilter to defined which changesets should be rolled back. The problem is that I have to use some private members of class Liquibase like changeLogParameters. I tried to implement this method in my own class that extends Liquibase without using the private fields and it works since i don’t use different contexts.

So now I have to maintain my own version of liquibase which I don’t want to.
Is there any way to make liquibase API more friendly in my case?

Also I found a bug on datadiff. I have a string value in the db ‘\d\d\d’. In the xml file i get

and when I insert the data form the xml file to the db i get 'ddd'. There is some issue with the escaping of string values. I fixed it putting replace("\\", "\\\\") before writing to the xml file.

You have very good suggestions.  I applied them to trunk.

If you have changes you would like to make to the main liquibase codebase, feel free to send patches and/or commit directly to SVN.  I have the repository set up for anyone to commit and I will review all changes put in.  If you have a question on whether you should commit a particular change, or if there is a better way to implement something you can give me a patch and I can pre-look at it.