Update replaceable_schema.sql

This commit is contained in:
dullbananas 2023-12-25 09:02:32 -07:00 committed by GitHub
parent 0f200435d7
commit e6dc68d6d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -59,7 +59,7 @@ CREATE PROCEDURE r.resolve_reports_when_target_removed (target_name text)
LANGUAGE plpgsql LANGUAGE plpgsql
AS $a$ AS $a$
BEGIN BEGIN
EXECUTE format($b$ CREATE FUNCTION r.resolve_reports_when_%1 $ s_removed ( ) EXECUTE format($b$ CREATE FUNCTION r.resolve_reports_when_%1$s_removed ( )
RETURNS TRIGGER RETURNS TRIGGER
LANGUAGE plpgsql LANGUAGE plpgsql
AS $$ AS $$
@ -70,14 +70,14 @@ BEGIN
resolved = TRUE, resolver_id = mod_person_id, updated = now() resolved = TRUE, resolver_id = mod_person_id, updated = now()
FROM new_removal FROM new_removal
WHERE WHERE
report.%1$s_id = new_removal.%1$a_id report.%1$s_id = new_removal.%1$s_id
AND new_removal.removed; AND new_removal.removed;
RETURN NULL; RETURN NULL;
END $$; END $$;
CREATE TRIGGER resolve_reports CREATE TRIGGER resolve_reports
AFTER INSERT ON mod_remove_ %1$s REFERENCING NEW TABLE AS new_removal AFTER INSERT ON mod_remove_%1$s REFERENCING NEW TABLE AS new_removal
FOR EACH STATEMENT FOR EACH STATEMENT
EXECUTE FUNCTION r.resolve_reports_when_ %1 $ s_removed ( ); EXECUTE FUNCTION r.resolve_reports_when_%1$s_removed ( );
$b$, $b$,
target_name); target_name);
END END
@ -214,8 +214,8 @@ BEGIN
LANGUAGE plpgsql LANGUAGE plpgsql
AS $$ AS $$
BEGIN BEGIN
-- Update aggregates for target, then update aggregates for target's creator
WITH WITH
-- Update aggregates for target
target_diff ( target_diff (
creator_id, score creator_id, score
) AS ( UPDATE ) AS ( UPDATE
@ -230,11 +230,10 @@ BEGIN
target_aggregates.comment_id = diff.target_id target_aggregates.comment_id = diff.target_id
RETURNING RETURNING
%2$s, diff.upvotes - diff.downvotes) %2$s, diff.upvotes - diff.downvotes)
-- Update aggregates for target's creator
UPDATE UPDATE
person_aggregates person_aggregates
SET SET
%1$s_score = %1$s_score + diff.score; %1$s_score = %1$s_score + diff.score
FROM ( FROM (
SELECT SELECT
creator_id, creator_id,