CREATE TABLE IF NOT EXISTS message_idempotency ( user_id uuid NOT NULL REFERENCES users(id), chat_id uuid NOT NULL REFERENCES chats(id), key varchar(128) NOT NULL, fingerprint char(64) NOT NULL, message_id uuid REFERENCES messages(id), created_at timestamptz NOT NULL DEFAULT now(), PRIMARY KEY (user_id, chat_id, key) );