diff --git a/app/database/matchmaking.py b/app/database/matchmaking.py index 3d55d8f..26af4de 100644 --- a/app/database/matchmaking.py +++ b/app/database/matchmaking.py @@ -24,9 +24,9 @@ class MatchmakingUserStatsBase(SQLModel, UTCBaseModel): default=None, sa_column=Column(BigInteger, ForeignKey("lazer_users.id"), primary_key=True), ) - ruleset_id: int = Field( + pool_id: int = Field( default=None, - sa_column=Column(SmallInteger, primary_key=True), + sa_column=Column(ForeignKey("matchmaking_pools.id"), primary_key=True, nullable=True), ) first_placements: int = Field(default=0, ge=0) total_points: int = Field(default=0, ge=0) @@ -43,8 +43,13 @@ class MatchmakingUserStatsBase(SQLModel, UTCBaseModel): class MatchmakingUserStats(MatchmakingUserStatsBase, table=True): __tablename__: str = "matchmaking_user_stats" + __table_args__ = ( + Index("matchmaking_user_stats_pool_first_idx", "pool_id", "first_placements"), + Index("matchmaking_user_stats_pool_points_idx", "pool_id", "total_points"), + ) user: "User" = Relationship(back_populates="matchmaking_stats", sa_relationship_kwargs={"lazy": "joined"}) + pool: "MatchmakingPool" = Relationship() class MatchmakingPoolBase(SQLModel, UTCBaseModel): @@ -53,13 +58,11 @@ class MatchmakingPoolBase(SQLModel, UTCBaseModel): default=0, sa_column=Column(SmallInteger, nullable=False), ) - variant_id: int = Field( - default=0, - ge=0, - sa_column=Column(SmallInteger, nullable=False, server_default="0"), - ) name: str = Field(max_length=255) active: bool = Field(default=True) + lobby_size: int = Field(default=8) + rating_search_radius: int = Field(default=20) + rating_search_radius_exp: int = Field(default=15) created_at: datetime | None = Field( default=None, sa_column=Column(DateTime(timezone=True), server_default=func.now()), @@ -72,7 +75,7 @@ class MatchmakingPoolBase(SQLModel, UTCBaseModel): class MatchmakingPool(MatchmakingPoolBase, table=True): __tablename__: str = "matchmaking_pools" - __table_args__ = (Index("matchmaking_pools_ruleset_variant_active_idx", "ruleset_id", "variant_id", "active"),) + __table_args__ = (Index("matchmaking_pools_ruleset_active_idx", "ruleset_id", "active"),) beatmaps: list["MatchmakingPoolBeatmap"] = Relationship( back_populates="pool", @@ -93,7 +96,7 @@ class MatchmakingPoolBeatmapBase(SQLModel, UTCBaseModel): sa_column=Column(ForeignKey("beatmaps.id"), nullable=False), ) mods: list[APIMod] | None = Field(default=None, sa_column=Column(JSON)) - rating: int = Field(default=1500) + rating: int | None = Field(default=1500) selection_count: int = Field(default=0) diff --git a/migrations/versions/2025-11-22_3f0f22f38c3d_matchmaking_sync_with_osu_web.py b/migrations/versions/2025-11-22_3f0f22f38c3d_matchmaking_sync_with_osu_web.py new file mode 100644 index 0000000..a8959eb --- /dev/null +++ b/migrations/versions/2025-11-22_3f0f22f38c3d_matchmaking_sync_with_osu_web.py @@ -0,0 +1,61 @@ +"""matchmaking: sync with osu-web + +Revision ID: 3f0f22f38c3d +Revises: a7646e082906 +Create Date: 2025-11-22 12:45:36.767097 + +""" + +from collections.abc import Sequence + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import mysql + +# revision identifiers, used by Alembic. +revision: str = "3f0f22f38c3d" +down_revision: str | Sequence[str] | None = "a7646e082906" +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.drop_index(op.f("matchmaking_pools_ruleset_variant_active_idx"), table_name="matchmaking_pools") + op.create_index("matchmaking_pools_ruleset_active_idx", "matchmaking_pools", ["ruleset_id", "active"], unique=False) + op.drop_column("matchmaking_pools", "variant_id") + op.add_column("matchmaking_user_stats", sa.Column("pool_id", sa.Integer(), nullable=True)) + op.create_index( + "matchmaking_user_stats_pool_first_idx", "matchmaking_user_stats", ["pool_id", "first_placements"], unique=False + ) + op.create_index( + "matchmaking_user_stats_pool_points_idx", "matchmaking_user_stats", ["pool_id", "total_points"], unique=False + ) + op.create_foreign_key(None, "matchmaking_user_stats", "matchmaking_pools", ["pool_id"], ["id"]) + op.drop_column("matchmaking_user_stats", "ruleset_id") + # ### end Alembic commands ### + + +def downgrade() -> None: + """Downgrade schema.""" + # ### commands auto generated by Alembic - please adjust! ### + op.add_column( + "matchmaking_user_stats", + sa.Column("ruleset_id", mysql.SMALLINT(), nullable=False, server_default="0"), + ) + op.drop_index("matchmaking_user_stats_pool_points_idx", table_name="matchmaking_user_stats") + op.drop_index("matchmaking_user_stats_pool_first_idx", table_name="matchmaking_user_stats") + op.drop_column("matchmaking_user_stats", "pool_id") + op.add_column( + "matchmaking_pools", + sa.Column("variant_id", mysql.SMALLINT(), nullable=False, server_default="0"), + ) + op.drop_index("matchmaking_pools_ruleset_active_idx", table_name="matchmaking_pools") + op.create_index( + "matchmaking_pools_ruleset_variant_active_idx", + "matchmaking_pools", + ["ruleset_id", "variant_id", "active"], + unique=False, + ) + # ### end Alembic commands ###