From 6093f341d647c4029918f94cad87192d78a62ec9 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Wed, 27 Dec 2023 20:20:44 -0700 Subject: [PATCH] Remove truncate trigger because truncate is already restricted by foreign keys --- replaceable_schema.sql | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/replaceable_schema.sql b/replaceable_schema.sql index a1d22e0c2..6842c3858 100644 --- a/replaceable_schema.sql +++ b/replaceable_schema.sql @@ -65,21 +65,9 @@ BEGIN EXECUTE format('CREATE TRIGGER %2$s_insert AFTER INSERT ON %1$s REFERENCING NEW TABLE AS new_table FOR EACH STATEMENT EXECUTE FUNCTION r.%2$s ();', table_name, function_name); EXECUTE format('CREATE TRIGGER %2$s_delete AFTER DELETE ON %1$s REFERENCING OLD TABLE AS old_table FOR EACH STATEMENT EXECUTE FUNCTION r.%2$s ();', table_name, function_name); EXECUTE format('CREATE TRIGGER %2$s_update AFTER UPDATE ON %1$s REFERENCING OLD TABLE AS old_table NEW TABLE AS new_table FOR EACH STATEMENT EXECUTE FUNCTION r.%2$s ();', table_name, function_name); - -- Prevent admin from running `TRUNCATE` because it doesn't allow reading old rows which is needed by triggers - EXECUTE format('CREATE OR REPLACE TRIGGER no_truncate BEFORE TRUNCATE ON %s FOR EACH STATEMENT EXECUTE FUNCTION r.no_truncate ();', table_name); END $$; -CREATE FUNCTION r.no_truncate () - RETURNS TRIGGER - LANGUAGE plpgsql - AS $$ -BEGIN - RAISE EXCEPTION 'Run DELETE instead'; - RETURN NULL; -END -$$; - -- Define functions CREATE FUNCTION r.creator_id_from_post_aggregates (agg post_aggregates) RETURNS int RETURN agg.creator_id;