Files
uptimesebi/internal/migrations/sql/00031_check_evidence.sql

30 lines
1.2 KiB
SQL

-- +goose Up
-- What checkers saw of HTTP exchanges (see check.Evidence). Kept apart
-- from check_results, which is compressed and holds one small row per
-- check; evidence is sampled and large. Per monitor and region the API
-- keeps the latest success and failures at most every few minutes.
CREATE TABLE check_evidence (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
org_id uuid NOT NULL,
monitor_id uuid NOT NULL,
region text NOT NULL,
checker_id uuid NOT NULL,
time timestamptz NOT NULL,
ok boolean NOT NULL,
status_code integer,
error text,
evidence jsonb NOT NULL,
FOREIGN KEY (monitor_id, org_id) REFERENCES monitors (id, org_id) ON DELETE CASCADE
);
CREATE INDEX check_evidence_monitor_idx ON check_evidence (monitor_id, region, time DESC);
CREATE INDEX check_evidence_time_idx ON check_evidence (time);
ALTER TABLE check_evidence ENABLE ROW LEVEL SECURITY;
ALTER TABLE check_evidence FORCE ROW LEVEL SECURITY;
CREATE POLICY check_evidence_tenant ON check_evidence 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 check_evidence;