Strange script execution order with combined yml and sql file includes

I seem to have a strange issue with the ordering. I’m using multiple yml files for the databaseChangeLog listing. I want to have a script run before and after all other scripts so for this I have the following setup in 1 yml file

  - include:
      file: CreateTempSproc.sql
      relativeToChangelogFile: true
  - include:
      file: scripts.yml
      relativeToChangelogFile: true
  - include:
      file: DropTempSproc.sql
      relativeToChangelogFile: true

The scripts.yml file contains a whole load of includes for individual sql files which will use the stored procedure created and dropped either side of it. However, in the change log table I’m seeing the sql files from within this yml executing and then those from the scripts.yml file

Is there a better method to ensure this kind of sequence for executing my scripts?

Why am I doing this?
I’m not a fan of 100s or 1000s of insert scripts and prefer to use a stored procedure to insert the data. I find this a much more maintainable method of inserting data. Imagine a change to the table and having to update all the insert scripts

Hello, @dbegent,

Looking into this, there isn’t anything in the diff/snapshot functionality to manage the ordering of inserts. The main reason is that data diff is enough outside the primary scope of Liquibase that it doesn’t make sense to start dealing with all the difficult logic that would be required to figure the correct insertion order (which may not be possible, if you have circular references). When you do a snapshot generation, we include the data insert before the FK creation so it will load correctly.

Please let me know if you have additional questions.


@dbegent Is this behavior happening on an initial deployment, where none of the scripts have executed in the database before, or is this on a subsequent deployment where you have runOnChange=“true”?