Using Liquibase parameter inside loadData CSV

I want to abstract the functions for generating uuid for each dbms:

<property name="uuid_function" value="gen_random_uuid()" dbms="postgresql"/>
<property name="uuid_function" value="NEWID()" dbms="mssql"/>
<property name="uuid_function" value="sys_guid()" dbms="oracle"/>

And then using this property in my CSV, which loads loadData, like this:

"${uuid_function}"

But it does not work (parsing error on $). Another approach with default values ​​for a column inside loadData:

<column name="id" type="COMPUTED" defaultValueComputed="${uuid_function}"/>

.. also does not work. The column Identifier is defined as NOT NULL, and if I leave the column outside my CSV, it complains that the columns cannot be null, even if they should use the default value.

How to use parameters inside CSV files and / or why the default value doesn’t work for me?

+4
source share
2 answers

, , , , UUID, Date, , .

:

<property name="now" value="CURRENT_DATE" dbms="hsqldb" />

, changeSet:

<changeSet author="miguel" id="1448735850226-1">
    <createTable tableName="usuario">
        <column name="login" type="VARCHAR(255)">
            <constraints nullable="false"/>
        </column>
        <column name="oid" type="VARCHAR(255)"/>
        <column name="fecha" type="date" defaultValueComputed="${now}">
            <constraints nullable="false"/>
        </column>
        <column name="nombre" type="VARCHAR(255)"/>
        <column name="apellidos" type="VARCHAR(255)"/>
        <column name="activo" type="BOOLEAN"/>
    </createTable>
</changeSet>

, fecha null defaultValueComputed ${now}.

users.csv, (usuarios-test.csv):

login;oid;nombre;apellidos;activo
user;b776052e-7c9f-11e5-8584-67d602646e6f;Prueba;Prueba;true

, csv , fecha. ( , UUID , , ).

, loadData

<changeSet author="miguel" id="1448735850226-16">
    <loadData tableName="usuario" encoding="UTF-8" 
      file="src/main/resources/liquibase/changelogs/usuarios-test.csv"
      quotchar="'" separator=";" >
      <column header="login" name="login" type="STRING"/>
      <column header="oid" name="oid" type="STRING"/>
      <column header="nombre" name="nombre" type="STRING"/>
      <column header="apellidos" name="apellidos" type="STRING"/>
      <column header="activo" name="activo" type="BOOLEAN"/>
    </loadData>
</changeSet>

, , .csv, fecha , defaultValueComputed , , .

, !

+3

type="COMPUTED" . , UUID , .

Oracle Postgres :

  <property name="uuid_function" value="gen_random_uuid()" dbms="postgresql"/>
  <property name="uuid_function" value="NEWID()" dbms="mssql"/>
  <property name="uuid_function" value="sys_guid()" dbms="oracle"/>

  <property name="uuid_type" value="uuid" dbms="postgresql"/>
  <property name="uuid_type" value="uniqueidentifier" dbms="mssql"/>
  <property name="uuid_type" value="RAW(32)" dbms="oracle"/>

  <changeSet author="testing" id="1">
    <createTable tableName="foo">
      <column name="id" type="${uuid_type}" defaultValueComputed="${uuid_function}">
        <constraints nullable="false"/>
      </column>
    </createTable>
  </changeSet>

Postgres:

CREATE TABLE foo
(
   id  uuid    DEFAULT gen_random_uuid() NOT NULL
);

Oracle:

CREATE TABLE FOO
(
   ID  RAW(32)   DEFAULT sys_guid() NOT NULL
);
+2

Source: https://habr.com/ru/post/1613327/


All Articles