CREATE TABLE live_audit_events (
    event_id        TEXT NOT NULL,
    account_id      TEXT NOT NULL,
    broker          TEXT NOT NULL DEFAULT '',
    order_id        TEXT NOT NULL DEFAULT '',
    event_type      TEXT NOT NULL,
    status          TEXT NOT NULL DEFAULT '',
    reason          TEXT NOT NULL DEFAULT '',
    actor           TEXT NOT NULL DEFAULT '',
    correlation_id  TEXT NOT NULL DEFAULT '',
    payload         JSONB NOT NULL DEFAULT '{}',
    created_at      TIMESTAMP WITH TIME ZONE NOT NULL,
    PRIMARY KEY (event_id)
);

CREATE INDEX live_audit_events_account_id_idx ON live_audit_events (account_id);
CREATE INDEX live_audit_events_order_id_idx   ON live_audit_events (order_id) WHERE order_id != '';
CREATE INDEX live_audit_events_created_at_idx ON live_audit_events (created_at);
