-- Metrics captured from the Prometheus an alert came from (its generatorURL), -- once when the incident opens and once when it closes, so the graph outlives -- Prometheus' own retention. One row per incident, alert and kind. -- -- A row exists whether or not the capture worked: a failure is recorded in -- error with the attempt count, which is what stops the worker from retrying a -- host that is not on the allowlist (or is gone) forever. CREATE TABLE incident_metric_snapshots ( id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, incident_id bigint NOT NULL REFERENCES incidents(id) ON DELETE CASCADE, alert_id bigint NOT NULL REFERENCES alerts(id) ON DELETE CASCADE, kind text NOT NULL CHECK (kind IN ('opened', 'closed')), expr text NOT NULL DEFAULT '', window_start bigint NOT NULL, window_end bigint NOT NULL, step_seconds integer NOT NULL DEFAULT 0, series jsonb NOT NULL DEFAULT '[]'::jsonb, error text, attempts integer NOT NULL DEFAULT 1, captured_at bigint NOT NULL, UNIQUE (incident_id, alert_id, kind) ); CREATE INDEX incident_metric_snapshots_alert_id_idx ON incident_metric_snapshots (alert_id);