-- Idempotency store for POST message: scope = (user, method, path, key). CREATE TABLE IF NOT EXISTS idempotency_keys ( user_id UUID NOT NULL, method TEXT NOT NULL, path TEXT NOT NULL, idem_key TEXT NOT NULL, request_hash TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'pending', response_status INT, response_body JSONB, created_at TIMESTAMPTZ NOT NULL DEFAULT now(), PRIMARY KEY (user_id, method, path, idem_key) ); CREATE INDEX IF NOT EXISTS idempotency_keys_created_idx ON idempotency_keys (created_at);