Update replaceable_schema.sql

This commit is contained in:
dullbananas 2023-12-22 23:27:02 -07:00 committed by GitHub
parent 8a36657ea0
commit 5606a8c6cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,7 +21,30 @@ CREATE SCHEMA r;
-- These triggers create and update rows in each aggregates table to match its associated table's rows. -- These triggers create and update rows in each aggregates table to match its associated table's rows.
-- Deleting rows and updating IDs are already handled by `CASCADE` in foreign key constraints. -- Deleting rows and updating IDs are already handled by `CASCADE` in foreign key constraints.
CREATE FUNCTION r.community_aggregates_from_community () RETURNS trigger CREATE FUNCTION comment_aggregates_from_comment ()
RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
INSERT INTO comment_aggregates (comment_id, published)
SELECT
id,
published
FROM
new_comment;
RETURN NULL;
END
$$;
CREATE TRIGGER aggregates
AFTER INSERT ON comment
REFERENCING NEW TABLE AS new_comment
FOR EACH STATEMENT
EXECUTE FUNCTION r.comment_aggregates_from_comment ();
CREATE FUNCTION r.community_aggregates_from_community ()
RETURNS trigger
LANGUAGE plpgsql LANGUAGE plpgsql
AS $$ AS $$
BEGIN BEGIN
@ -42,7 +65,8 @@ CREATE TRIGGER aggregates
FOR EACH STATEMENT FOR EACH STATEMENT
EXECUTE FUNCTION r.community_aggregates_from_community (); EXECUTE FUNCTION r.community_aggregates_from_community ();
CREATE FUNCTION r.post_aggregates_from_post () RETURNS trigger CREATE FUNCTION r.post_aggregates_from_post ()
RETURNS trigger
LANGUAGE plpgsql LANGUAGE plpgsql
AS $$ AS $$
BEGIN BEGIN