Files
Messenger/alembic/versions/0009_chat_notification_settings.py
benya ea8a50ee05
Some checks failed
CI / test (push) Failing after 18s
feat(notifications): per-chat mute settings
- add chat_notification_settings table and migration
- add chat notifications API (get/update muted)
- skip message notifications for muted recipients
- add mute/unmute control in chat info panel
2026-03-08 02:17:09 +03:00

53 lines
2.2 KiB
Python

"""add chat notification settings
Revision ID: 0009_chat_notification_settings
Revises: 0008_user_last_seen_presence
Create Date: 2026-03-08 14:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
revision: str = "0009_chat_notification_settings"
down_revision: Union[str, Sequence[str], None] = "0008_user_last_seen_presence"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.create_table(
"chat_notification_settings",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("chat_id", sa.Integer(), nullable=False),
sa.Column("user_id", sa.Integer(), nullable=False),
sa.Column("muted", sa.Boolean(), nullable=False, server_default=sa.text("false")),
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
sa.ForeignKeyConstraint(["chat_id"], ["chats.id"], name=op.f("fk_chat_notification_settings_chat_id_chats"), ondelete="CASCADE"),
sa.ForeignKeyConstraint(["user_id"], ["users.id"], name=op.f("fk_chat_notification_settings_user_id_users"), ondelete="CASCADE"),
sa.PrimaryKeyConstraint("id", name=op.f("pk_chat_notification_settings")),
sa.UniqueConstraint("chat_id", "user_id", name="uq_chat_notification_settings_chat_user"),
)
op.create_index(op.f("ix_chat_notification_settings_id"), "chat_notification_settings", ["id"], unique=False)
op.create_index(
op.f("ix_chat_notification_settings_chat_id"),
"chat_notification_settings",
["chat_id"],
unique=False,
)
op.create_index(
op.f("ix_chat_notification_settings_user_id"),
"chat_notification_settings",
["user_id"],
unique=False,
)
def downgrade() -> None:
op.drop_index(op.f("ix_chat_notification_settings_user_id"), table_name="chat_notification_settings")
op.drop_index(op.f("ix_chat_notification_settings_chat_id"), table_name="chat_notification_settings")
op.drop_index(op.f("ix_chat_notification_settings_id"), table_name="chat_notification_settings")
op.drop_table("chat_notification_settings")