Files
archie/internal/platform/pg/migrations/00022_memory_incidents.sql
T

42 lines
1.4 KiB
SQL

-- +goose Up
CREATE SCHEMA memory;
-- An incident is one investigation of one target: what the event was, the cause
-- the investigation found and what was done about it. The row is made when the
-- cause is recorded and gets its actions when the run settles them.
CREATE TABLE memory.incidents (
id uuid PRIMARY KEY,
org_id text NOT NULL,
run_id uuid NOT NULL,
target_kind text NOT NULL,
target_id text NOT NULL,
cause text NOT NULL,
summary text NOT NULL,
event jsonb NOT NULL,
actions jsonb NOT NULL DEFAULT '[]',
at timestamptz NOT NULL DEFAULT now(),
UNIQUE (org_id, run_id)
);
CREATE INDEX incidents_by_target ON memory.incidents (org_id, target_kind, target_id, at DESC);
-- A proposal is the root-cause fix asked for once a cause keeps coming back on
-- a target. One per target and cause.
CREATE TABLE memory.proposals (
id uuid PRIMARY KEY,
org_id text NOT NULL,
target_kind text NOT NULL,
target_id text NOT NULL,
cause text NOT NULL,
incidents integer NOT NULL,
body text NOT NULL,
created_at timestamptz NOT NULL DEFAULT now(),
UNIQUE (org_id, target_kind, target_id, cause)
);
ALTER TABLE governance.settings ADD COLUMN recurrence_threshold integer NOT NULL DEFAULT 5;
-- +goose Down
ALTER TABLE governance.settings DROP COLUMN recurrence_threshold;
DROP SCHEMA memory CASCADE;