using custom properties in changelogs

Although I’m an advanced Liquibase user, I’m stumped when it comes to using custom properties in changelogs using the Liquibase Maven plugin.

Right now with my Ant project, I’ve got changelog entries like the following:

   
   

And within that changelog, I insert ${schemaname} and ${tablespace} within changesets, for example:

       

However, I don’t want to have to keep manually modifying changelogs each time I run Liquibase, so right now I am trying to get this simple functionality to work with Maven filtering.

Getting filtering to work is easy. In checking the project target, the above entries are filtered correctly. However, the Liquibase Maven plugin seems to be looking at the source rather than the target when processing, so the database driver complains that there are invalid characters in the SQL (the “$” and “{” characters obviously are not expected by the database).

I’ll really appreciate any help someone can offer on this topic. Is there a way to pass in custom properties to changelogs without actually putting them in the changelogs? It doesn’t make sense to keep changing the source code, and it would seem that using Maven filtering would be the solution to this issue.

I’ve seen several posts about the standard “driver”, “classpath”, and “url” etc properties that are needed for liquibase.properties, but nothing about custom properties. Alternatively, if the Liquibase Maven plugin does not offer this functionality, I’ll appreciate any other solutions you might have. Thanks very much.

My apologies, I had intended to reply to my own discussion here later last week, but was fairly swamped at work. The solution was actually very straightforward and simple, but the documentation is very light in this regard.

After much trial-and-error, it became apparent that it was rather unlikely to come to a solution with the Liquibase Maven plugin, so I ended up installing Maven and setting up a series of scripts to be executed at the command line (I had been using M2Eclipse).

Each of the scripts references a Maven profile, and properties are passed in at that level. Here’s an example:

mvn resources:resources “-Dschema=nameofschema” liquibase:update -Pupdateschema

Here, the profile “updateschema” in the pom.xml is referenced along with the “update” liquibase goal. Property value “nameofschema” is passed in to substitute each occurrence of ${nameofschema} within the changelog.

That’s it. To my knowledge there is no other way to pass in custom properties when using Liquibase. Custom properties based on my experience cannot be passed in via liquibase.properties files; only the small set of properties defined by Liquibase, such as “url”, “driver”, etc are accepted via these files.

I’ll put together some more complete examples in one of my next blog installments of “Liquibase in the Enterprise” at the following location: http://www.erikgfesser.com/  Click on “software development” or “enterprise architecture” in the categories cloud. There are quite a few misleading posts on this subject out there, so I’m hoping this post will help lay some of these to rest.

One more thing. Maven filtering is not a solution because the filtering happens after the Liquibase goal is executed, not before.

Precede your ${property} references with a backslash to get them past Maven resource filtering.

Best,
Laird

I haven’t done much with the maven plugin code or maven itself, so I was hoping someone else would chime in. 


What version of liquibase are you using? I know there have been improvements in 2.0. The custom properties can come from system properties as well, so if you can set system properties in maven you can use them as changelog paramteters.


Nathan

In this case, Maven resource filtering is desired. Although it works, the resultant filtered files are placed into the project target, so unless I explicitly point Liquibase to target, Liquibase does not see the filtered files. And if changelogs etc in another folder are referenced, the databasechangelog primary key values are altered and everything ends up being a complete mess. If anyone sees an alternate solution to passing in non-Liquibase properties other than via the Maven command line, please let me know.

I have been able to get maven filtering to work with my liquibase project without doing anything special.   I believe getting it to work has to do with setting up your plugin configuration and executions correctly.   Setting it up this way I do not have to explicitly say the resources are coming from target, it simply uses the target.  Here is my pom.xml.