Files
Sebastian UnterschützandClaude Opus 5.5 00658d49a2 feat(store): add monitors, regions, agents and check result hypertable
check_results has no row-level security because TimescaleDB refuses
compression and continuous aggregates on such tables. Every results
query takes org_id as a parameter, which a test enforces.

Refs #10, #13

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
2026-11-22 01:12:53 +01:00

29 lines
1.2 KiB
SQL

-- +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;