Search code examples
warliquibaseliquibase-sql

Liquibase SQL Changeset Cannot Load CSV File : FileNotFoundException


Using a SQL style approach to Liquibase changesets (which is our codestyle, we don't use XML) I am trying to load an CSV file using the following SQL changeset

SQL

-- changeset user:insert-prices-data-temp-table

LOAD DATA LOCAL INFILE 'foo/src/main/resources/liquibase/changelogs/2021/prices.csv'
INTO TABLE prices_temp
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES

When deploying the WAR file to Wildfly the following exception

java.io.FileNotFoundException: foo/src/resources/liquibase/changelogs/2021/prices.csv (No such file or directory) 2021-09-22T20:52:18.581085123Z at java.io.FileInputStream.open0(Native Method) 2021-09-22T20:52:18.581087214Z at java.io.FileInputStream.open(FileInputStream.java:195) 2021-09-22T20:52:18.581089768Z at java.io.FileInputStream.(FileInputStream.java:138) 2021-09-22T20:52:18.581092029Z at java.io.FileInputStream.(FileInputStream.java:93) 2021-09-22T20:52:18.581094150Z at com.mysql.jdbc.MysqlIO.sendFileToServer(MysqlIO.java:3772)

The Master Change log file references the 2021 directory with the SQL and CSV file existing in the same directory.

<includeAll path="liquibase/changelogs/2021/" filter="xml" errorIfMissingOrEmpty="true" />

I have tried the following other paths but they all still yield a FileNotFoundException

  • prices.csv
  • liquibase/changelogs/2021/prices.csv
  • WEB-INF/classes/liquibase/changelogs/2021/CCC-220-marking-time-prices.csv
  • (Absolute path) /home/xxxx/Work/foo-service/foo/src/main/resources/liquibase/changelogs/2021/prices.csv

Liquibase Version: 3.5.1

Wildfly Jboss Version : 21

I have checked the CSV file is present in the WAR file

Any ideas how to fix this?


Solution

  • The problem is that you are trying to use some mysql function LOAD DATA LOCAL INFILE which doesn't know about your classpath. It's trying to look at your filesystem and such path doesn't exists. Even if you provide something like yourapp.jar!liquibase/changelogs/2021/prices.csv it won't be able to read that file. You will need to pull prices.csv out of your application to filesystem and point mysql function to that location.
    Or you can use liquibase's loadData if that helps.