1
0

sample-data: replacing pipes ('|') with newlines now via customChange

this avoids database-specific code spread over all sample-data/*.xml files
This commit is contained in:
Michael Hoennig
2019-05-05 14:15:07 +02:00
parent 4c42d15c12
commit f8ed5069fb
7 changed files with 130 additions and 82 deletions

View File

@ -3,7 +3,6 @@
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.5.xsd">
<include file="config/liquibase/changelog/00000000000000_initial_schema.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20190430152136_added_entity_Customer.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20190430152137_added_entity_Membership.xml" relativeToChangelogFile="false"/>

View File

@ -16,26 +16,16 @@
separator=";"
tableName="asset">
</loadData>
</changeSet>
<changeSet id="20190502111400-2" author="mhoennig" context="sample-data,">
<!-- I've tried extracting this to a stored procedure, but a compatible call
is only possible with PostgresSQL 11.x, otherwise the call syntax
between H2 and PostgresSQL would be different which defeated the point.
-->
<sql dbms="h2">
UPDATE asset SET remark = replace(remark, '|', STRINGDECODE('\n'))
</sql>
<sql dbms="postgresql">
UPDATE asset SET remark = replace(remark, '|', E'\n')
</sql>
<customChange class="org.hostsharing.hsadminng.liquibase.ReplaceCustomChange">
<param name="tableName" value="asset" />
<param name="columnNames" value="remark" />
<param name="searchFor" value="|" />
<param name="replaceWith" value="\n" />
</customChange>
<rollback>
DELETE FROM asset;
</rollback>
</changeSet>
</databaseChangeLog>

View File

@ -10,32 +10,19 @@
<property name="floatType" value="float4" dbms="postgresql, h2"/>
<property name="floatType" value="float" dbms="mysql, oracle, mssql"/>
<changeSet id="20190403083736-2" author="mhoennig" context="sample-data">
<changeSet id="20190505130300-1" author="mhoennig" context="sample-data">
<loadData encoding="UTF-8"
file="config/liquibase/sample-data/customers.csv"
separator=";"
tableName="customer">
</loadData>
</changeSet>
<changeSet id="20190403083736-3" author="mhoennig" context="sample-data">
<!-- I've tried extracting this to a stored procedure, but a compatible call
is only possible with PostgresSQL 11.x, otherwise the call syntax
between H2 and PostgresSQL would be different which defeated the point.
-->
<sql dbms="h2">
UPDATE customer SET contractual_address = replace(contractual_address, '|', STRINGDECODE('\n'));
UPDATE customer SET billing_address = replace(billing_address, '|', STRINGDECODE('\n'));
UPDATE customer SET remark = replace(remark, '|', STRINGDECODE('\n'));
</sql>
<sql dbms="postgresql">
UPDATE customer SET contractual_address = replace(contractual_address, '|', '\n');
UPDATE customer SET billing_address = replace(billing_address, '|', '\n');
UPDATE customer SET remark = replace(remark, '|', E'\n');
</sql>
<customChange class="org.hostsharing.hsadminng.liquibase.ReplaceCustomChange">
<param name="tableName" value="customer" />
<param name="columnNames" value="contractual_address,billing_address,remark" />
<param name="searchFor" value="|" />
<param name="replaceWith" value="\n" />
</customChange>
<rollback>
DELETE FROM customer;

View File

@ -16,22 +16,13 @@
separator=";"
tableName="membership">
</loadData>
</changeSet>
<changeSet id="20190502100700-2" author="mhoennig" context="sample-data">
<!-- I've tried extracting this to a stored procedure, but a compatible call
is only possible with PostgresSQL 11.x, otherwise the call syntax
between H2 and PostgresSQL would be different which defeated the point.
-->
<sql dbms="h2">
UPDATE membership SET remark = replace(remark, '|', STRINGDECODE('\n'))
</sql>
<sql dbms="postgresql">
UPDATE customer SET remark = replace(remark, '|', E'\n');
</sql>
<customChange class="org.hostsharing.hsadminng.liquibase.ReplaceCustomChange">
<param name="tableName" value="membership" />
<param name="columnNames" value="remark" />
<param name="searchFor" value="|" />
<param name="replaceWith" value="\n" />
</customChange>
<rollback>
DELETE FROM membership;

View File

@ -16,22 +16,13 @@
separator=";"
tableName="sepa_mandate">
</loadData>
</changeSet>
<changeSet id="20190503152800-2" author="mhoennig" context="sample-data">
<!-- I've tried extracting this to a stored procedure, but a compatible call
is only possible with PostgresSQL 11.x, otherwise the call syntax
between H2 and PostgresSQL would be different which defeated the point.
-->
<sql dbms="h2">
UPDATE sepa_mandate SET remark = replace(remark, '|', STRINGDECODE('\n'))
</sql>
<sql dbms="postgresql">
UPDATE customer SET remark = replace(remark, '|', E'\n');
</sql>
<customChange class="org.hostsharing.hsadminng.liquibase.ReplaceCustomChange">
<param name="tableName" value="sepa_mandate" />
<param name="columnNames" value="remark" />
<param name="searchFor" value="|" />
<param name="replaceWith" value="\n" />
</customChange>
<rollback>
DELETE FROM sepa_mandate;

View File

@ -16,22 +16,13 @@
separator=";"
tableName="share">
</loadData>
</changeSet>
<changeSet id="20190502111400-2" author="mhoennig" context="sample-data">
<!-- I've tried extracting this to a stored procedure, but a compatible call
is only possible with PostgresSQL 11.x, otherwise the call syntax
between H2 and PostgresSQL would be different which defeated the point.
-->
<sql dbms="h2">
UPDATE share SET remark = replace(remark, '|', STRINGDECODE('\n'))
</sql>
<sql dbms="postgresql">
UPDATE customer SET remark = replace(remark, '|', E'\n');
</sql>
<customChange class="org.hostsharing.hsadminng.liquibase.ReplaceCustomChange">
<param name="tableName" value="share" />
<param name="columnNames" value="remark" />
<param name="searchFor" value="|" />
<param name="replaceWith" value="\n" />
</customChange>
<rollback>
DELETE FROM share;