From 90fa732f8d1c5d92964b30189cf73f9bf37a413c Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc kop@karlpinc.com" Date: Fri, 3 Oct 2025 22:07:47 +0000 Subject: [PATCH] Initial trigger on EVENTS, prevent EID change --- db/schemas/lib/triggers/Makefile | 3 +- db/schemas/lib/triggers/create/events.m4 | 52 ++++++++++++++++++++++++ db/schemas/lib/triggers/drop/events.m4 | 23 +++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 db/schemas/lib/triggers/create/events.m4 create mode 100644 db/schemas/lib/triggers/drop/events.m4 diff --git a/db/schemas/lib/triggers/Makefile b/db/schemas/lib/triggers/Makefile index 5722070..be84aec 100644 --- a/db/schemas/lib/triggers/Makefile +++ b/db/schemas/lib/triggers/Makefile @@ -29,7 +29,8 @@ ORDER := comm_ids \ _error_immutable_view \ follow_observers \ biography \ - follows + follows \ + events DROP_EXISTING := true diff --git a/db/schemas/lib/triggers/create/events.m4 b/db/schemas/lib/triggers/create/events.m4 new file mode 100644 index 0000000..e52c217 --- /dev/null +++ b/db/schemas/lib/triggers/create/events.m4 @@ -0,0 +1,52 @@ +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 it +dnl 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 the follows table +dnl +dnl Karl O. Pinc + +dnl m4 includes +include(`copyright.m4')dnl +include(`constants.m4')dnl +include(`macros.m4')dnl + + +RAISE INFO 'events_func'; +CREATE OR REPLACE FUNCTION events_func () + RETURNS trigger + LANGUAGE plpgsql + sdb_function_set_search_path + AS $$ + BEGIN + -- Function for events insert and update triggers + -- + -- AGPL_notice(` --', `2025', + `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') + END IF; + + RETURN NULL; + END; +$$; + + +RAISE INFO 'events_trigger'; +CREATE TRIGGER events_trigger + AFTER INSERT OR UPDATE + ON events FOR EACH ROW + EXECUTE PROCEDURE events_func(); diff --git a/db/schemas/lib/triggers/drop/events.m4 b/db/schemas/lib/triggers/drop/events.m4 new file mode 100644 index 0000000..edb9ac4 --- /dev/null +++ b/db/schemas/lib/triggers/drop/events.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 events table +dnl +dnl Karl O. Pinc + +dnl m4 includes +include(`copyright.m4')dnl + +DROP FUNCTION IF EXISTS events_func() CASCADE; -- 2.34.1