Files
mtusi2026lab2/student-tests/fixtures/legacy/0002_idempotency_keys.sql
T
Artyom 71c643c6d1 Adopt async SQLAlchemy storage and verified Alembic migrations
Keep the message and idempotency receipt in one Core CTE statement with chat-first locking. Preserve rollback, bounded dependency failures, and domain ports.

Replace the SQL runner with Alembic. Adopt legacy databases only after validating their journal and PostgreSQL schema, retain all data, and verify migrations on fresh and populated databases.
2026-11-05 21:38:12 +03:00

11 lines
453 B
SQL

CREATE TABLE idempotency_keys (
chat_id uuid NOT NULL,
user_id uuid NOT NULL,
key text NOT NULL CHECK (key ~ '^[A-Za-z0-9._:-]{1,128}$'),
fingerprint bytea NOT NULL CHECK (octet_length(fingerprint) = 32),
message_id uuid NOT NULL REFERENCES messages (id) ON DELETE CASCADE,
created_at timestamptz NOT NULL,
PRIMARY KEY (chat_id, user_id, key),
FOREIGN KEY (chat_id, user_id) REFERENCES chat_members (chat_id, user_id)
);