Перенести решение lab3 как базу lab4

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-30 13:37:23 +03:00
co-authored by Claude Opus 5.5
parent ec540a1a72
commit e9ee60b0ba
31 changed files with 2856 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
-- Lab3: shared idempotency of POST /chats/{chat_id}/messages.
-- Scope: user + method + chat path + key. The key row and the message are
-- written in one transaction, so either both exist or neither does.
-- Expand-only change: the running lab2/lab3 API keeps working with it.
CREATE TABLE IF NOT EXISTS idempotency_keys (
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
chat_id UUID NOT NULL REFERENCES chats(id) ON DELETE CASCADE,
method VARCHAR(8) NOT NULL,
key VARCHAR(128) NOT NULL,
request_hash CHAR(64) NOT NULL,
message_id UUID REFERENCES messages(id) ON DELETE CASCADE,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
PRIMARY KEY (user_id, chat_id, method, key)
);
-- For a periodic cleanup of keys older than IDEMPOTENCY_TTL_SECONDS.
CREATE INDEX IF NOT EXISTS idempotency_keys_created_idx
ON idempotency_keys (created_at);