ALTER TABLE agent_tokens
ADD COLUMN IF NOT EXISTS purpose text NOT NULL DEFAULT 'ops'
CHECK (purpose IN ('ops', 'ontology'));

CREATE INDEX IF NOT EXISTS agent_tokens_purpose_idx ON agent_tokens(purpose);

ALTER TABLE agent_setup_codes
ADD COLUMN IF NOT EXISTS used_ontology_token_id uuid REFERENCES agent_tokens(id) ON DELETE SET NULL;
