ЛР3: балансировка, отказоустойчивость и идемпотентность

This commit is contained in:
2026-10-23 18:54:18 +03:00
parent 3f7c306f4f
commit 57b4e8b5ec
20 changed files with 659 additions and 39 deletions
+11 -2
View File
@@ -3,7 +3,7 @@ from __future__ import annotations
from datetime import datetime
from uuid import UUID
from sqlalchemy import DateTime, ForeignKey, Index, String
from sqlalchemy import DateTime, ForeignKey, Index, String, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.types import Uuid
@@ -12,10 +12,19 @@ from ..db.postgres import Base
class MessageRow(Base):
__tablename__ = 'messages'
__table_args__ = (Index('messages_history_idx', 'chat_id', 'created_at', 'id'),)
__table_args__ = (
Index('messages_history_idx', 'chat_id', 'created_at', 'id'),
UniqueConstraint(
'sender_id',
'chat_id',
'idempotency_key',
name='messages_sender_chat_idempotency_key',
),
)
id: Mapped[UUID] = mapped_column(Uuid, primary_key=True)
chat_id: Mapped[UUID] = mapped_column(ForeignKey('chats.id', ondelete='CASCADE'), nullable=False)
sender_id: Mapped[UUID] = mapped_column(ForeignKey('users.id'), nullable=False)
text: Mapped[str] = mapped_column(String(4000), nullable=False)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False)
idempotency_key: Mapped[str | None] = mapped_column(String(128), nullable=True)