feat(invites): add group/channel invite links and join by token

This commit is contained in:
2026-03-08 09:58:55 +03:00
parent cc70394960
commit f01bbda14e
11 changed files with 247 additions and 6 deletions

View File

@@ -0,0 +1,46 @@
"""add chat invite links
Revision ID: 0016_chat_invites
Revises: 0015_chat_pin_set
Create Date: 2026-03-08 19:45:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
revision: str = "0016_chat_invites"
down_revision: Union[str, Sequence[str], None] = "0015_chat_pin_set"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.create_table(
"chat_invite_links",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("chat_id", sa.Integer(), nullable=False),
sa.Column("creator_user_id", sa.Integer(), nullable=False),
sa.Column("token", sa.String(length=64), nullable=False),
sa.Column("is_active", sa.Boolean(), nullable=False, server_default=sa.text("true")),
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False),
sa.ForeignKeyConstraint(["chat_id"], ["chats.id"], name=op.f("fk_chat_invite_links_chat_id_chats"), ondelete="CASCADE"),
sa.ForeignKeyConstraint(["creator_user_id"], ["users.id"], name=op.f("fk_chat_invite_links_creator_user_id_users"), ondelete="CASCADE"),
sa.PrimaryKeyConstraint("id", name=op.f("pk_chat_invite_links")),
sa.UniqueConstraint("token", name="uq_chat_invite_links_token"),
)
op.create_index(op.f("ix_chat_invite_links_id"), "chat_invite_links", ["id"], unique=False)
op.create_index(op.f("ix_chat_invite_links_chat_id"), "chat_invite_links", ["chat_id"], unique=False)
op.create_index(op.f("ix_chat_invite_links_creator_user_id"), "chat_invite_links", ["creator_user_id"], unique=False)
op.create_index(op.f("ix_chat_invite_links_token"), "chat_invite_links", ["token"], unique=False)
def downgrade() -> None:
op.drop_index(op.f("ix_chat_invite_links_token"), table_name="chat_invite_links")
op.drop_index(op.f("ix_chat_invite_links_creator_user_id"), table_name="chat_invite_links")
op.drop_index(op.f("ix_chat_invite_links_chat_id"), table_name="chat_invite_links")
op.drop_index(op.f("ix_chat_invite_links_id"), table_name="chat_invite_links")
op.drop_table("chat_invite_links")