From 5337e7a7e89906dfd9e1e498947071031748178c Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Tue, 7 May 2019 10:54:27 +0200 Subject: [PATCH] historicization trigger+view for Customer, Membership, SepaMandate, Share and Asset --- .../changelog/constraints_Membership.xml | 15 ++ ...xml => constraints_UserRoleAssignment.xml} | 1 + .../historicization/historicization_Asset.xml | 96 +++++++++++++ .../historicization_Customer.xml | 131 ++++++++++++++++++ .../historicization_Membership.xml | 95 +++++++++++++ .../historicization_SepaMandate.xml | 112 +++++++++++++++ .../historicization/historicization_Share.xml | 96 +++++++++++++ .../historicization_UserRoleAssignment.xml | 2 +- .../resources/config/liquibase/master.xml | 11 +- 9 files changed, 556 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/config/liquibase/changelog/constraints_Membership.xml rename src/main/resources/config/liquibase/changelog/{20190506185600_constraints_UserRoleAssignment.xml => constraints_UserRoleAssignment.xml} (88%) create mode 100644 src/main/resources/config/liquibase/historicization/historicization_Asset.xml create mode 100644 src/main/resources/config/liquibase/historicization/historicization_Customer.xml create mode 100644 src/main/resources/config/liquibase/historicization/historicization_Membership.xml create mode 100644 src/main/resources/config/liquibase/historicization/historicization_SepaMandate.xml create mode 100644 src/main/resources/config/liquibase/historicization/historicization_Share.xml diff --git a/src/main/resources/config/liquibase/changelog/constraints_Membership.xml b/src/main/resources/config/liquibase/changelog/constraints_Membership.xml new file mode 100644 index 00000000..9ce63193 --- /dev/null +++ b/src/main/resources/config/liquibase/changelog/constraints_Membership.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/src/main/resources/config/liquibase/changelog/20190506185600_constraints_UserRoleAssignment.xml b/src/main/resources/config/liquibase/changelog/constraints_UserRoleAssignment.xml similarity index 88% rename from src/main/resources/config/liquibase/changelog/20190506185600_constraints_UserRoleAssignment.xml rename to src/main/resources/config/liquibase/changelog/constraints_UserRoleAssignment.xml index 2a0e4ec1..66a7712f 100644 --- a/src/main/resources/config/liquibase/changelog/20190506185600_constraints_UserRoleAssignment.xml +++ b/src/main/resources/config/liquibase/changelog/constraints_UserRoleAssignment.xml @@ -7,6 +7,7 @@ + diff --git a/src/main/resources/config/liquibase/historicization/historicization_Asset.xml b/src/main/resources/config/liquibase/historicization/historicization_Asset.xml new file mode 100644 index 00000000..22584e19 --- /dev/null +++ b/src/main/resources/config/liquibase/historicization/historicization_Asset.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + CREATE TRIGGER asset_historicize + AFTER INSERT OR DELETE OR UPDATE ON asset + FOR EACH ROW EXECUTE PROCEDURE historicize(); + + + DROP TRIGGER asset_historicize + + + + + + SELECT * + FROM asset_history + WHERE history_id IN ( + SELECT max(history_id) AS history_id + FROM asset_history + WHERE history_transaction <= current_setting('history.transaction')::bigint + GROUP BY id) -- assets are not deletable, thus id is enough + + + + + + diff --git a/src/main/resources/config/liquibase/historicization/historicization_Customer.xml b/src/main/resources/config/liquibase/historicization/historicization_Customer.xml new file mode 100644 index 00000000..6d7245fa --- /dev/null +++ b/src/main/resources/config/liquibase/historicization/historicization_Customer.xml @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + CREATE TRIGGER customer_historicize + AFTER INSERT OR DELETE OR UPDATE ON customer + FOR EACH ROW EXECUTE PROCEDURE historicize(); + + + DROP TRIGGER customer_historicize + + + + + + SELECT * + FROM customer_history + WHERE history_id IN ( + SELECT max(history_id) AS history_id + FROM customer_history + WHERE history_transaction <= current_setting('history.transaction')::bigint + GROUP BY name) -- must have a unique constraint + + + + diff --git a/src/main/resources/config/liquibase/historicization/historicization_Membership.xml b/src/main/resources/config/liquibase/historicization/historicization_Membership.xml new file mode 100644 index 00000000..9759f9d8 --- /dev/null +++ b/src/main/resources/config/liquibase/historicization/historicization_Membership.xml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + CREATE TRIGGER membership_historicize + AFTER INSERT OR DELETE OR UPDATE ON membership + FOR EACH ROW EXECUTE PROCEDURE historicize(); + + + DROP TRIGGER membership_historicize + + + + + + SELECT * + FROM membership_history + WHERE history_id IN ( + SELECT max(history_id) AS history_id + FROM membership_history + WHERE history_transaction <= current_setting('history.transaction')::bigint + GROUP BY customer_id, member_from_date) -- must have a unique constraint + + + + diff --git a/src/main/resources/config/liquibase/historicization/historicization_SepaMandate.xml b/src/main/resources/config/liquibase/historicization/historicization_SepaMandate.xml new file mode 100644 index 00000000..7c15d4bf --- /dev/null +++ b/src/main/resources/config/liquibase/historicization/historicization_SepaMandate.xml @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + CREATE TRIGGER sepa_mandate_historicize + AFTER INSERT OR DELETE OR UPDATE ON sepa_mandate + FOR EACH ROW EXECUTE PROCEDURE historicize(); + + + DROP TRIGGER sepa_mandate_historicize + + + + + + SELECT * + FROM sepa_mandate_history + WHERE history_id IN ( + SELECT max(history_id) AS history_id + FROM sepa_mandate_history + WHERE history_transaction <= current_setting('history.transaction')::bigint + GROUP BY reference) -- must have a unique constraint + + + + diff --git a/src/main/resources/config/liquibase/historicization/historicization_Share.xml b/src/main/resources/config/liquibase/historicization/historicization_Share.xml new file mode 100644 index 00000000..5f2219ff --- /dev/null +++ b/src/main/resources/config/liquibase/historicization/historicization_Share.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + CREATE TRIGGER share_historicize + AFTER INSERT OR DELETE OR UPDATE ON share + FOR EACH ROW EXECUTE PROCEDURE historicize(); + + + DROP TRIGGER share_historicize + + + + + + SELECT * + FROM share_history + WHERE history_id IN ( + SELECT max(history_id) AS history_id + FROM share_history + WHERE history_transaction <= current_setting('history.transaction')::bigint + GROUP BY id) -- shares are not deletable, thus id is enough + + + + + + diff --git a/src/main/resources/config/liquibase/historicization/historicization_UserRoleAssignment.xml b/src/main/resources/config/liquibase/historicization/historicization_UserRoleAssignment.xml index b5d55fdd..e5f3c9f4 100644 --- a/src/main/resources/config/liquibase/historicization/historicization_UserRoleAssignment.xml +++ b/src/main/resources/config/liquibase/historicization/historicization_UserRoleAssignment.xml @@ -80,7 +80,7 @@ SELECT max(history_id) AS history_id FROM user_role_assignment_history WHERE history_transaction <= current_setting('history.transaction')::bigint - GROUP BY entity_type_id, entity_object_id, assigned_role, user_id) + GROUP BY entity_type_id, entity_object_id, assigned_role, user_id) -- must have a unique constraint diff --git a/src/main/resources/config/liquibase/master.xml b/src/main/resources/config/liquibase/master.xml index bc1ac640..1a649f66 100644 --- a/src/main/resources/config/liquibase/master.xml +++ b/src/main/resources/config/liquibase/master.xml @@ -23,13 +23,20 @@ - + + + + + + + - +