I’m trying to launch Liquibase programatically and I’m running into some trouble. Using 2.0 RC7, I’m trying to use the following code to launch Liquibase and run a group of changes. Has anyone seen seen a similar issue, and if so, how did you work around it?
For reference, LIQUIBASE_SCRIPT_LOCATION = “conf/Database2.xml”
Liquibase liquibase = new Liquibase(LIQUIBASE_SCRIPT_LOCATION, new FileSystemResourceAccessor(), new JdbcConnection(conn));
liquibase.exception.ChangeLogParseException: Error Reading Migration File: null
at liquibase.parser.core.xml.XMLChangeLogSAXParser.parse(XMLChangeLogSAXParser.java:91)
at liquibase.Liquibase.update(Liquibase.java:105)
Apparently the behavior of XML entities has changed in Liquibase 2.0. I had to change the location in the !ENTITY element from relative to the working directory to relative to the xml file.
When we first started using liquibase, we kept everything in one file. Eventually we split every thing out into separate files for new releases. Due to some issues with the filename in the database change log table, the original changes had to maintain the first file name.
To do that we used a !ENTITY tag that pointed to the original changesets and imported them using an entity reference (ie: &referenceName). However, the default java resolver uses the pwd for relative paths, so we had to include an additional folder in the path compared to the files that we included using the tag.
Let me know if you need me to explain more or try to work up a small example.
I think I see what the issues were. It is generally best to use the tag, there is a logicalPath attribute available on the root databaseChangeLog tag that allows you to override what liquibase considers to be the “file name” for the changesets in the changelog. That will allow you to move your changesets to other files, or move changelog files around while keeping backwards compatibility.
It’s definitely better to use the include tag, and we use it for everything other than this one legacy file. You may want to note the change in the liquibase 2.0 upgrade guide.