Liquibase loadData doesn’t use my load my CSV but not error

I’m trying to load datas from a CSV with liquibase, my problem is that the script run and there is no error, but there is no data in my table, here is my configuration

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                      http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
    <changeSet id="1" author="dev">
        <createTable tableName="products">
            <column name="code" type="varchar(3)">
                <constraints primaryKey="true"/>
            </column>
            <column name="name" type="text"/>
        </createTable>
    </changeSet>
    <changeSet id="2" author="dev">
        <loadData tableName="products"
                  file="data_products.csv"
                  separator=";"
                  relativeToChangelogFile="true"/>
    </changeSet>
</databaseChangeLog>

In my file data_products.csv I have things like this

code;name
000;product1
001;product2

and here is my console log when I run my project :

2021-01-15 11:21:18.986  INFO 9540 --- [main] liquibase.changelog: Creating database history table with name: public.databasechangelog
2021-01-15 11:21:18.993  INFO 9540 --- [main] liquibase.changelog: Reading from public.databasechangelog
2021-01-15 11:21:19.047  INFO 9540 --- [main] liquibase.changelog: Table products created
2021-01-15 11:21:19.048  INFO 9540 --- [main] liquibase.changelog: ChangeSet liquibase/sql/1.0.0/init_db.xml::1::dev ran successfully in 8ms
2021-01-15 11:21:19.156  INFO 9540 --- [main] liquibase.changelog: Data loaded from data_products.csv into products
2021-01-15 11:21:19.156  INFO 9540 --- [main] liquibase.changelog: ChangeSet liquibase/sql/1.0.0/init_db.xml::2::dev ran successfully in 104ms
2021-01-15 11:21:19.160  INFO 9540 --- [main] liquibase.lockservice: Successfully released change log lock

I don’t know what is wrong with my configuration, since the log says that datas are loaded but when I do a select in my table, I’ve got nothing inside

Answer

I did find the solution, the problem is with the type in the column name,

If you use text for a type with liquibase it’s performed as a CLOB in database, and then it doesn’t load datas,

I just changed

        <column name="name" type="text"/>

to

        <column name="name" type="varchar"/>

without size and it worked !

Leave a Reply

Your email address will not be published. Required fields are marked *