From 84f1abf0b0176d3fd9ebedb715bff695d5489b27 Mon Sep 17 00:00:00 2001 From: Michael Hoennig <michael@hoennig.de> Date: Thu, 2 May 2019 11:17:22 +0200 Subject: [PATCH] shares sample data and some cleanup --- .../changelog/sample-data-Customer.xml | 27 ---------------- .../changelog/sample-data-Membership.xml | 26 ---------------- .../resources/config/liquibase/master.xml | 1 + .../liquibase/sample-data/customers.xml | 8 ++++- .../liquibase/sample-data/memberships.xml | 8 ++++- .../config/liquibase/sample-data/shares.csv | 13 ++++++++ .../config/liquibase/sample-data/shares.xml | 31 +++++++++++++++++++ 7 files changed, 59 insertions(+), 55 deletions(-) delete mode 100644 src/main/resources/config/liquibase/changelog/sample-data-Customer.xml delete mode 100644 src/main/resources/config/liquibase/changelog/sample-data-Membership.xml create mode 100644 src/main/resources/config/liquibase/sample-data/shares.csv create mode 100644 src/main/resources/config/liquibase/sample-data/shares.xml diff --git a/src/main/resources/config/liquibase/changelog/sample-data-Customer.xml b/src/main/resources/config/liquibase/changelog/sample-data-Customer.xml deleted file mode 100644 index b5b09fb8..00000000 --- a/src/main/resources/config/liquibase/changelog/sample-data-Customer.xml +++ /dev/null @@ -1,27 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<databaseChangeLog - 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"> - - <changeSet id="sample-data-Customer-01" author="mhoennig" context="sample-data"> - <loadData encoding="UTF-8" - file="config/liquibase/sample-data/customers.csv" - separator=";" - quotchar="'" - tableName="customer"> - </loadData> - - <!-- Liquibase CSV files can contain linebreaks just as real linebreaks, but which - make the CSV files hard to read. Therefore I've encoded linebreaks as '|' and - replace these after import with '\n'. --> - <sql> - UPDATE customer SET contractual_address = REPLACE(contractual_address, '|', STRINGDECODE('\n')); - </sql> - - <rollback> - DELETE FROM customer; - </rollback> - </changeSet> - -</databaseChangeLog> diff --git a/src/main/resources/config/liquibase/changelog/sample-data-Membership.xml b/src/main/resources/config/liquibase/changelog/sample-data-Membership.xml deleted file mode 100644 index 7ed7e3f6..00000000 --- a/src/main/resources/config/liquibase/changelog/sample-data-Membership.xml +++ /dev/null @@ -1,26 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<databaseChangeLog - 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"> - - <changeSet id="sample-data-Membership-01" author="mhoennig" context="sample-data"> - <loadData encoding="UTF-8" - file="config/liquibase/sample-data/memberships.csv" - separator=";" - tableName="membership"> - </loadData> - - <!-- Liquibase CSV files can contain linebreaks just as real linebreaks, but which - make the CSV files hard to read. Therefore I've encoded linebreaks as '|' and - replace these after import with '\n'. --> - <sql> - UPDATE membership SET remark = REPLACE(remark, '|', STRINGDECODE('\n')); - </sql> - - <rollback> - DELETE FROM membership; - </rollback> - </changeSet> - -</databaseChangeLog> diff --git a/src/main/resources/config/liquibase/master.xml b/src/main/resources/config/liquibase/master.xml index 4be32e10..ba329b2a 100644 --- a/src/main/resources/config/liquibase/master.xml +++ b/src/main/resources/config/liquibase/master.xml @@ -22,5 +22,6 @@ <!-- sample data --> <include file="config/liquibase/sample-data/customers.xml" relativeToChangelogFile="false"/> <include file="config/liquibase/sample-data/memberships.xml" relativeToChangelogFile="false"/> + <include file="config/liquibase/sample-data/shares.xml" relativeToChangelogFile="false"/> </databaseChangeLog> diff --git a/src/main/resources/config/liquibase/sample-data/customers.xml b/src/main/resources/config/liquibase/sample-data/customers.xml index 730e9471..5823ef58 100644 --- a/src/main/resources/config/liquibase/sample-data/customers.xml +++ b/src/main/resources/config/liquibase/sample-data/customers.xml @@ -19,7 +19,13 @@ </changeSet> <changeSet id="20190403083736-3" author="mhoennig" context="sample-data"> - <sql>UPDATE customer SET contractual_address = replace(contractual_address, '|', '\n')</sql> + <sql> + UPDATE customer SET contractual_address = replace(contractual_address, '|', '\n') + </sql> + + <rollback> + DELETE FROM customer; + </rollback> </changeSet> </databaseChangeLog> diff --git a/src/main/resources/config/liquibase/sample-data/memberships.xml b/src/main/resources/config/liquibase/sample-data/memberships.xml index f078ab38..89a4d6f0 100644 --- a/src/main/resources/config/liquibase/sample-data/memberships.xml +++ b/src/main/resources/config/liquibase/sample-data/memberships.xml @@ -19,7 +19,13 @@ </changeSet> <changeSet id="20190502100700-2" author="mhoennig" context="sample-data"> - <sql>UPDATE membership SET remark = replace(remark, '|', '\n')</sql> + <sql> + UPDATE membership SET remark = replace(remark, '|', '\n') + </sql> + + <rollback> + DELETE FROM membership; + </rollback> </changeSet> </databaseChangeLog> diff --git a/src/main/resources/config/liquibase/sample-data/shares.csv b/src/main/resources/config/liquibase/sample-data/shares.csv new file mode 100644 index 00000000..b3cbe4e4 --- /dev/null +++ b/src/main/resources/config/liquibase/sample-data/shares.csv @@ -0,0 +1,13 @@ +id;membership_id;document_date;value_date;action;quantity;remark +1;1;2001-04-10;2001-04-11;SUBSCRIPTION;16;some|multiline|remark +2;1;2007-08-09;2007-12-31;CANCELLATION;16;another remark +3;2;2017-01-15;2017-01-17;SUBSCRIPTION;8;became a member again +4;2;2017-01-15;2017-01-17;SUBSCRIPTION;1;just writing something +5;3;2003-05-11;2003-05-18;SUBSCRIPTION;4;some comment +6;3;2003-05-15;2003-05-30;CANCELLATION;4;cancelled membership +7;4;2017-05-15;2017-05-17;SUBSCRIPTION;16; +8;5;2011-08-18;2011-09-01;SUBSCRIPTION;10; +9;5;2012-12-15;2013-01-01;SUBSCRIPTION;20;signed more shares +10;5;2017-11-22;2018-01-01;CANCELLATION;25;cancelled most of their shares + + diff --git a/src/main/resources/config/liquibase/sample-data/shares.xml b/src/main/resources/config/liquibase/sample-data/shares.xml new file mode 100644 index 00000000..307a9fe7 --- /dev/null +++ b/src/main/resources/config/liquibase/sample-data/shares.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="utf-8"?> +<databaseChangeLog + xmlns="http://www.liquibase.org/xml/ns/dbchangelog" + xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" + 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 + http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"> + <property name="now" value="now()" dbms="h2"/> + <property name="now" value="current_timestamp" dbms="postgresql"/> + <property name="floatType" value="float4" dbms="postgresql, h2"/> + <property name="floatType" value="float" dbms="mysql, oracle, mssql"/> + + <changeSet id="20190502111400-1" author="mhoennig" context="sample-data"> + <loadData encoding="UTF-8" + file="config/liquibase/sample-data/shares.csv" + separator=";" + tableName="share"> + </loadData> + </changeSet> + + <changeSet id="20190502111400-2" author="mhoennig" context="sample-data"> + <sql> + UPDATE share SET remark = replace(remark, '|', '\n') + </sql> + + <rollback> + DELETE FROM share; + </rollback> + </changeSet> + +</databaseChangeLog>