scripts/rolling-update.sh (make rolling_update) replaces API replicas one by one: build, migrations once, new replica UP in HAProxy, old replica drained and put into maintenance through the LB runtime API on loopback, then stopped and removed; the slot is reset once DNS drops the address. Expand migration adds messages.instance_id with a lock timeout. The bench rollout profile runs the same script under constant load, starting from the image of an older commit built with git archive. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
from uuid import UUID
|
|
|
|
from sqlalchemy import CheckConstraint, ForeignKeyConstraint, Index, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from src.infra.db.models.base import Base
|
|
from src.utils.constants import (
|
|
MESSAGE_TEXT_MAX_LENGTH,
|
|
MESSAGE_TEXT_MIN_LENGTH,
|
|
)
|
|
|
|
|
|
class Message(Base):
|
|
__tablename__ = "messages"
|
|
__table_args__ = (
|
|
# отправитель — участник этого чата: проверяет сама БД
|
|
ForeignKeyConstraint(
|
|
["chat_id", "sender_id"],
|
|
["chat_members.chat_id", "chat_members.user_id"],
|
|
),
|
|
CheckConstraint(
|
|
"char_length(text) BETWEEN "
|
|
f"{MESSAGE_TEXT_MIN_LENGTH} AND {MESSAGE_TEXT_MAX_LENGTH}",
|
|
name="text_length",
|
|
),
|
|
# keyset истории: WHERE chat_id = ... AND (created_at, id) > (...)
|
|
Index(None, "chat_id", "created_at", "id"),
|
|
)
|
|
|
|
id: Mapped[UUID] = mapped_column(primary_key=True)
|
|
chat_id: Mapped[UUID]
|
|
sender_id: Mapped[UUID]
|
|
text: Mapped[str] = mapped_column(Text)
|
|
# X-Instance-Id реплики, которая записала сообщение; NULL — запись
|
|
# версии до этой колонки. Наружу не отдаётся. Колонка добавлена
|
|
# расширяющей миграцией: прежняя версия её не знает и работает на
|
|
# новой схеме (design change rolling-update, решение 7)
|
|
instance_id: Mapped[str | None] = mapped_column(Text)
|