From fdad7f715f23c56084752c32bd63be562fbf274a Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc kop@karlpinc.com" Date: Thu, 4 Jun 2026 18:00:01 +0000 Subject: [PATCH] Simplify because events only fire on update --- db/schemas/lib/triggers/create/events.m4 | 52 ++++++++++++------------ db/schemas/lib/triggers/drop/events.m4 | 4 +- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/db/schemas/lib/triggers/create/events.m4 b/db/schemas/lib/triggers/create/events.m4 index 5a0ce01..7c4cd95 100644 --- a/db/schemas/lib/triggers/create/events.m4 +++ b/db/schemas/lib/triggers/create/events.m4 @@ -1,4 +1,4 @@ -dnl Copyright (C) 2025 The Meme Factory, Inc. http://www.karlpinc.com/ +dnl Copyright (C) 2025, 2026 The Meme Factory, Inc. http://www.karlpinc.com/ dnl dnl This program is free software: you can redistribute it and/or modify it dnl under the terms of the GNU Affero General Public License as published by @@ -23,48 +23,46 @@ include(`constants.m4')dnl include(`macros.m4')dnl -RAISE INFO 'events_func'; -CREATE OR REPLACE FUNCTION events_func () +RAISE INFO 'events_update_func'; +CREATE OR REPLACE FUNCTION events_update_func () RETURNS trigger LANGUAGE plpgsql sdb_function_set_search_path AS $$ BEGIN - -- Function for events insert and update triggers + -- Function for events update trigger -- - -- AGPL_notice(` --', `2025', + -- AGPL_notice(` --', `2025, 2026', `The Meme Factory, Inc., www.karlpinc.com') - IF TG_OP = 'UPDATE' THEN - -- Allowing the EID to change makes life too complicated. - cannot_change(`EVENTS', `EID') + -- Allowing the EID to change makes life too complicated. + cannot_change(`EVENTS', `EID') - -- If the FID is allowed to change, at minimum -- there may be other - -- cases, the check that ROLES.Participant must be under study - -- becomes complicated. It would require code in the triggers - -- to trace the BIOGRAPHY_DATA.Animid <- ROLES.Participant -> - -- EVENTS.EID --> FOLLOWS.FID chain to check FOLLOWS.Date - -- against biography. Simpler to dis-allow change. - cannot_change(`EVENTS', `FID') + -- If the FID is allowed to change, at minimum -- there may be other + -- cases, the check that ROLES.Participant must be under study + -- becomes complicated. It would require code in the triggers + -- to trace the BIOGRAPHY_DATA.Animid <- ROLES.Participant -> + -- EVENTS.EID --> FOLLOWS.FID chain to check FOLLOWS.Date + -- against biography. Simpler to dis-allow change. + cannot_change(`EVENTS', `FID') - -- Likewise, allowing the AtID to change adds too much complication. - cannot_change(`EVENTS', `AtID') + -- Likewise, allowing the AtID to change adds too much complication. + cannot_change(`EVENTS', `AtID') - -- If the Behavior is allowed to change, we need to add code here - -- that checks all the tables related to the participants and the - -- various event detail tables. This is way too much code; it is - -- easier to prevent the behavior from changing and instead - -- require the old rows be deleted and then new ones added. - cannot_change(`EVENTS', `Behavior') - END IF; + -- If the Behavior is allowed to change, we need to add code here + -- that checks all the tables related to the participants and the + -- various event detail tables. This is way too much code; it is + -- easier to prevent the behavior from changing and instead + -- require the old rows be deleted and then new ones added. + cannot_change(`EVENTS', `Behavior') RETURN NULL; END; $$; -RAISE INFO 'events_trigger'; -CREATE TRIGGER events_trigger +RAISE INFO 'events_update_trigger'; +CREATE TRIGGER events_update_trigger AFTER INSERT OR UPDATE ON events FOR EACH ROW - EXECUTE PROCEDURE events_func(); + EXECUTE PROCEDURE events_update_func(); diff --git a/db/schemas/lib/triggers/drop/events.m4 b/db/schemas/lib/triggers/drop/events.m4 index edb9ac4..41f2c9b 100644 --- a/db/schemas/lib/triggers/drop/events.m4 +++ b/db/schemas/lib/triggers/drop/events.m4 @@ -1,4 +1,4 @@ -dnl Copyright (C) 2025 The Meme Factory, Inc. http://www.karlpinc.com/ +dnl Copyright (C) 2025, 2026 The Meme Factory, Inc. http://www.karlpinc.com/ dnl dnl This program is free software: you can redistribute it and/or modify dnl it under the terms of the GNU Affero General Public License as published by @@ -20,4 +20,4 @@ dnl Karl O. Pinc dnl m4 includes include(`copyright.m4')dnl -DROP FUNCTION IF EXISTS events_func() CASCADE; +DROP FUNCTION IF EXISTS events_update_func() CASCADE; -- 2.34.1