Using dullbananas trigger procedure

This commit is contained in:
Dessalines 2024-12-02 13:46:51 -05:00
parent 7fdbb58e98
commit 00beccd272

View file

@ -655,55 +655,33 @@ CREATE TRIGGER change_values
-- Combined tables triggers -- Combined tables triggers
-- These insert (published, item_id) into X_combined tables -- These insert (published, item_id) into X_combined tables
-- Reports -- Reports (comment_report, post_report, private_message_report)
-- Comment CREATE PROCEDURE r.create_report_combined_trigger (table_name text)
CREATE FUNCTION r.report_combined_comment_report_insert () LANGUAGE plpgsql
AS $a$
BEGIN
EXECUTE replace($b$ CREATE FUNCTION r.report_combined_thing_insert ( )
RETURNS TRIGGER RETURNS TRIGGER
LANGUAGE plpgsql LANGUAGE plpgsql
AS $$ AS $$
BEGIN BEGIN
INSERT INTO report_combined (published, comment_report_id) INSERT INTO report_combined (published, thing_id)
VALUES (NEW.published, NEW.id); VALUES (NEW.published, NEW.id);
RETURN NEW; RETURN NEW;
END END $$;
$$; CREATE TRIGGER report_combined
AFTER INSERT ON thing
CREATE TRIGGER report_combined_comment
AFTER INSERT ON comment_report
FOR EACH ROW FOR EACH ROW
EXECUTE FUNCTION r.report_combined_comment_report_insert (); EXECUTE FUNCTION r.report_combined_thing_insert ( );
$b$,
'thing',
table_name);
END;
$a$;
-- Post CALL r.create_report_combined_trigger ('post_report');
CREATE FUNCTION r.report_combined_post_report_insert ()
RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
BEGIN
INSERT INTO report_combined (published, post_report_id)
VALUES (NEW.published, NEW.id);
RETURN NEW;
END
$$;
CREATE TRIGGER report_combined_post CALL r.create_report_combined_trigger ('comment_report');
AFTER INSERT ON post_report
FOR EACH ROW
EXECUTE FUNCTION r.report_combined_post_report_insert ();
-- Private message CALL r.create_report_combined_trigger ('private_message_report');
CREATE FUNCTION r.report_combined_private_message_report_insert ()
RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
BEGIN
INSERT INTO report_combined (published, private_message_report_id)
VALUES (NEW.published, NEW.id);
RETURN NEW;
END
$$;
CREATE TRIGGER report_combined_private_message
AFTER INSERT ON private_message_report
FOR EACH ROW
EXECUTE FUNCTION r.report_combined_private_message_report_insert ();