forked from mtusi2026/mtusi2026lab3
15 lines
723 B
SQL
15 lines
723 B
SQL
CREATE TABLE IF NOT EXISTS message_idempotency (
|
|
sender_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
chat_id uuid NOT NULL REFERENCES chats(id) ON DELETE CASCADE,
|
|
idempotency_key text NOT NULL,
|
|
request_hash bytea NOT NULL,
|
|
message_id uuid NOT NULL REFERENCES messages(id) ON DELETE CASCADE,
|
|
created_at timestamptz NOT NULL,
|
|
expires_at timestamptz NOT NULL,
|
|
PRIMARY KEY (sender_id, chat_id, idempotency_key),
|
|
CONSTRAINT message_idempotency_key_len CHECK (char_length(idempotency_key) BETWEEN 1 AND 128)
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS message_idempotency_expires_at_idx
|
|
ON message_idempotency (expires_at);
|