2024-01-05 08:19:49 +01:00
|
|
|
--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.
|
|
|
|
|
|
|
|
-- ============================================================================
|
2024-09-16 15:36:37 +02:00
|
|
|
--changeset michael.hoennig:hs-office-coopassets-MIGRATION-mapping endDelimiter:--//
|
2024-01-05 08:19:49 +01:00
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
|
2024-09-18 10:28:21 +02:00
|
|
|
CREATE TABLE hs_office.coopassetstransaction_legacy_id
|
2024-01-05 08:19:49 +01:00
|
|
|
(
|
2024-09-18 10:28:21 +02:00
|
|
|
uuid uuid NOT NULL REFERENCES hs_office.coopassetstransaction(uuid),
|
2024-01-05 10:52:15 +01:00
|
|
|
member_asset_id integer NOT NULL
|
2024-01-05 08:19:49 +01:00
|
|
|
);
|
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2024-09-16 15:36:37 +02:00
|
|
|
--changeset michael.hoennig:hs-office-coopassets-MIGRATION-sequence endDelimiter:--//
|
2024-01-05 08:19:49 +01:00
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
|
2024-09-18 10:28:21 +02:00
|
|
|
CREATE SEQUENCE IF NOT EXISTS hs_office.coopassetstransaction_legacy_id_seq
|
2024-01-05 08:19:49 +01:00
|
|
|
AS integer
|
|
|
|
START 1000000000
|
2024-09-18 10:28:21 +02:00
|
|
|
OWNED BY hs_office.coopassetstransaction_legacy_id.member_asset_id;
|
2024-01-05 08:19:49 +01:00
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2024-09-16 15:36:37 +02:00
|
|
|
--changeset michael.hoennig:hs-office-coopassets-MIGRATION-default endDelimiter:--//
|
2024-01-05 08:19:49 +01:00
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
|
2024-09-18 10:28:21 +02:00
|
|
|
ALTER TABLE hs_office.coopassetstransaction_legacy_id
|
2024-01-05 10:52:15 +01:00
|
|
|
ALTER COLUMN member_asset_id
|
2024-09-18 10:28:21 +02:00
|
|
|
SET DEFAULT nextVal('hs_office.coopassetstransaction_legacy_id_seq');
|
2024-01-05 08:19:49 +01:00
|
|
|
--/
|
|
|
|
|
2024-01-05 10:52:15 +01:00
|
|
|
|
2024-01-05 08:19:49 +01:00
|
|
|
-- ============================================================================
|
2024-09-16 15:36:37 +02:00
|
|
|
--changeset michael.hoennig:hs-office-coopassets-MIGRATION-insert endDelimiter:--//
|
2024-01-05 08:19:49 +01:00
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
|
2024-09-16 15:36:37 +02:00
|
|
|
CALL base.defineContext('schema-migration');
|
2024-09-18 10:28:21 +02:00
|
|
|
INSERT INTO hs_office.coopassetstransaction_legacy_id(uuid, member_asset_id)
|
|
|
|
SELECT uuid, nextVal('hs_office.coopassetstransaction_legacy_id_seq') FROM hs_office.coopassetstransaction;
|
2024-01-05 08:19:49 +01:00
|
|
|
--/
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2024-09-16 15:36:37 +02:00
|
|
|
--changeset michael.hoennig:hs-office-coopAssets-MIGRATION-insert-trigger endDelimiter:--//
|
2024-01-05 08:19:49 +01:00
|
|
|
-- ----------------------------------------------------------------------------
|
2024-09-20 08:44:35 +02:00
|
|
|
create or replace function hs_office.coopassettx_insert_legacy_id_mapping_tf()
|
2024-01-05 08:19:49 +01:00
|
|
|
returns trigger
|
|
|
|
language plpgsql
|
|
|
|
strict as $$
|
|
|
|
begin
|
|
|
|
if TG_OP <> 'INSERT' then
|
|
|
|
raise exception 'invalid usage of trigger';
|
|
|
|
end if;
|
|
|
|
|
2024-09-18 10:28:21 +02:00
|
|
|
INSERT INTO hs_office.coopassetstransaction_legacy_id VALUES
|
|
|
|
(NEW.uuid, nextVal('hs_office.coopassetstransaction_legacy_id_seq'));
|
2024-01-05 08:19:49 +01:00
|
|
|
|
|
|
|
return NEW;
|
|
|
|
end; $$;
|
|
|
|
|
2024-09-20 08:44:35 +02:00
|
|
|
create trigger insert_legacy_id_mapping_tg
|
2024-09-18 10:28:21 +02:00
|
|
|
after insert on hs_office.coopassetstransaction
|
2024-01-05 10:52:15 +01:00
|
|
|
for each row
|
2024-09-20 08:44:35 +02:00
|
|
|
execute procedure hs_office.coopassettx_insert_legacy_id_mapping_tf();
|
2024-01-05 08:19:49 +01:00
|
|
|
--/
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2024-09-16 15:36:37 +02:00
|
|
|
--changeset michael.hoennig:hs-office-coopAssets-MIGRATION-delete-trigger endDelimiter:--//
|
2024-01-05 08:19:49 +01:00
|
|
|
-- ----------------------------------------------------------------------------
|
2024-09-20 08:44:35 +02:00
|
|
|
create or replace function hs_office.coopassettx_delete_legacy_id_mapping_tf()
|
2024-01-05 08:19:49 +01:00
|
|
|
returns trigger
|
|
|
|
language plpgsql
|
|
|
|
strict as $$
|
|
|
|
begin
|
|
|
|
if TG_OP <> 'DELETE' then
|
|
|
|
raise exception 'invalid usage of trigger';
|
|
|
|
end if;
|
|
|
|
|
2024-09-18 10:28:21 +02:00
|
|
|
DELETE FROM hs_office.coopassetstransaction_legacy_id
|
2024-01-05 08:19:49 +01:00
|
|
|
WHERE uuid = OLD.uuid;
|
|
|
|
|
|
|
|
return OLD;
|
|
|
|
end; $$;
|
|
|
|
|
2024-09-20 08:44:35 +02:00
|
|
|
create trigger delete_legacy_id_mapping_tg
|
2024-09-18 10:28:21 +02:00
|
|
|
before delete on hs_office.coopassetstransaction
|
2024-01-05 10:52:15 +01:00
|
|
|
for each row
|
2024-09-20 08:44:35 +02:00
|
|
|
execute procedure hs_office.coopassettx_delete_legacy_id_mapping_tf();
|
2024-01-05 08:19:49 +01:00
|
|
|
--/
|