Liquibase loadData as string, not CLOB resource
Asked Answered
C

3

17

The Problem

I recently upgraded Liquibase to 3.6.2 from 3.4.2.

Loading seed data from a CSV into text fields now results in a CLOB resource error. Before it would simply insert the text as a value.

The Setup

I'm using Liquibase to manage migrations of my data.

I have a table with an code and description column. description is of type TEXT.

<changeSet author="" id="create-table-degrees">
  <createTable tableName="degrees">
    <column name="code"
            type="varchar(2)">
      <constraints primaryKey="true"/>
    </column>
    <column name="description"
            type="text">
      <constraints unique="true"/>
    </column>
  </createTable>
  <rollback>
    <dropTable tableName="degrees"/>
  </rollback>
</changeSet>

I have seed data in a CSV:

code,description
"D1","MASTERS"
"D2","DOCTORATE"

I load it using loadData:

<changeSet author="" id="seed-degrees">
  <loadData file="seeds/degrees.csv"
            tableName="degrees" />
</changeSet>

The Error

Unexpected error running Liquibase: CLOB resource not found: MASTERS

The Question

Is there a way to keep Liquibase from interpreting seed values as file paths instead of strings, or do I need to manually define the column types as String in loadData.

e.g. I would like to avoid having to modify the old changeSet to:

<changeSet author="" id="seed-degrees">
  <loadData file="seeds/degrees.csv"
            tableName="roles">
    <column name="description" type="string" />
  </loadData>
</changeSet>
Citrine answered 22/7, 2018 at 22:27 Comment(1)
Just a note that I have added an issue for this in the liquibase JIRA -- liquibase.jira.com/browse/CORE-3287Citrine
R
6

The workaround listed in CORE-3287: Anver S December 3, 2018, 3:07 PM

While adding an explicit column type definition as defined in original stackoverflow post

<column name="description" type="string" />

does the trick - for me it effectively requires to update already applied changesets which ideally I'd try to avoid.

Reagan answered 7/5, 2020 at 13:34 Comment(1)
Thank you for adding that directly -- though I won't mark it as an answer since that solution is actually part of the question (listed as something I want to avoid)Citrine
H
0

try column name="description" type="varchar(1500)" for example to allow for longer text

Hippie answered 30/6, 2023 at 11:27 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Ashbaugh
P
0

Change description column from text type to varchar (no need to give any limit in brackets). It works the same and it loads without giving any column in loadData

<column name="description" type="varchar">
      <constraints unique="true"/>
</column>
Popple answered 14/11, 2023 at 15:50 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.