CREATE TABLE events (
    id          TEXT        PRIMARY KEY,
    source      TEXT        NOT NULL,
    action      TEXT        NOT NULL,
    occurred_at TIMESTAMPTZ NOT NULL,
    payload     JSONB       NOT NULL,
    fetched_at  TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX events_occurred_at_desc        ON events (occurred_at DESC);
CREATE INDEX events_source_occurred_at_desc ON events (source, occurred_at DESC);
