From b60d878db83c919d543b24d871a92c15b1957eb8 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc kop@karlpinc.com" Date: Sun, 21 Sep 2025 19:06:39 +0000 Subject: [PATCH] Enforce PEOPLE.Active on FOLLOW_OBSERVERS --- db/schemas/lib/triggers/Makefile | 1 + .../lib/triggers/create/follow_observers.m4 | 83 +++++++++++++++++++ .../lib/triggers/drop/follow_observers.m4 | 23 +++++ 3 files changed, 107 insertions(+) create mode 100644 db/schemas/lib/triggers/create/follow_observers.m4 create mode 100644 db/schemas/lib/triggers/drop/follow_observers.m4 diff --git a/db/schemas/lib/triggers/Makefile b/db/schemas/lib/triggers/Makefile index 1476733..e1361f4 100644 --- a/db/schemas/lib/triggers/Makefile +++ b/db/schemas/lib/triggers/Makefile @@ -24,6 +24,7 @@ ORDER := comm_ids \ biography_data \ comm_membs \ _error_immutable_view \ + follow_observers \ biography DROP_EXISTING := true diff --git a/db/schemas/lib/triggers/create/follow_observers.m4 b/db/schemas/lib/triggers/create/follow_observers.m4 new file mode 100644 index 0000000..94257c8 --- /dev/null +++ b/db/schemas/lib/triggers/create/follow_observers.m4 @@ -0,0 +1,83 @@ +dnl Copyright (C) 2025 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 +dnl the Free Software Foundation, either version 3 of the License, or +dnl (at your option) any later version. +dnl +dnl This program is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +dnl GNU Affero General Public License for more details. +dnl +dnl You should have received a copy of the GNU Affero General Public License +dnl along with this program. If not, see . +dnl +dnl Triggers for follow_observers table +dnl +dnl Karl O. Pinc + +dnl m4 includes +include(`copyright.m4')dnl +include(`constants.m4')dnl +include(`macros.m4')dnl + +RAISE INFO 'follow_observers_func'; +CREATE OR REPLACE FUNCTION follow_observers_func () + RETURNS trigger + LANGUAGE plpgsql + sdb_function_set_search_path + AS $$ + BEGIN + -- Function for follow_observers insert and update triggers + -- + -- AGPL_notice(` --', `2025', + `The Meme Factory, Inc., www.karlpinc.com') + + changequote({,})dnl + person_active({FOLLOW_OBSERVERS}, {OBS_BRec}, + {'Key (FOID) = (' + || NEW.FOID + || '): Value (FID) = (' + || NEW.FID + || '): ' + || (SELECT 'Value (FOLLOWS.Focal) = (' + || follows.focal + || '): Value (FOLLOWS.Community) = (' + || follows.community + || '): Value (FOLLOWS.Date) = (' + || follows.date + || '): ' + FROM follows + WHERE follows.fid = NEW.fid) + || '(Period) = (' + || NEW.period + || ')'}) + person_active({FOLLOW_OBSERVERS}, {OBS_Tiki}, + {'Key (FOID) = (' + || NEW.FOID + || '): Value (FID) = (' + || NEW.FID + || '): ' + || (SELECT 'Value (FOLLOWS.Focal) = (' + || follows.focal + || '): Value (FOLLOWS.Community) = (' + || follows.community + || '): Value (FOLLOWS.Date) = (' + || follows.date + || '): ' + FROM follows + WHERE follows.fid = NEW.fid) + || 'Value (Period) = (' + || NEW.period + || ')'}) + changequote(`,')dnl + RETURN NULL; + END; +$$; + +RAISE INFO 'follow_observers_trigger'; +CREATE TRIGGER follow_observers_trigger + AFTER INSERT OR UPDATE + ON follow_observers FOR EACH ROW + EXECUTE PROCEDURE follow_observers_func(); diff --git a/db/schemas/lib/triggers/drop/follow_observers.m4 b/db/schemas/lib/triggers/drop/follow_observers.m4 new file mode 100644 index 0000000..1ff12bf --- /dev/null +++ b/db/schemas/lib/triggers/drop/follow_observers.m4 @@ -0,0 +1,23 @@ +dnl Copyright (C) 2025 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 +dnl the Free Software Foundation, either version 3 of the License, or +dnl (at your option) any later version. +dnl +dnl This program is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +dnl GNU Affero General Public License for more details. +dnl +dnl You should have received a copy of the GNU Affero General Public License +dnl along with this program. If not, see . +dnl +dnl Drop triggers for the follow_observers table +dnl +dnl Karl O. Pinc + +dnl m4 includes +include(`copyright.m4')dnl + +DROP FUNCTION IF EXISTS follow_observers_func() CASCADE; -- 2.34.1