11 lines
587 B
SQL
11 lines
587 B
SQL
CREATE TABLE message_idempotency (
|
|
user_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 CHECK (idempotency_key ~ '^[A-Za-z0-9._:-]{1,128}$'),
|
|
request_hash bytea NOT NULL CHECK (octet_length(request_hash) = 32),
|
|
message_id uuid NOT NULL REFERENCES messages(id) ON DELETE CASCADE,
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
PRIMARY KEY (user_id, chat_id, idempotency_key)
|
|
);
|
|
CREATE INDEX message_idempotency_expiry_idx ON message_idempotency (created_at);
|