Implement lab 3 level 4 failover and idempotency

This commit is contained in:
2026-10-29 23:35:04 +03:00
parent 0ab3a341aa
commit a2cb1ad2ae
338 changed files with 37821 additions and 22 deletions
@@ -0,0 +1,23 @@
-- +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;