mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-01 16:51:21 +00:00
Update replaceable_schema.sql
This commit is contained in:
parent
8a36657ea0
commit
5606a8c6cf
1 changed files with 26 additions and 2 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue