Update replaceable_schema.sql

This commit is contained in:
dullbananas 2023-12-27 11:23:09 -07:00 committed by GitHub
parent b97a039c45
commit 0a93d1979c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -86,16 +86,19 @@ BEGIN
UPDATE UPDATE
thing_report thing_report
SET SET
resolved = TRUE, resolver_id = mod_person_id, updated = now() resolved = TRUE, resolver_id = first_removal.mod_person_id, updated = first_removal.when_
FROM ( SELECT DISTINCT FROM ( SELECT
thing_id thing_id,
min(when_) AS when_
FROM new_removal FROM new_removal
WHERE WHERE
new_removal.removed) AS distinct_removal new_removal.removed
GROUP BY
thing_id) AS first_removal
WHERE WHERE
report.thing_id = distinct_removal.thing_id report.thing_id = first_removal.thing_id
AND NOT report.resolved AND NOT report.resolved
AND COALESCE(report.updated < now(), TRUE); AND COALESCE(report.updated < first_removal.when_, TRUE);
RETURN NULL; RETURN NULL;
END $$; END $$;
CREATE TRIGGER resolve_reports CREATE TRIGGER resolve_reports