feat(matchmaking): support matchmaking (#48)
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
"""matchmaking: add tables
|
||||
|
||||
Revision ID: ceabe941b207
|
||||
Revises: 48fb754416de
|
||||
Create Date: 2025-10-18 13:52:28.005667
|
||||
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import mysql
|
||||
import sqlmodel
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "ceabe941b207"
|
||||
down_revision: str | Sequence[str] | None = "48fb754416de"
|
||||
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! ###
|
||||
op.create_table(
|
||||
"matchmaking_pools",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("ruleset_id", sa.SmallInteger(), nullable=False),
|
||||
sa.Column("variant_id", sa.SmallInteger(), server_default="0", nullable=False),
|
||||
sa.Column("name", sqlmodel.sql.sqltypes.AutoString(length=255), nullable=False),
|
||||
sa.Column("active", sa.Boolean(), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=True),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=True),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_index(
|
||||
"matchmaking_pools_ruleset_variant_active_idx",
|
||||
"matchmaking_pools",
|
||||
["ruleset_id", "variant_id", "active"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_table(
|
||||
"matchmaking_user_stats",
|
||||
sa.Column("user_id", sa.BigInteger(), nullable=False),
|
||||
sa.Column("ruleset_id", sa.SmallInteger(), nullable=False),
|
||||
sa.Column("first_placements", sa.Integer(), nullable=False),
|
||||
sa.Column("total_points", sa.Integer(), nullable=False),
|
||||
sa.Column("elo_data", sa.JSON(), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=True),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
["user_id"],
|
||||
["lazer_users.id"],
|
||||
),
|
||||
sa.PrimaryKeyConstraint("user_id", "ruleset_id"),
|
||||
)
|
||||
op.create_table(
|
||||
"matchmaking_pool_beatmaps",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("pool_id", sa.Integer(), nullable=False),
|
||||
sa.Column("beatmap_id", sa.Integer(), nullable=False),
|
||||
sa.Column("mods", sa.JSON(), nullable=True),
|
||||
sa.Column("rating", sa.Integer(), nullable=False),
|
||||
sa.Column("selection_count", sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(
|
||||
["beatmap_id"],
|
||||
["beatmaps.id"],
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["pool_id"],
|
||||
["matchmaking_pools.id"],
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_matchmaking_pool_beatmaps_pool_id"), "matchmaking_pool_beatmaps", ["pool_id"], unique=False
|
||||
)
|
||||
op.alter_column(
|
||||
"rooms",
|
||||
"type",
|
||||
existing_type=mysql.ENUM("PLAYLISTS", "HEAD_TO_HEAD", "TEAM_VERSUS", name="matchtype"),
|
||||
type_=mysql.ENUM("PLAYLISTS", "HEAD_TO_HEAD", "TEAM_VERSUS", "MATCHMAKING", name="matchtype"),
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.execute("UPDATE rooms SET type='TEAM_VERSUS' WHERE type='MATCHMAKING'")
|
||||
op.alter_column(
|
||||
"rooms",
|
||||
"type",
|
||||
existing_type=mysql.ENUM("PLAYLISTS", "HEAD_TO_HEAD", "TEAM_VERSUS", "MATCHMAKING", name="matchtype"),
|
||||
type_=mysql.ENUM("PLAYLISTS", "HEAD_TO_HEAD", "TEAM_VERSUS", name="matchtype"),
|
||||
)
|
||||
op.drop_index(op.f("ix_matchmaking_pool_beatmaps_pool_id"), table_name="matchmaking_pool_beatmaps")
|
||||
op.drop_table("matchmaking_pool_beatmaps")
|
||||
op.drop_table("matchmaking_user_stats")
|
||||
op.drop_index("matchmaking_pools_ruleset_variant_active_idx", table_name="matchmaking_pools")
|
||||
op.drop_table("matchmaking_pools")
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user