From 47338cead8253a58b88608bbb01c06834a436f5e Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Fri, 5 Jan 2024 08:19:49 +0100 Subject: [PATCH] =?UTF-8?q?Liquibase-Changesets=20f=C3=BCr=20Legacy-ID=20M?= =?UTF-8?q?apping?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../206-hs-office-contact-migration.sql | 96 ++++++++++++++++++ .../226-hs-office-partner-migration.sql | 95 ++++++++++++++++++ .../256-hs-office-sepamandate-migration.sql | 97 +++++++++++++++++++ .../316-hs-office-coopshares-migration.sql | 96 ++++++++++++++++++ .../326-hs-office-coopassets-migration.sql | 96 ++++++++++++++++++ .../db/changelog/db.changelog-master.yaml | 12 ++- 6 files changed, 491 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/db/changelog/206-hs-office-contact-migration.sql create mode 100644 src/main/resources/db/changelog/226-hs-office-partner-migration.sql create mode 100644 src/main/resources/db/changelog/256-hs-office-sepamandate-migration.sql create mode 100644 src/main/resources/db/changelog/316-hs-office-coopshares-migration.sql create mode 100644 src/main/resources/db/changelog/326-hs-office-coopassets-migration.sql diff --git a/src/main/resources/db/changelog/206-hs-office-contact-migration.sql b/src/main/resources/db/changelog/206-hs-office-contact-migration.sql new file mode 100644 index 00000000..67309307 --- /dev/null +++ b/src/main/resources/db/changelog/206-hs-office-contact-migration.sql @@ -0,0 +1,96 @@ +--liquibase formatted sql + +-- TODO: These changesets are just for the external remote views to simulate the legacy tables. +-- Once we don't need the external remote views anymore, create revert changesets. + +-- ============================================================================ +--changeset hs-office-contact-MIGRATION-mapping:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- + +CREATE TABLE hs_office_contact_legacy_id +( + uuid uuid NOT NULL REFERENCES hs_office_contact(uuid), + contact_id integer NOT NULL +); +--// + + +-- ============================================================================ +--changeset hs-office-contact-MIGRATION-sequence:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- + +CREATE SEQUENCE IF NOT EXISTS hs_office_contact_legacy_id_seq + AS integer + START 1000000000 + OWNED BY hs_office_contact_legacy_id.contact_id; +--// + + +-- ============================================================================ +--changeset hs-office-contact-MIGRATION-default:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- + +ALTER TABLE hs_office_contact_legacy_id + ALTER COLUMN contact_id + SET DEFAULT nextVal('hs_office_contact_legacy_id_seq'); + +--/ + +-- ============================================================================ +--changeset hs-office-contact-MIGRATION-insert:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- + +CALL defineContext('schema-migration'); +INSERT INTO hs_office_contact_legacy_id(uuid, contact_id) +SELECT uuid, nextVal('hs_office_contact_legacy_id_seq') FROM hs_office_contact; +--/ + + +-- ============================================================================ +--changeset hs-office-contact-MIGRATION-insert-trigger:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- +create or replace function insertContactLegacyIdMapping() + returns trigger + language plpgsql + strict as $$ +begin + if TG_OP <> 'INSERT' then + raise exception 'invalid usage of trigger'; + end if; + + INSERT INTO hs_office_contact_legacy_id VALUES + (NEW.uuid, nextVal('hs_office_contact_legacy_id_seq')); + + return NEW; +end; $$; + +create trigger createContactLegacyIdMapping + after insert on hs_office_contact + for each row +execute procedure insertContactLegacyIdMapping(); +--/ + + +-- ============================================================================ +--changeset hs-office-contact-MIGRATION-delete-trigger:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- +create or replace function deleteContactLegacyIdMapping() + returns trigger + language plpgsql + strict as $$ +begin + if TG_OP <> 'DELETE' then + raise exception 'invalid usage of trigger'; + end if; + + DELETE FROM hs_office_contact_legacy_id + WHERE uuid = OLD.uuid; + + return OLD; +end; $$; + +create trigger removeContactLegacyIdMapping + before delete on hs_office_contact + for each row +execute procedure deleteContactLegacyIdMapping(); +--/ diff --git a/src/main/resources/db/changelog/226-hs-office-partner-migration.sql b/src/main/resources/db/changelog/226-hs-office-partner-migration.sql new file mode 100644 index 00000000..abc18a88 --- /dev/null +++ b/src/main/resources/db/changelog/226-hs-office-partner-migration.sql @@ -0,0 +1,95 @@ +--liquibase formatted sql + +-- TODO: These changesets are just for the external remote views to simulate the legacy tables. +-- Once we don't need the external remote views anymore, create revert changesets. + +-- ============================================================================ +--changeset hs-office-partner-MIGRATION-mapping:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- + +CREATE TABLE hs_office_partner_legacy_id +( + uuid uuid NOT NULL REFERENCES hs_office_partner(uuid), + bp_id integer NOT NULL +); +--// + + +-- ============================================================================ +--changeset hs-office-partner-MIGRATION-sequence:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- + +CREATE SEQUENCE IF NOT EXISTS hs_office_partner_legacy_id_seq + AS integer + START 1000000000 + OWNED BY hs_office_partner_legacy_id.bp_id; +--// + + +-- ============================================================================ +--changeset hs-office-partner-MIGRATION-default:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- + +ALTER TABLE hs_office_partner_legacy_id + ALTER COLUMN bp_id + SET DEFAULT nextVal('hs_office_partner_legacy_id_seq'); +--/ + +-- ============================================================================ +--changeset hs-office-partner-MIGRATION-insert:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- + +CALL defineContext('schema-migration'); +INSERT INTO hs_office_partner_legacy_id(uuid, bp_id) +SELECT uuid, nextVal('hs_office_partner_legacy_id_seq') FROM hs_office_partner; +--/ + + +-- ============================================================================ +--changeset hs-office-partner-MIGRATION-insert-trigger:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- +create or replace function insertPartnerLegacyIdMapping() + returns trigger + language plpgsql + strict as $$ +begin + if TG_OP <> 'INSERT' then + raise exception 'invalid usage of trigger'; + end if; + + INSERT INTO hs_office_partner_legacy_id VALUES + (NEW.uuid, nextVal('hs_office_partner_legacy_id_seq')); + + return NEW; +end; $$; + +create trigger createPartnerLegacyIdMapping + after insert on hs_office_partner + for each row + execute procedure insertPartnerLegacyIdMapping(); +--/ + + +-- ============================================================================ +--changeset hs-office-partner-MIGRATION-delete-trigger:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- +create or replace function deletePartnerLegacyIdMapping() + returns trigger + language plpgsql + strict as $$ +begin + if TG_OP <> 'DELETE' then + raise exception 'invalid usage of trigger'; + end if; + + DELETE FROM hs_office_partner_legacy_id + WHERE uuid = OLD.uuid; + + return OLD; +end; $$; + +create trigger removePartnerLegacyIdMapping + before delete on hs_office_partner + for each row + execute procedure deletePartnerLegacyIdMapping(); +--/ diff --git a/src/main/resources/db/changelog/256-hs-office-sepamandate-migration.sql b/src/main/resources/db/changelog/256-hs-office-sepamandate-migration.sql new file mode 100644 index 00000000..5baaf783 --- /dev/null +++ b/src/main/resources/db/changelog/256-hs-office-sepamandate-migration.sql @@ -0,0 +1,97 @@ +--liquibase formatted sql + +-- TODO: These changesets are just for the external remote views to simulate the legacy tables. +-- Once we don't need the external remote views anymore, create revert changesets. + +-- ============================================================================ +--changeset hs-office-sepamandate-MIGRATION-mapping:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- + +CREATE TABLE hs_office_sepamandate_legacy_id +( + uuid uuid NOT NULL REFERENCES hs_office_sepamandate(uuid), + sepa_mandat_id integer NOT NULL +); +--// + + +-- ============================================================================ +--changeset hs-office-sepamandate-MIGRATION-sequence:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- + +CREATE SEQUENCE IF NOT EXISTS hs_office_sepamandate_legacy_id_seq + AS integer + START 1000000000 + OWNED BY hs_office_sepamandate_legacy_id.sepa_mandat_id; +--// + + +-- ============================================================================ +--changeset hs-office-sepamandate-MIGRATION-default:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- + +ALTER TABLE hs_office_sepamandate_legacy_id + ALTER COLUMN sepa_mandat_id + SET DEFAULT nextVal('hs_office_sepamandate_legacy_id_seq'); + +--/ + + +-- ============================================================================ +--changeset hs-office-sepamandate-MIGRATION-insert:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- + +CALL defineContext('schema-migration'); +INSERT INTO hs_office_sepamandate_legacy_id(uuid, sepa_mandat_id) +SELECT uuid, nextVal('hs_office_sepamandate_legacy_id_seq') FROM hs_office_sepamandate; +--/ + + +-- ============================================================================ +--changeset hs-office-sepamandate-MIGRATION-insert-trigger:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- +create or replace function insertSepaMandateLegacyIdMapping() + returns trigger + language plpgsql + strict as $$ +begin + if TG_OP <> 'INSERT' then + raise exception 'invalid usage of trigger'; + end if; + + INSERT INTO hs_office_sepamandate_legacy_id VALUES + (NEW.uuid, nextVal('hs_office_sepamandate_legacy_id_seq')); + + return NEW; +end; $$; + +create trigger createSepaMandateLegacyIdMapping + after insert on hs_office_sepamandate + for each row +execute procedure insertSepaMandateLegacyIdMapping(); +--/ + + +-- ============================================================================ +--changeset hs-office-sepamandate-MIGRATION-delete-trigger:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- +create or replace function deleteSepaMandateLegacyIdMapping() + returns trigger + language plpgsql + strict as $$ +begin + if TG_OP <> 'DELETE' then + raise exception 'invalid usage of trigger'; + end if; + + DELETE FROM hs_office_sepamandate_legacy_id + WHERE uuid = OLD.uuid; + + return OLD; +end; $$; + +create trigger removeSepaMandateLegacyIdMapping + before delete on hs_office_sepamandate + for each row +execute procedure deleteSepaMandateLegacyIdMapping(); +--/ diff --git a/src/main/resources/db/changelog/316-hs-office-coopshares-migration.sql b/src/main/resources/db/changelog/316-hs-office-coopshares-migration.sql new file mode 100644 index 00000000..105c1ebe --- /dev/null +++ b/src/main/resources/db/changelog/316-hs-office-coopshares-migration.sql @@ -0,0 +1,96 @@ +--liquibase formatted sql + +-- TODO: These changesets are just for the external remote views to simulate the legacy tables. +-- Once we don't need the external remote views anymore, create revert changesets. + +-- ============================================================================ +--changeset hs-office-coopshares-MIGRATION-mapping:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- + +CREATE TABLE hs_office_coopsharestransaction_legacy_id +( + uuid uuid NOT NULL REFERENCES hs_office_coopsharestransaction(uuid), + member_share_id integer NOT NULL +); +--// + + +-- ============================================================================ +--changeset hs-office-coopshares-MIGRATION-sequence:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- + +CREATE SEQUENCE IF NOT EXISTS hs_office_coopsharestransaction_legacy_id_seq + AS integer + START 1000000000 + OWNED BY hs_office_coopsharestransaction_legacy_id.member_share_id; +--// + + +-- ============================================================================ +--changeset hs-office-coopshares-MIGRATION-default:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- + +ALTER TABLE hs_office_coopsharestransaction_legacy_id + ALTER COLUMN member_share_id + SET DEFAULT nextVal('hs_office_coopsharestransaction_legacy_id_seq'); + +--/ + +-- ============================================================================ +--changeset hs-office-coopshares-MIGRATION-insert:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- + +CALL defineContext('schema-migration'); +INSERT INTO hs_office_coopsharestransaction_legacy_id(uuid, member_share_id) +SELECT uuid, nextVal('hs_office_coopsharestransaction_legacy_id_seq') FROM hs_office_coopsharestransaction; +--/ + + +-- ============================================================================ +--changeset hs-office-coopShares-MIGRATION-insert-trigger:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- +create or replace function insertCoopSharesLegacyIdMapping() + returns trigger + language plpgsql + strict as $$ +begin + if TG_OP <> 'INSERT' then + raise exception 'invalid usage of trigger'; + end if; + + INSERT INTO hs_office_coopsharestransaction_legacy_id VALUES + (NEW.uuid, nextVal('hs_office_coopsharestransaction_legacy_id_seq')); + + return NEW; +end; $$; + +create trigger createCoopSharesLegacyIdMapping + after insert on hs_office_coopsharestransaction + for each row +execute procedure insertCoopSharesLegacyIdMapping(); +--/ + + +-- ============================================================================ +--changeset hs-office-coopShares-MIGRATION-delete-trigger:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- +create or replace function deleteCoopSharesLegacyIdMapping() + returns trigger + language plpgsql + strict as $$ +begin + if TG_OP <> 'DELETE' then + raise exception 'invalid usage of trigger'; + end if; + + DELETE FROM hs_office_coopsharestransaction_legacy_id + WHERE uuid = OLD.uuid; + + return OLD; +end; $$; + +create trigger removeCoopSharesLegacyIdMapping + before delete on hs_office_coopsharestransaction + for each row +execute procedure deleteCoopSharesLegacyIdMapping(); +--/ diff --git a/src/main/resources/db/changelog/326-hs-office-coopassets-migration.sql b/src/main/resources/db/changelog/326-hs-office-coopassets-migration.sql new file mode 100644 index 00000000..ee432d73 --- /dev/null +++ b/src/main/resources/db/changelog/326-hs-office-coopassets-migration.sql @@ -0,0 +1,96 @@ +--liquibase formatted sql + +-- TODO: These changesets are just for the external remote views to simulate the legacy tables. +-- Once we don't need the external remote views anymore, create revert changesets. + +-- ============================================================================ +--changeset hs-office-coopassets-MIGRATION-mapping:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- + +CREATE TABLE hs_office_coopassetstransaction_legacy_id +( + uuid uuid NOT NULL REFERENCES hs_office_coopassetstransaction(uuid), + member_asstr_id integer NOT NULL +); +--// + + +-- ============================================================================ +--changeset hs-office-coopassets-MIGRATION-sequence:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- + +CREATE SEQUENCE IF NOT EXISTS hs_office_coopassetstransaction_legacy_id_seq + AS integer + START 1000000000 + OWNED BY hs_office_coopassetstransaction_legacy_id.member_asstr_id; +--// + + +-- ============================================================================ +--changeset hs-office-coopassets-MIGRATION-default:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- + +ALTER TABLE hs_office_coopassetstransaction_legacy_id + ALTER COLUMN member_asstr_id + SET DEFAULT nextVal('hs_office_coopassetstransaction_legacy_id_seq'); + +--/ + +-- ============================================================================ +--changeset hs-office-coopassets-MIGRATION-insert:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- + +CALL defineContext('schema-migration'); +INSERT INTO hs_office_coopassetstransaction_legacy_id(uuid, member_asstr_id) +SELECT uuid, nextVal('hs_office_coopassetstransaction_legacy_id_seq') FROM hs_office_coopassetstransaction; +--/ + + +-- ============================================================================ +--changeset hs-office-coopAssets-MIGRATION-insert-trigger:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- +create or replace function insertCoopAssetsLegacyIdMapping() + returns trigger + language plpgsql + strict as $$ +begin + if TG_OP <> 'INSERT' then + raise exception 'invalid usage of trigger'; + end if; + + INSERT INTO hs_office_coopassetstransaction_legacy_id VALUES + (NEW.uuid, nextVal('hs_office_coopassetstransaction_legacy_id_seq')); + + return NEW; +end; $$; + +create trigger createCoopAssetsLegacyIdMapping + after insert on hs_office_coopassetstransaction + for each row +execute procedure insertCoopAssetsLegacyIdMapping(); +--/ + + +-- ============================================================================ +--changeset hs-office-coopAssets-MIGRATION-delete-trigger:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- +create or replace function deleteCoopAssetsLegacyIdMapping() + returns trigger + language plpgsql + strict as $$ +begin + if TG_OP <> 'DELETE' then + raise exception 'invalid usage of trigger'; + end if; + + DELETE FROM hs_office_coopassetstransaction_legacy_id + WHERE uuid = OLD.uuid; + + return OLD; +end; $$; + +create trigger removeCoopAssetsLegacyIdMapping + before delete on hs_office_coopassetstransaction + for each row +execute procedure deleteCoopAssetsLegacyIdMapping(); +--/ diff --git a/src/main/resources/db/changelog/db.changelog-master.yaml b/src/main/resources/db/changelog/db.changelog-master.yaml index 3a1bb533..68719b66 100644 --- a/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/src/main/resources/db/changelog/db.changelog-master.yaml @@ -53,6 +53,8 @@ databaseChangeLog: file: db/changelog/200-hs-office-contact.sql - include: file: db/changelog/203-hs-office-contact-rbac.sql + - include: + file: db/changelog/206-hs-office-contact-migration.sql - include: file: db/changelog/208-hs-office-contact-test-data.sql - include: @@ -67,6 +69,8 @@ databaseChangeLog: file: db/changelog/223-hs-office-partner-rbac.sql - include: file: db/changelog/224-hs-office-partner-details-rbac.sql + - include: + file: db/changelog/226-hs-office-partner-migration.sql - include: file: db/changelog/228-hs-office-partner-test-data.sql - include: @@ -80,7 +84,7 @@ databaseChangeLog: - include: file: db/changelog/243-hs-office-bankaccount-rbac.sql - include: - file: db/changelog/248-hs-office-bankaccount-test-data.sql + file: db/changelog/248-hs-office-bankaccount-test-data.sql - include: file: db/changelog/270-hs-office-debitor.sql - include: @@ -91,6 +95,8 @@ databaseChangeLog: file: db/changelog/250-hs-office-sepamandate.sql - include: file: db/changelog/253-hs-office-sepamandate-rbac.sql + - include: + file: db/changelog/256-hs-office-sepamandate-migration.sql - include: file: db/changelog/258-hs-office-sepamandate-test-data.sql - include: @@ -103,11 +109,15 @@ databaseChangeLog: file: db/changelog/310-hs-office-coopshares.sql - include: file: db/changelog/313-hs-office-coopshares-rbac.sql + - include: + file: db/changelog/316-hs-office-coopshares-migration.sql - include: file: db/changelog/318-hs-office-coopshares-test-data.sql - include: file: db/changelog/320-hs-office-coopassets.sql - include: file: db/changelog/323-hs-office-coopassets-rbac.sql + - include: + file: db/changelog/326-hs-office-coopassets-migration.sql - include: file: db/changelog/328-hs-office-coopassets-test-data.sql