CREATE TABLE assessor_ai_overview_runs ( id text PRIMARY KEY, project_id text NOT NULL REFERENCES assessor_projects(id) ON DELETE CASCADE, scope_key text NOT NULL, assessment_ids text[] NOT NULL DEFAULT '{}', scan_run_ids text[] NOT NULL DEFAULT '{}', idempotency_key text NOT NULL, run_status text NOT NULL CHECK (run_status IN ('queued', 'running', 'succeeded', 'failed')), input_hash text NOT NULL CHECK (input_hash ~ '^[a-f0-9]{64}$'), prompt_version text NOT NULL, output_schema_version integer NOT NULL, model text NOT NULL, created_at timestamptz NOT NULL, updated_at timestamptz NOT NULL, data jsonb NOT NULL, CONSTRAINT assessor_ai_overview_runs_idempotency_uq UNIQUE (project_id, scope_key, idempotency_key) ); CREATE UNIQUE INDEX assessor_ai_overview_runs_active_scope_uq ON assessor_ai_overview_runs (project_id, scope_key) WHERE run_status IN ('queued', 'running'); CREATE INDEX assessor_ai_overview_runs_scope_created_idx ON assessor_ai_overview_runs (project_id, scope_key, created_at DESC, id DESC);