Question about generateStatement() being executed multiple times



I’ve been trying to tweak liquibase to add a sql statement capability to the loadData action to generate a value based on other data in the db.  For example, determining a foreign key value by doing something like this in a element:


   <column name=“CUSTOMER_ID” type=“NUMERIC” select=“select customer_id from customer where name like %customer_name%”


   …(other columns)


and then in the csv I could have data like this:



,“ABC Corporation”,


So, any column with a type of “DATA” is not pumped into the insertStatement being generated.

And - for the select - the %xxx% allows reference to any column in the current line.


So - enough for background.  I’ve got it basically working.  The problem I’m encountering is that the LoadDataChange.generateStatements() method, where I implemented the select, is invoked three times - the first two times before any actual data has been loaded for the changeSets in the databaseChangeLog.


So - I can’t just throw an exception when the select statement fails (i.e. on “Empty result set, expected one row”).  Instead, I have an ugly warning written to the console like this:


[updateDatabase] Warning - ‘select’ statement failed, message Empty result set, expected one row
[updateDatabase] This warning may appear a couple of times.  If your changeLog doesn’t actually run, then this probably a real error.
[updateDatabase] This has to do with the way Liquibase handles the changesets - multiple passes through, first pass before any of the changeSets have executed


So - finally - the question.  Anyone have any suggestions on a better approach than this?  One thought I had was to introduce a parameter to the generateStatement indicating that “I’m really about to run this code” vs “I’m just checking”.


I’m working with Liquibase 2.0.




Bob Sandiford


I think something needs to be added/changed in the interface so generateStatements is called only once or you can tell why it is being requested. I don’t know of a better way currently

I created to track the feature