-- +goose Up CREATE SCHEMA approvals; -- A request is one judged action waiting for a person's answer. key is the run -- wait an answer wakes, and the decision columns bind the answer to the action -- that was judged, so it can't be replayed onto another one. CREATE TABLE approvals.requests ( id uuid PRIMARY KEY, org_id text NOT NULL, run_id uuid NOT NULL, key text NOT NULL, decision_id uuid NOT NULL, digest text NOT NULL, level text NOT NULL CHECK (level IN ('act_quietly', 'act_and_tell', 'propose_and_wait', 'escalate', 'never')), summary text NOT NULL, state text NOT NULL CHECK (state IN ('pending', 'approved', 'denied', 'expired')), deadline timestamptz NOT NULL, created_at timestamptz NOT NULL DEFAULT now(), answered_at timestamptz, answered_by text, answered_via text, UNIQUE (org_id, run_id, key) ); CREATE INDEX requests_by_state ON approvals.requests (org_id, state, created_at); -- +goose Down DROP SCHEMA approvals CASCADE;