How to generate insert statements in separate changeSets via generateChangeLog with --diffTypes=data

Given this scenario:

  • existent database (SQL Server, however can be of MySQL also, RDBMS doesn’t matter that much at this point) with one table tblA.
  • tblA has two rows
  • for migrating the data via Liquibase, a generateChangeLog call is made with parameter valued --diffTypes=data.
  • the output of the call is a changelog containing one changeSet containing two insert statements.

Question: is there a way to have the output changelog containing two changesets, one for each insert statement? (if we extrapolate, each DML statement to be in it’s own changeset, so n changesets for n insert statements ) ?

The reason: for existent databases (i.e db1A) that they are used as both reference (for generating the data changelogs) and target (for later applies), we want to make sure that a particular row is inserted via Liquibase apply only if it does not already exist (for example at a first Liquibase deploy over same db1A).
This check can be made easily via a sql precondition, but this can be done at changeSet level (hence the need for “splitting” the bulk inserts into multiple changesets, each containing one insert).

As a workaround, we can use .sql with liquibase formatted sql inside (raw sql code with all the options and support we need for this task) but wanted to know for sure if there are other options out there, Liquibased (:smiley: ).

Thanks in advance for your input!


PS: what would be really cool would be if the insert change type would support if not exists functionality (check based on the PK or something user pre-defined).

Hi @EduardUta ,

Love seeing all the activity from you on the forum. I think of generateChangeLog as a helper command. But you have to still verify what is produced. Why you may ask? Many use this function to migrate to another db platform type (ex. from Oracle → Postgres), and some dbs may not translate to the target platform type.

However, I think some of your suggestions are really cool.

You can log a feature request, and I will just mention @Pete and @mariochampion from Product to check out this use case.

Thanks for all your contributions @EduardUta !


1 Like