feat(chat): support public channel chat
This commit is contained in:
192
migrations/versions/dd33d89aa2c2_chat_add_chat.py
Normal file
192
migrations/versions/dd33d89aa2c2_chat_add_chat.py
Normal file
@@ -0,0 +1,192 @@
|
||||
"""chat: add chat
|
||||
|
||||
Revision ID: dd33d89aa2c2
|
||||
Revises: 9f6b27e8ea51
|
||||
Create Date: 2025-08-15 14:22:34.775877
|
||||
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
import sqlmodel
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "dd33d89aa2c2"
|
||||
down_revision: str | Sequence[str] | None = "9f6b27e8ea51"
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
channel_table = op.create_table(
|
||||
"chat_channels",
|
||||
sa.Column("name", sa.VARCHAR(length=50), nullable=True),
|
||||
sa.Column("description", sa.VARCHAR(length=255), nullable=True),
|
||||
sa.Column("icon", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
|
||||
sa.Column(
|
||||
"type",
|
||||
sa.Enum(
|
||||
"PUBLIC",
|
||||
"PRIVATE",
|
||||
"MULTIPLAYER",
|
||||
"SPECTATOR",
|
||||
"TEMPORARY",
|
||||
"PM",
|
||||
"GROUP",
|
||||
"SYSTEM",
|
||||
"ANNOUNCE",
|
||||
"TEAM",
|
||||
name="channeltype",
|
||||
),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column("channel_id", sa.Integer(), nullable=False),
|
||||
sa.PrimaryKeyConstraint("channel_id"),
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_chat_channels_channel_id"),
|
||||
"chat_channels",
|
||||
["channel_id"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_chat_channels_description"),
|
||||
"chat_channels",
|
||||
["description"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_chat_channels_name"), "chat_channels", ["name"], unique=False
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_chat_channels_type"), "chat_channels", ["type"], unique=False
|
||||
)
|
||||
op.create_table(
|
||||
"chat_messages",
|
||||
sa.Column("channel_id", sa.Integer(), nullable=False),
|
||||
sa.Column("content", sa.VARCHAR(length=1000), nullable=True),
|
||||
sa.Column("message_id", sa.Integer(), nullable=False),
|
||||
sa.Column("sender_id", sa.BigInteger(), nullable=True),
|
||||
sa.Column("timestamp", sa.DateTime(), nullable=True),
|
||||
sa.Column(
|
||||
"type",
|
||||
sa.Enum("ACTION", "MARKDOWN", "PLAIN", name="messagetype"),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column("uuid", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
["channel_id"],
|
||||
["chat_channels.channel_id"],
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["sender_id"],
|
||||
["lazer_users.id"],
|
||||
),
|
||||
sa.PrimaryKeyConstraint("message_id"),
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_chat_messages_channel_id"),
|
||||
"chat_messages",
|
||||
["channel_id"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_chat_messages_message_id"),
|
||||
"chat_messages",
|
||||
["message_id"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_chat_messages_sender_id"), "chat_messages", ["sender_id"], unique=False
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_chat_messages_timestamp"), "chat_messages", ["timestamp"], unique=False
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_chat_messages_type"), "chat_messages", ["type"], unique=False
|
||||
)
|
||||
op.create_table(
|
||||
"chat_silence_users",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("user_id", sa.BigInteger(), nullable=False),
|
||||
sa.Column("channel_id", sa.Integer(), nullable=False),
|
||||
sa.Column("until", sa.DateTime(), nullable=True),
|
||||
sa.Column("banned_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("reason", sa.VARCHAR(length=255), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
["channel_id"],
|
||||
["chat_channels.channel_id"],
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["user_id"],
|
||||
["lazer_users.id"],
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_chat_silence_users_channel_id"),
|
||||
"chat_silence_users",
|
||||
["channel_id"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_chat_silence_users_reason"),
|
||||
"chat_silence_users",
|
||||
["reason"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_chat_silence_users_until"),
|
||||
"chat_silence_users",
|
||||
["until"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_chat_silence_users_banned_at"),
|
||||
"chat_silence_users",
|
||||
["banned_at"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_chat_silence_users_user_id"),
|
||||
"chat_silence_users",
|
||||
["user_id"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_chat_silence_users_id"),
|
||||
"chat_silence_users",
|
||||
["id"],
|
||||
unique=False,
|
||||
)
|
||||
op.bulk_insert(
|
||||
channel_table,
|
||||
[
|
||||
{
|
||||
"name": "osu!",
|
||||
"description": "General discussion for osu!",
|
||||
"type": "PUBLIC",
|
||||
},
|
||||
{
|
||||
"name": "announce",
|
||||
"description": "Official announcements",
|
||||
"type": "PUBLIC",
|
||||
},
|
||||
],
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table("chat_silence_users")
|
||||
op.drop_table("chat_messages")
|
||||
op.drop_table("chat_channels")
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user