44 lines
1.9 KiB
Python
44 lines
1.9 KiB
Python
"""add chat user settings for archive
|
|
|
|
Revision ID: 0014_chat_user_set
|
|
Revises: 0013_msg_reactions
|
|
Create Date: 2026-03-08 19:00:00.000000
|
|
"""
|
|
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
revision: str = "0014_chat_user_set"
|
|
down_revision: Union[str, Sequence[str], None] = "0013_msg_reactions"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"chat_user_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("archived", sa.Boolean(), nullable=False, server_default=sa.text("false")),
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False),
|
|
sa.ForeignKeyConstraint(["chat_id"], ["chats.id"], name=op.f("fk_chat_user_settings_chat_id_chats"), ondelete="CASCADE"),
|
|
sa.ForeignKeyConstraint(["user_id"], ["users.id"], name=op.f("fk_chat_user_settings_user_id_users"), ondelete="CASCADE"),
|
|
sa.PrimaryKeyConstraint("id", name=op.f("pk_chat_user_settings")),
|
|
sa.UniqueConstraint("chat_id", "user_id", name="uq_chat_user_settings_chat_user"),
|
|
)
|
|
op.create_index(op.f("ix_chat_user_settings_id"), "chat_user_settings", ["id"], unique=False)
|
|
op.create_index(op.f("ix_chat_user_settings_chat_id"), "chat_user_settings", ["chat_id"], unique=False)
|
|
op.create_index(op.f("ix_chat_user_settings_user_id"), "chat_user_settings", ["user_id"], unique=False)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index(op.f("ix_chat_user_settings_user_id"), table_name="chat_user_settings")
|
|
op.drop_index(op.f("ix_chat_user_settings_chat_id"), table_name="chat_user_settings")
|
|
op.drop_index(op.f("ix_chat_user_settings_id"), table_name="chat_user_settings")
|
|
op.drop_table("chat_user_settings")
|
|
|