Inserting Multiple Records using Single Change Set with dynamic parameters

Hi Team,

We are having a requirement where we need to insert the Multiple records based on Dynamic Parameter. For Example ,
My DML Change Set :

<?xml version="1.0" encoding="UTF-8"?>

<changeSet  author="admin"  id="COCD seed inserts">
    <insert
            tableName="COMMONCODES">
         <column  name="bank_id"  value="${bankid}"/>
        <column  name="code_type"  value="WFST"/>
        <column  name="cm_code"  value="PFA"/>            
    </insert>
	
</changeSet>

Here i need to insert 3 records, if there are 3 different Bank Id(bankid1,bankid2,bankid3).

|bank_id|code_type|cm_code|
|bankid1|WFST|PFA|
|bankid2|WFST|PFA|
|bankid3|WFST|PFA|

This has to be done in a single execution.

Is there any way to pass the list of Substitution parameter values for a single parameter.

Thanks in advance.

If it’s a requirement to dynamically generate your data and then load it, one way to do this would be to dynamically create a .csv file that has all the inserts you need and read that into your changeset using a loadData changeset type.

And thanks for joining our community of people using Liquibase.

Thanks Mike for the Soln. Is there any way to generate the .csv file dynamically through the checked-in changesets? Does Liquibase provides any way to generate .csv files?

Hi @arsh_liquibase Liquibase will dynamically generate a .csv file when you pull data from a database. Liquibase does not dynamically generate data. I would think there are many tools that can dynamically generate a csv file. Once you have that you can feed the file to the loaddata changeset type. Is this a requirement or a design decision to build it this way?

Here is a sample to create a csv.

This is a requirement as we need to insert the same scripts for two different entities with Entity ID as the only difference. This will become more complex if we go with CSV way. We might have to create CSV files for each table and then insert using the liquibase engine.

Is there any way other than .CSV format.
I can think of one way where i can loop through entity ID list for each change set.