Liquibase:插入blob文件,其路径来自输入 *.csv

0aydgbwb  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(113)

我正在使用Liquibase进行数据库人口。具有一个实体定义文件,其字段为:

<column name="image" type="longblob"></column>

和加载数据配置:

<loadData encoding="UTF-8" file="images.csv"
            separator=";" tableName="images">
    </loadData>

在输入csv文件中,我有3列:1)名称2)类型3)图像
所以我的问题是是否可以在输入文件字段“image”中填充图像的PATH(“/test.png”),并在数据库中将其填充为从 *.cvs路径中提供的BLOB上传图像?

lrpiutwd

lrpiutwd1#

是的,有可能

只需使用CSV文件中图像文件的路径,即可在图像数据列中找到图像文件。
就像这个CSV文件:

id,description,image
1,'just my image',/path/to/the/image
2,'nice image',/path/to/another/image

你可以这样定义你的liquibase changelog文件:

<databaseChangeLog
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">

    <changeSet id="1" author="Johny.Walker">
        <loadData tableName="Image"
                  file="image_test_data.csv"
                  separator=","
                  quotchar="'"/>
    </changeSet>
</databaseChangeLog>

相关问题