I started playing with Liquibase two days ago on June 24. I wanted to take advantage of Liquibase’s ability to generate database schema upgrade DDLs given an existing database and Hibernate mapping files. This capability was new in Liquibase 1.6. I downloaded version 1.6.1 on June 24.
My ultimate goal was to integrate Liquibase into our Ant-based build system, so I started exprimenting with Liquibase’s Ant tasks, specifically diffDatabaseToChangeLog and updateDatabase. The diffDatabaseToChangeLog task kept complaining about not finding the Hibernate mapping file, so I switched over to Liquibase command line interface hoping for more luck. After a few hours of tinkering, including changing command line’s CLASSPATH environment variable and liquibase.bat’s CP variable to include the path to hibernate file, I managed to generate a Liquibase change log. Along the way I realized that Hibernate file needed to be in the CLASSPATH to be visible to Liquibase.
Still the Liquibase diffDatabaseToChangeLog Ant task refused to work. I tried adding the Hibernate mapping file path to Ant script’s classpath variable but it didn’t seem to help.
Next day morning (June 25) I continued working with Liquibase in Ant. I focused on Ant’s classpath variable based on my experience from the day before. A night’s rest certainly helped with investigation, for I quickly I found the problem on that fresh morning. Turned out the command line environment variable CLASSPATH, which I had set the day before for liquibase.bat, was confusing Ant (http://ant.apache.org/manual/install.html#classpath). I removed CLASSPATH and finally got my Liquibase change log.
It was barely 30 minutes of joy and celebration before I bumped into another wall. This time Liquibase threw an exception when analyzing MySql’s views. It ran a query select view_definition from information_schema.view where table_name=’foobar’ and table_schema=’null’ and threw up when no rows were returned. No rows were returned because of the table_schema=’null’ clause. The query was wrong.
After lunch I wandered back to Liquibase’s webpage, only to find that a new version was released. When I downloaded Liquibase one day earlier (June 24), the latest version was 1.6.1. Version 1.7 was released on June 25. I downloaded the new latest version, and low and behold, the MySql view analysis problem went away.
Despite finally getting Liquibase to work with Ant, MySql, and Hibernate mappings, in the end I decided against using Liquibase in our system. I found Liquibase to be much more extensive over Hibernate’s hbm2ddl when it came to database differences. Unfortunately, it (as of version 1.7) had some quirks which make it unreliable for our needs.
Example 1:
We had a column ‘foo’ which was defined with length 100000 in Hibernate. Hibernate’s SchemaExport created the column as mediumtext, but Liquibase generated DDLs of column type varchar(100000) literally. The DDL then failed to execute because length 100000 exceeded varchar’s limit.
Example 2:
There were additional constraints that weren’t captured by Liquibase. Constraints such as auto-increment on identity columns, column uniqueness were not in the DDLs I generated.