From bada6dc2e27b8890cc81a673ddd2fa75410faac1 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Sun, 15 May 2022 13:19:01 +0200 Subject: [PATCH] Modify DB upgrade file 25 to use final_shots --- ...5-v0.3.12-add-midnight-shots-procedure.sql | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) 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 90fd4d5..b9e7704 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 @@ -51,7 +51,7 @@ BEGIN WITH straddlers AS ( -- Get sequence numbers straddling midnight UTC SELECT sequence - FROM raw_shots + FROM final_shots GROUP BY sequence HAVING min(date(tstamp)) != max(date(tstamp)) ), @@ -61,12 +61,12 @@ BEGIN -- This will return the timestamps for: -- FSP, LDSP, FDSP, LSP. SELECT - rs.sequence, - min(rs.tstamp) AS ts0, - max(rs.tstamp) AS ts1 - FROM raw_shots rs INNER JOIN straddlers USING (sequence) - GROUP BY rs.sequence, (date(rs.tstamp)) - ORDER BY rs.sequence, date(rs.tstamp) + fs.sequence, + min(fs.tstamp) AS ts0, + max(fs.tstamp) AS ts1 + FROM final_shots fs INNER JOIN straddlers USING (sequence) + GROUP BY fs.sequence, (date(fs.tstamp)) + ORDER BY fs.sequence, date(fs.tstamp) ), spts AS ( -- Filter out FSP, LSP from the above. @@ -81,21 +81,21 @@ BEGIN ORDER BY sequence ), evt AS ( SELECT - rs.tstamp, - rs.sequence, + fs.tstamp, + fs.sequence, point, 'Last shotpoint of the day' remarks, '{LDSP}'::text[] labels - FROM raw_shots rs - INNER JOIN spts ON rs.sequence = spts.sequence AND rs.tstamp = spts.ldsp + FROM final_shots fs + INNER JOIN spts ON fs.sequence = spts.sequence AND fs.tstamp = spts.ldsp UNION SELECT - rs.tstamp, - rs.sequence, + fs.tstamp, + fs.sequence, point, 'First shotpoint of the day' remarks, '{FDSP}'::text[] labels - FROM raw_shots rs - INNER JOIN spts ON rs.sequence = spts.sequence AND rs.tstamp = spts.fdsp + FROM final_shots fs + INNER JOIN spts ON fs.sequence = spts.sequence AND fs.tstamp = spts.fdsp ORDER BY tstamp ) SELECT * FROM evt; @@ -104,8 +104,10 @@ BEGIN CREATE OR REPLACE PROCEDURE log_midnight_shots (dt0 date, dt1 date) LANGUAGE sql AS $$ - INSERT INTO event_log (sequence, point, remarks, labels) - SELECT sequence, point, remarks, labels + INSERT INTO event_log (sequence, point, remarks, labels, meta) + SELECT + sequence, point, remarks, labels, + '{"auto": true, "insertedBy": "log_midnight_shots"}'::jsonb FROM midnight_shots ms WHERE (dt0 IS NULL OR ms.tstamp >= dt0) AND