mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-01-24 10:55:56 +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
|
-- 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
|
||||||
RETURNS TRIGGER
|
AS $a$
|
||||||
LANGUAGE plpgsql
|
|
||||||
AS $$
|
|
||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO report_combined (published, comment_report_id)
|
EXECUTE replace($b$ CREATE FUNCTION r.report_combined_thing_insert ( )
|
||||||
VALUES (NEW.published, NEW.id);
|
RETURNS TRIGGER
|
||||||
RETURN NEW;
|
LANGUAGE plpgsql
|
||||||
END
|
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
|
CALL r.create_report_combined_trigger ('post_report');
|
||||||
AFTER INSERT ON comment_report
|
|
||||||
FOR EACH ROW
|
|
||||||
EXECUTE FUNCTION r.report_combined_comment_report_insert ();
|
|
||||||
|
|
||||||
-- Post
|
CALL r.create_report_combined_trigger ('comment_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 ('private_message_report');
|
||||||
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 ();
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue