OXYGENHUB
◆ v0.9.19 oxygenhub / crates / hub / migrations / 0033_flow_cancelled.sql
3.5 KiB · SQL · last changed Cancel runs from oh, the run page, and newer pushes 1 month ago source blame history raw
745d225d Andy McCall ↶ 1
-- Cancelled runs and jobs (oxygenflow#32). SQLite cannot change a CHECK
2
-- constraint in place, so both tables are rebuilt. Migrations run with
3
-- foreign keys off (db::migrate), or dropping flow_jobs would take its
4
-- logs and artifacts with it.
5
6
CREATE TABLE flow_runs_new (
7
    id            INTEGER PRIMARY KEY,
8
    repo_id       INTEGER NOT NULL REFERENCES repositories(id) ON DELETE CASCADE,
9
    bookmark      TEXT NOT NULL,
10
    -- The bookmark's state hash (checks are keyed by it) and its heads, joined with '+'.
11
    state         TEXT NOT NULL,
12
    heads         TEXT NOT NULL,
13
    pipeline_hash TEXT NOT NULL DEFAULT '',
14
    status        TEXT NOT NULL CHECK (status IN ('queued', 'running', 'passed', 'failed', 'error', 'cancelled')),
15
    -- Pipeline problems, one per line, for a run in error.
16
    error         TEXT NOT NULL DEFAULT '',
17
    actor         TEXT NOT NULL DEFAULT '',
18
    created_ms    INTEGER NOT NULL,
19
    finished_ms   INTEGER,
20
    number        INTEGER NOT NULL DEFAULT 0,
21
    trigger       TEXT NOT NULL DEFAULT 'push'
22
);
23
INSERT INTO flow_runs_new (id, repo_id, bookmark, state, heads, pipeline_hash, status, error, actor, created_ms, finished_ms, number, trigger)
24
    SELECT id, repo_id, bookmark, state, heads, pipeline_hash, status, error, actor, created_ms, finished_ms, number, trigger FROM flow_runs;
25
DROP TABLE flow_runs;
26
ALTER TABLE flow_runs_new RENAME TO flow_runs;
27
CREATE INDEX flow_runs_by_repo ON flow_runs (repo_id, id DESC);
28
CREATE UNIQUE INDEX flow_runs_number ON flow_runs (repo_id, number);
29
30
CREATE TABLE flow_jobs_new (
31
    id             INTEGER PRIMARY KEY,
32
    run_id         INTEGER NOT NULL REFERENCES flow_runs(id) ON DELETE CASCADE,
33
    name           TEXT NOT NULL,
34
    depth          INTEGER NOT NULL,
35
    -- JSON: the job's dependencies, compiled form and sandbox (flow-core types).
36
    depends        TEXT NOT NULL,
37
    spec           TEXT NOT NULL,
38
    sandbox        TEXT NOT NULL,
39
    runtime        TEXT NOT NULL,
40
    status         TEXT NOT NULL CHECK (status IN ('queued', 'running', 'passed', 'failed', 'skipped', 'error', 'cancelled')),
41
    runner         TEXT NOT NULL DEFAULT '',
42
    token_hash     TEXT NOT NULL DEFAULT '',
43
    started_ms     INTEGER,
44
    finished_ms    INTEGER,
45
    exit_code      INTEGER,
46
    error          TEXT NOT NULL DEFAULT '',
47
    receipt        TEXT NOT NULL DEFAULT '',
48
    receipt_hash   TEXT NOT NULL DEFAULT '',
49
    log_count      INTEGER NOT NULL DEFAULT 0,
50
    also_read      TEXT NOT NULL DEFAULT '',
51
    receipt_attest TEXT NOT NULL DEFAULT '',
52
    receipt_signer TEXT NOT NULL DEFAULT '',
53
    receipt_note   TEXT NOT NULL DEFAULT '',
54
    runner_id      INTEGER,
55
    timeout_s      INTEGER NOT NULL DEFAULT 0,
56
    UNIQUE (run_id, name)
57
);
58
INSERT INTO flow_jobs_new (id, run_id, name, depth, depends, spec, sandbox, runtime, status, runner, token_hash, started_ms, finished_ms,
59
        exit_code, error, receipt, receipt_hash, log_count, also_read, receipt_attest, receipt_signer, receipt_note, runner_id, timeout_s)
60
    SELECT id, run_id, name, depth, depends, spec, sandbox, runtime, status, runner, token_hash, started_ms, finished_ms,
61
        exit_code, error, receipt, receipt_hash, log_count, also_read, receipt_attest, receipt_signer, receipt_note, runner_id, timeout_s FROM flow_jobs;
62
DROP TABLE flow_jobs;
63
ALTER TABLE flow_jobs_new RENAME TO flow_jobs;
64
CREATE INDEX flow_jobs_queued ON flow_jobs (status, id);
65
CREATE INDEX flow_jobs_token ON flow_jobs (token_hash) WHERE token_hash <> '';
66
CREATE INDEX flow_jobs_runner ON flow_jobs (runner_id);