-- ── Delivery log (partitioned by month on delivered_at) ────────────────────── -- Conformance: subscription delivery audit. community_id carried for tenant -- attribution; child of subscriptions. CREATE TABLE delivery_log ( community_id UUID NOT NULL REFERENCES communities(id), id BIGINT GENERATED ALWAYS AS IDENTITY, subscription_id VARCHAR(255), event_id BYTEA, method delivery_method, delivered_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), success BOOLEAN, http_status INT, error_message TEXT, attempt_number INT DEFAULT 1, PRIMARY KEY (delivered_at, id) ) PARTITION BY RANGE (delivered_at); CREATE INDEX idx_delivery_log_community_sub ON delivery_log (community_id, subscription_id);