OXYGENHUB
# 4866be1c9040 oxygenhub / crates / hub / migrations / 0019_flow_run_numbers.sql
628 B · SQL · last changed Number Flow runs per repository 1 month ago source blame history raw
1
-- Runs are numbered per repository (1, 2, 3 …), not by the hub-wide row id.
2
ALTER TABLE flow_runs ADD COLUMN number INTEGER NOT NULL DEFAULT 0;
3
UPDATE flow_runs SET number = (
4
    SELECT COUNT(*) FROM flow_runs r2 WHERE r2.repo_id = flow_runs.repo_id AND r2.id <= flow_runs.id
5
);
6
CREATE UNIQUE INDEX flow_runs_number ON flow_runs (repo_id, number);
7
-- Checks link to their run's page by number now.
8
UPDATE checks SET url = substr(checks.url, 1, length(checks.url) - length(CAST(r.id AS TEXT))) || r.number
9
FROM flow_runs r
10
WHERE checks.repo_id = r.repo_id AND checks.name LIKE 'flow/%' AND checks.url LIKE '%/flow/' || r.id;