feat: persist immutable Bell events and receipts (#17)
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
CREATE TABLE bell_events (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
producer_id text NOT NULL,
|
||||
source_event_id text NOT NULL,
|
||||
event_type text NOT NULL,
|
||||
occurred_at timestamptz NOT NULL,
|
||||
location text NOT NULL,
|
||||
severity text NOT NULL CHECK (severity IN ('low','medium','high','critical')),
|
||||
evidence_ref text,
|
||||
normalized_payload jsonb NOT NULL,
|
||||
payload_sha256 bytea NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
UNIQUE (producer_id, source_event_id)
|
||||
);
|
||||
CREATE INDEX bell_events_created_page_idx ON bell_events(created_at DESC,id DESC);
|
||||
CREATE TABLE bell_event_receipts (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
event_id uuid NOT NULL UNIQUE REFERENCES bell_events(id),
|
||||
producer_id text NOT NULL,
|
||||
source_event_id text NOT NULL,
|
||||
payload_sha256 bytea NOT NULL,
|
||||
accepted_at timestamptz NOT NULL DEFAULT now(),
|
||||
UNIQUE (producer_id, source_event_id)
|
||||
);
|
||||
|
||||
CREATE OR REPLACE FUNCTION bell_reject_event_mutation() RETURNS trigger LANGUAGE plpgsql AS $$
|
||||
BEGIN RAISE EXCEPTION 'Bell Event and Receipt facts are immutable'; END $$;
|
||||
CREATE TRIGGER bell_event_no_update BEFORE UPDATE OR DELETE ON bell_events FOR EACH ROW EXECUTE FUNCTION bell_reject_event_mutation();
|
||||
CREATE TRIGGER bell_receipt_no_update BEFORE UPDATE OR DELETE ON bell_event_receipts FOR EACH ROW EXECUTE FUNCTION bell_reject_event_mutation();
|
||||
Reference in New Issue
Block a user