forked from mtusi2026/mtusi2026lab6
24 lines
700 B
SQL
24 lines
700 B
SQL
-- +goose Up
|
|
|
|
CREATE TABLE message_idempotency
|
|
(
|
|
user_id UUID NOT NULL REFERENCES users(id),
|
|
chat_id UUID NOT NULL REFERENCES chats(id),
|
|
idempotency_key VARCHAR(128) NOT NULL,
|
|
message_id UUID NOT NULL REFERENCES messages(id),
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
expires_at TIMESTAMPTZ NOT NULL DEFAULT (now() + interval '24 hours'),
|
|
|
|
PRIMARY KEY (user_id, chat_id, idempotency_key),
|
|
UNIQUE (message_id),
|
|
|
|
CONSTRAINT message_idempotency_key_format_check
|
|
CHECK (idempotency_key COLLATE "C" ~ '^[A-Za-z0-9._:-]{1,128}$'),
|
|
CONSTRAINT message_idempotency_expiry_check
|
|
CHECK (expires_at > created_at)
|
|
);
|
|
|
|
-- +goose Down
|
|
|
|
DROP TABLE IF EXISTS message_idempotency;
|