Regenerate the latest_build_status table
As it doesn't handle wierdness for statuses, like builds being canceled with a timestamp of 0.
This commit is contained in:
parent
efb26a616d
commit
6a04d474c0
4 changed files with 38 additions and 0 deletions
23
sqitch/deploy/regenerate_latest_build_status.sql
Normal file
23
sqitch/deploy/regenerate_latest_build_status.sql
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
-- Deploy guix-data-service:regenerate_latest_build_status to pg
|
||||
|
||||
BEGIN;
|
||||
|
||||
DELETE FROM latest_build_status;
|
||||
|
||||
INSERT INTO latest_build_status
|
||||
SELECT DISTINCT build_id,
|
||||
first_value(timestamp) OVER rows_for_build AS timestamp,
|
||||
first_value(status) OVER rows_for_build AS status
|
||||
FROM build_status
|
||||
WINDOW rows_for_build AS (
|
||||
PARTITION BY build_id
|
||||
ORDER BY
|
||||
CASE WHEN status = 'scheduled' THEN -2
|
||||
WHEN status = 'started' THEN -1
|
||||
ELSE 0
|
||||
END DESC,
|
||||
timestamp DESC
|
||||
RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
|
||||
);
|
||||
|
||||
COMMIT;
|
||||
Loading…
Add table
Add a link
Reference in a new issue