From 0a93d1979c5775fb82c035a19e2a4ed7d9c2e059 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Wed, 27 Dec 2023 11:23:09 -0700 Subject: [PATCH] Update replaceable_schema.sql --- replaceable_schema.sql | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/replaceable_schema.sql b/replaceable_schema.sql index 7605d9542..2c206b4ae 100644 --- a/replaceable_schema.sql +++ b/replaceable_schema.sql @@ -86,16 +86,19 @@ BEGIN UPDATE thing_report SET - resolved = TRUE, resolver_id = mod_person_id, updated = now() - FROM ( SELECT DISTINCT - thing_id + resolved = TRUE, resolver_id = first_removal.mod_person_id, updated = first_removal.when_ + FROM ( SELECT + thing_id, + min(when_) AS when_ FROM new_removal WHERE - new_removal.removed) AS distinct_removal + new_removal.removed + GROUP BY + thing_id) AS first_removal WHERE - report.thing_id = distinct_removal.thing_id + report.thing_id = first_removal.thing_id AND NOT report.resolved - AND COALESCE(report.updated < now(), TRUE); + AND COALESCE(report.updated < first_removal.when_, TRUE); RETURN NULL; END $$; CREATE TRIGGER resolve_reports