Перенести API с общими сессиями и идемпотентной отправкой сообщения.

Реплика больше не держит корректность в своей памяти: сессия в Redis, а повтор POST сообщения фиксируется в Postgres вместе с X-Instance-Id.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-07 12:46:37 +03:00
co-authored by Cursor
parent 0ab3a341aa
commit c0d313703e
34 changed files with 2342 additions and 7 deletions
+14
View File
@@ -0,0 +1,14 @@
-- Shared idempotency for POST /messages. Scope: user + method + path + key.
-- The message row and this result are committed in one transaction.
-- A rolled-back request leaves no row, so a later retry with the same key can insert.
CREATE TABLE IF NOT EXISTS idempotency_keys (
user_id UUID NOT NULL REFERENCES users (id),
http_method TEXT NOT NULL,
path TEXT NOT NULL,
idem_key TEXT NOT NULL,
request_hash TEXT NOT NULL,
response_json TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
PRIMARY KEY (user_id, http_method, path, idem_key)
);