-- +goose Up CREATE SCHEMA judgement; -- A decision is the judgement of one concrete action, with every verdict in -- its body. key identifies the attempt to run it, so a replayed step finds the -- decision already made. The class columns are what earned autonomy is -- counted against. CREATE TABLE judgement.decisions ( id uuid PRIMARY KEY, org_id text NOT NULL, run_id uuid NOT NULL, key text NOT NULL, connector text NOT NULL, action text NOT NULL, target_kind text NOT NULL, environment text NOT NULL, level text NOT NULL CHECK (level IN ('act_quietly', 'act_and_tell', 'propose_and_wait', 'escalate', 'never')), body json NOT NULL, created_at timestamptz NOT NULL DEFAULT now(), UNIQUE (org_id, key) ); CREATE INDEX decisions_by_run ON judgement.decisions (org_id, run_id, created_at); CREATE INDEX decisions_by_class ON judgement.decisions (org_id, connector, action, target_kind, environment, created_at); -- +goose Down DROP SCHEMA judgement CASCADE;