-- +goose Up CREATE SCHEMA audit; -- Append-only audit events. The runtime database role holds only SELECT and -- INSERT privileges on this schema so records cannot be modified or deleted. CREATE TABLE audit.events ( id uuid PRIMARY KEY, org_id text NOT NULL, at timestamptz NOT NULL DEFAULT now(), category text NOT NULL, action text NOT NULL, actor_id text NOT NULL, actor_kind text NOT NULL DEFAULT '', resource_kind text NOT NULL DEFAULT '', resource_id text NOT NULL DEFAULT '', outcome text NOT NULL, trace_id text NOT NULL DEFAULT '', detail jsonb NOT NULL DEFAULT '{}' ); CREATE INDEX idx_audit_events_org_at ON audit.events (org_id, at DESC); CREATE INDEX idx_audit_events_org_category_at ON audit.events (org_id, category, at DESC); -- +goose Down DROP SCHEMA audit CASCADE;