"""Уведомления: таблица notifications (персистентные уведомления игроку). Идемпотентна (как 0006/0007): на свежей БД таблицу создаёт 0001 (create_all); на существующей — create_table здесь. Revision ID: 0008_notifications Revises: 0007_match_attachments Create Date: 2026-06-26 """ from typing import Sequence, Union import sqlalchemy as sa from sqlalchemy import inspect from alembic import op revision: str = "0008_notifications" down_revision: Union[str, None] = "0007_match_attachments" branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: bind = op.get_bind() insp = inspect(bind) if "notifications" in insp.get_table_names(): return op.create_table( "notifications", sa.Column("id", sa.Integer(), primary_key=True), sa.Column( "user_id", sa.Integer(), sa.ForeignKey("users.id", ondelete="CASCADE"), nullable=False, ), sa.Column("type", sa.String(32), nullable=False), sa.Column("title", sa.String(255), nullable=False), sa.Column("body", sa.Text(), nullable=True), sa.Column("link", sa.String(255), nullable=True), sa.Column("read_at", sa.DateTime(), nullable=True), sa.Column("created_at", sa.DateTime(), nullable=False), ) op.create_index("ix_notifications_user_id", "notifications", ["user_id"]) op.create_index("ix_notifications_created_at", "notifications", ["created_at"]) op.create_index( "ix_notifications_user_created", "notifications", ["user_id", "created_at"] ) def downgrade() -> None: bind = op.get_bind() insp = inspect(bind) if "notifications" in insp.get_table_names(): op.drop_table("notifications")