I habe to execute a Liquibase changeSet multiple times. Each time with different properties.
Imagine this example:
<!-- changeset_foo.xml -->
<databaseChangeLog ...>
<changeSet author="me" id="INSERT_FOO">
<insert tableName="FOO">
<column name="ID" valueSequenceNext="ID_SEQ"/>
<column name="NAME" value="${FOO_NAME}"/>
</insert>
</changeSet>
</databaseChangeLog>
Now, this will be used in two different changeSets with different property:
<!-- changeset_apple.xml -->
<databaseChangeLog ...>
<property name="FOO_NAME" value="Apple"/>
<include file="changeset_foo.xml"/>
</databaseChangeLog>
<!-- changeset_banana.xml -->
<databaseChangeLog ...>
<property name="FOO_NAME" value="Banana"/>
<include file="changeset_foo.xml"/>
</databaseChangeLog>
And course both are mentioned in master changelog:
<!-- changelog_master.xml -->
<databaseChangeLog ...>
<include file="changeset_apple.xml"/>
<include file="changeset_banana.xml"/>
</databaseChangeLog>
The result is some kind of expected. As it is assumed that the changeSet Id is unique the changeSet will be executed only once. The exception is
Caused by: liquibase.exception.CommandExecutionException: ...
Caused by: liquibase.exception.ValidationFailedException: Validation Failed:
1 changesets had duplicate identifiers
But how can I solve this behavior?
Setting runOnChange, runAlwaysan validCheckSumdoes not work (though mentioned here: execute parameterized liquibase changeset multiple times with different parameters) and produces the same error
<!-- changeset_foo.xml -->
<databaseChangeLog ...>
<changeSet author="me" id="INSERT_FOO" runOnChange="true" runAlways="true">
<validCheckSum>any</validCheckSum>
<insert tableName="FOO">
<column name="ID" valueSequenceNext="ID_SEQ"/>
<column name="NAME" value="${FOO_NAME}"/>
</insert>
</changeSet>
</databaseChangeLog>
I am using Liquibase 4.24.0. I read that with version 4.25.1 and later you can set allow-duplicated-changeset-identifiers
(https://docs.liquibase.com/parameters/allow-duplicated-changeset-identifiers.html). But even that would only execute the changeset once
your duplicated changesets are not deployed to your database, but Liquibase will not treat the duplicates like errors