Files
buzz/schema/triggers/events.sql
jm 4e63210974 feat(relay): complete IFC proof semantics
Co-authored-by: Codex <noreply@openai.com>
Signed-off-by: jm <jm@squareup.com>
2026-10-14 22:18:14 +00:00

28 lines
1.3 KiB
SQL

CREATE TRIGGER events_enqueue_push_match
AFTER INSERT ON events
FOR EACH ROW EXECUTE FUNCTION enqueue_push_match_job();
CREATE CONSTRAINT TRIGGER events_refresh_channel_ttl
AFTER INSERT ON events
DEFERRABLE INITIALLY DEFERRED
FOR EACH ROW EXECUTE FUNCTION refresh_channel_ttl_after_event_insert();
CREATE TRIGGER trg_events_guard_channel_roster_snapshot
BEFORE INSERT ON events
FOR EACH ROW EXECUTE FUNCTION guard_channel_roster_snapshot();
CREATE TRIGGER trg_events_guard_origin_generation
BEFORE INSERT OR UPDATE OF origin_generation ON events
FOR EACH ROW EXECUTE FUNCTION guard_event_origin_generation();
-- INSERT OR UPDATE OF: an UPDATE can move a previously exempt row into the
-- guarded set (channel_id NULL -> NOT NULL) or move a channel row's
-- created_at below the fence, so both mutation paths re-run the guard on the
-- NEW row. A created_at rewrite that crosses partition bounds runs as
-- DELETE + INSERT and hits the cloned AFTER INSERT guard on the destination
-- partition; an in-partition rewrite fires the UPDATE OF arm.
CREATE CONSTRAINT TRIGGER events_created_at_floor
AFTER INSERT OR UPDATE OF created_at, channel_id ON events
DEFERRABLE INITIALLY DEFERRED
FOR EACH ROW
EXECUTE FUNCTION events_created_at_floor_guard();
SELECT attach_community_write_fence('events');