chore: carry lab 3 over
- carry the lab 3 solution over from mtusi2026lab3-safronov (solution/bvt2301-safronov, ce89eba): src, migrations, student-tests, bench, openspec, .claude, infra/haproxy and infra/valkey, own scripts, Dockerfile, compose, pyproject and uv lock - merge Makefile, .gitignore and .dockerignore (the lab 3 versions only add lines to the skeleton, which is the same in lab 4) and .env.example (lab 4 skeleton names listed in the header) - rename the compose project to mtusi-lab4 and the image to :lab4 so the stand does not reuse the lab 3 containers and volumes - update AGENTS.md for lab 4: current lab, origin commit, contract and test files of the new skeleton Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
"""added idempotency keys
|
||||
|
||||
Revision ID: 7652184b7016
|
||||
Revises: 42bc3b9be38f
|
||||
Create Date: 2026-10-08 16:54:06.091180
|
||||
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "7652184b7016"
|
||||
down_revision: str | Sequence[str] | None = "42bc3b9be38f"
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# только новая таблица: работающая версия API без ключей её не
|
||||
# замечает (expand). CHECK записаны литералами, а не константами src
|
||||
op.create_table(
|
||||
"idempotency_keys",
|
||||
sa.Column("user_id", sa.Uuid(), nullable=False),
|
||||
sa.Column("chat_id", sa.Uuid(), nullable=False),
|
||||
sa.Column("key", sa.Text(), nullable=False),
|
||||
sa.Column("request_hash", sa.LargeBinary(), nullable=False),
|
||||
sa.Column("message_id", sa.Uuid(), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.CheckConstraint(
|
||||
"key ~ '^[A-Za-z0-9._:-]+$'",
|
||||
name=op.f("ck_idempotency_keys_key_format"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"char_length(key) BETWEEN 1 AND 128",
|
||||
name=op.f("ck_idempotency_keys_key_length"),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"octet_length(request_hash) = 32",
|
||||
name=op.f("ck_idempotency_keys_request_hash_length"),
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["chat_id", "user_id"],
|
||||
["chat_members.chat_id", "chat_members.user_id"],
|
||||
name=op.f("fk_idempotency_keys_chat_id_user_id_chat_members"),
|
||||
),
|
||||
# ключ вставляется раньше сообщения в той же транзакции: проверка
|
||||
# ссылки — на commit
|
||||
sa.ForeignKeyConstraint(
|
||||
["message_id"],
|
||||
["messages.id"],
|
||||
name=op.f("fk_idempotency_keys_message_id_messages"),
|
||||
initially="DEFERRED",
|
||||
deferrable=True,
|
||||
),
|
||||
sa.PrimaryKeyConstraint(
|
||||
"user_id",
|
||||
"chat_id",
|
||||
"key",
|
||||
name=op.f("pk_idempotency_keys"),
|
||||
),
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_idempotency_keys_created_at"),
|
||||
"idempotency_keys",
|
||||
["created_at"],
|
||||
unique=False,
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index(
|
||||
op.f("ix_idempotency_keys_created_at"),
|
||||
table_name="idempotency_keys",
|
||||
)
|
||||
op.drop_table("idempotency_keys")
|
||||
Reference in New Issue
Block a user