From aff974c03f27223588dc9b13c8cb201ba8770a86 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Sun, 15 May 2022 13:20:01 +0200 Subject: [PATCH] Modify log_midnight_shots() to remove non-relevant midnight shots. Those shots could for instance have been removed to a line edit. --- ...rade25-v0.3.12-add-midnight-shots-procedure.sql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/etc/db/upgrades/upgrade25-v0.3.12-add-midnight-shots-procedure.sql b/etc/db/upgrades/upgrade25-v0.3.12-add-midnight-shots-procedure.sql index b9e7704..13a9047 100644 --- a/etc/db/upgrades/upgrade25-v0.3.12-add-midnight-shots-procedure.sql +++ b/etc/db/upgrades/upgrade25-v0.3.12-add-midnight-shots-procedure.sql @@ -117,6 +117,20 @@ BEGIN FROM event_log el WHERE ms.sequence = el.sequence AND ms.point = el.point AND el.labels @> ms.labels ); + + -- Delete any midnight shots that might have been inserted in the log + -- but are no longer relevant according to the final_shots data. + -- We operate on event_log, so the deletion is traceable. + DELETE + FROM event_log + WHERE id IN ( + SELECT id + FROM event_log el + LEFT JOIN midnight_shots ms USING (sequence, point) + WHERE + '{LDSP,FDSP}'::text[] && el.labels -- &&: Do the arrays overlap? + AND ms.sequence IS NULL + ); $$; COMMENT ON PROCEDURE log_midnight_shots (date, date)