-- +goose Up -- Agents are checkers and status page servers. Agents without an org are run -- by the operator and serve every organization; org-owned agents arrive with -- customer-hosted checkers. CREATE TABLE agents ( id uuid PRIMARY KEY DEFAULT gen_random_uuid(), org_id uuid REFERENCES orgs (id) ON DELETE CASCADE, kind text NOT NULL CHECK (kind IN ('checker', 'statuspage')), name text NOT NULL CHECK (length(name) BETWEEN 1 AND 100), region text REFERENCES regions (key), token_hash bytea NOT NULL UNIQUE, prefix text NOT NULL, last_seen_at timestamptz, release text, created_at timestamptz NOT NULL DEFAULT now(), CHECK ((kind = 'checker') = (region IS NOT NULL)) ); ALTER TABLE agents ENABLE ROW LEVEL SECURITY; ALTER TABLE agents FORCE ROW LEVEL SECURITY; CREATE POLICY agents_read ON agents FOR SELECT USING (org_id IS NULL OR app_scope_system() OR org_id = app_org_id()); CREATE POLICY agents_write ON agents FOR ALL USING (app_scope_system() OR org_id = app_org_id()) WITH CHECK (app_scope_system() OR org_id = app_org_id()); -- +goose Down DROP TABLE agents;