mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-01-09 11:41:32 +00:00
Using dullbananas trigger procedure
This commit is contained in:
parent
7fdbb58e98
commit
00beccd272
1 changed files with 25 additions and 47 deletions
|
@ -655,55 +655,33 @@ CREATE TRIGGER change_values
|
|||
|
||||
-- Combined tables triggers
|
||||
-- These insert (published, item_id) into X_combined tables
|
||||
-- Reports
|
||||
-- Comment
|
||||
CREATE FUNCTION r.report_combined_comment_report_insert ()
|
||||
RETURNS TRIGGER
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
-- Reports (comment_report, post_report, private_message_report)
|
||||
CREATE PROCEDURE r.create_report_combined_trigger (table_name text)
|
||||
LANGUAGE plpgsql
|
||||
AS $a$
|
||||
BEGIN
|
||||
INSERT INTO report_combined (published, comment_report_id)
|
||||
VALUES (NEW.published, NEW.id);
|
||||
RETURN NEW;
|
||||
END
|
||||
$$;
|
||||
EXECUTE replace($b$ CREATE FUNCTION r.report_combined_thing_insert ( )
|
||||
RETURNS TRIGGER
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
BEGIN
|
||||
INSERT INTO report_combined (published, thing_id)
|
||||
VALUES (NEW.published, NEW.id);
|
||||
RETURN NEW;
|
||||
END $$;
|
||||
CREATE TRIGGER report_combined
|
||||
AFTER INSERT ON thing
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION r.report_combined_thing_insert ( );
|
||||
$b$,
|
||||
'thing',
|
||||
table_name);
|
||||
END;
|
||||
$a$;
|
||||
|
||||
CREATE TRIGGER report_combined_comment
|
||||
AFTER INSERT ON comment_report
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION r.report_combined_comment_report_insert ();
|
||||
CALL r.create_report_combined_trigger ('post_report');
|
||||
|
||||
-- Post
|
||||
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
|
||||
$$;
|
||||
CALL r.create_report_combined_trigger ('comment_report');
|
||||
|
||||
CREATE TRIGGER report_combined_post
|
||||
AFTER INSERT ON post_report
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION r.report_combined_post_report_insert ();
|
||||
|
||||
-- Private message
|
||||
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 ();
|
||||
CALL r.create_report_combined_trigger ('private_message_report');
|
||||
|
||||
|
|
Loading…
Reference in a new issue