51 lines
1.6 KiB
SQL
51 lines
1.6 KiB
SQL
-- +goose Up
|
|
CREATE SCHEMA runs;
|
|
|
|
CREATE TABLE runs.runs (
|
|
id uuid PRIMARY KEY,
|
|
org_id text NOT NULL,
|
|
workflow text NOT NULL,
|
|
start_key text,
|
|
input jsonb NOT NULL,
|
|
state text NOT NULL CHECK (state IN ('queued', 'running', 'waiting', 'succeeded', 'failed', 'cancelled')),
|
|
lease_token uuid,
|
|
lease_owner text,
|
|
lease_expires_at timestamptz,
|
|
wake_at timestamptz,
|
|
waiting_for text,
|
|
cancel_requested boolean NOT NULL DEFAULT false,
|
|
attempts integer NOT NULL DEFAULT 0,
|
|
result jsonb,
|
|
error text,
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
updated_at timestamptz NOT NULL DEFAULT now(),
|
|
finished_at timestamptz,
|
|
UNIQUE (org_id, start_key)
|
|
);
|
|
|
|
-- Claiming scans only runs that could be claimed.
|
|
CREATE INDEX runs_claimable ON runs.runs (created_at)
|
|
WHERE state IN ('queued', 'waiting', 'running');
|
|
|
|
CREATE TABLE runs.steps (
|
|
run_id uuid NOT NULL REFERENCES runs.runs (id) ON DELETE CASCADE,
|
|
seq integer NOT NULL,
|
|
name text NOT NULL,
|
|
outcome text NOT NULL CHECK (outcome IN ('done', 'failed', 'unknown')),
|
|
output jsonb,
|
|
error text,
|
|
recorded_at timestamptz NOT NULL DEFAULT now(),
|
|
PRIMARY KEY (run_id, seq)
|
|
);
|
|
|
|
CREATE TABLE runs.signals (
|
|
run_id uuid NOT NULL REFERENCES runs.runs (id) ON DELETE CASCADE,
|
|
key text NOT NULL,
|
|
payload jsonb NOT NULL,
|
|
received_at timestamptz NOT NULL DEFAULT now(),
|
|
PRIMARY KEY (run_id, key)
|
|
);
|
|
|
|
-- +goose Down
|
|
DROP SCHEMA runs CASCADE;
|