Skip to content

Commit

Permalink
Fine-tune indices
Browse files Browse the repository at this point in the history
  • Loading branch information
ishefi committed Mar 5, 2024
1 parent 60a9d9f commit 1b98b4f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 7 deletions.
53 changes: 53 additions & 0 deletions alembic/versions/6777d9f1937f_fine_tune_indexes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""fine-tune indexes
Revision ID: 6777d9f1937f
Revises: edef17c40466
Create Date: 2024-03-05 17:11:50.533412
"""
from typing import Sequence
from typing import Union

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "6777d9f1937f"
down_revision: Union[str, None] = "edef17c40466"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index("ix_secretword_game_date", table_name="secretword")
op.drop_index("ux_user_id__game_date", table_name="usercluecount")
op.drop_index("ux_user_id__game_date", table_name="userhistory")
op.drop_index("ix_user_email", table_name="user")
op.create_index(
"nci_user_id__game_date",
"userhistory",
["user_id", "game_date"],
unique=False,
mssql_include=["distance", "egg", "guess", "similarity", "solver_count"],
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(
"nci_user_id__game_date",
table_name="userhistory",
mssql_include=["distance", "egg", "guess", "similarity", "solver_count"],
)
op.create_index(
"ux_user_id__game_date", "userhistory", ["user_id", "game_date"], unique=False
)
op.create_index(
"ux_user_id__game_date", "usercluecount", ["user_id", "game_date"], unique=False
)
op.create_index("ix_user_email", "user", columns=["email"], unique=True)
op.create_index(
"ix_secretword_game_date", "secretword", ["game_date"], unique=False
)
# ### end Alembic commands ###
16 changes: 9 additions & 7 deletions common/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def NoFinalHebrewString(length: int | None = None, *args: Any, **kwargs: Any) ->

class User(SQLModel, table=True):
id: int = Field(default=None, primary_key=True)
email: str = NoFinalHebrewString(128, unique=True, index=True)
email: str = NoFinalHebrewString(128, unique=True)
user_type: str = "User" # TODO: enum
active: bool = True
picture: str
Expand All @@ -35,7 +35,12 @@ class User(SQLModel, table=True):
class UserHistory(SQLModel, table=True):
__table_args__ = (
UniqueConstraint("user_id", "game_date", "guess"),
Index("ux_user_id__game_date", "user_id", "game_date"),
Index(
"nci_user_id__game_date",
"user_id",
"game_date",
mssql_include=["distance", "egg", "guess", "similarity", "solver_count"],
),
)

id: int = Field(default=None, primary_key=True)
Expand All @@ -49,10 +54,7 @@ class UserHistory(SQLModel, table=True):


class UserClueCount(SQLModel, table=True):
__table_args__ = (
UniqueConstraint("user_id", "game_date"),
Index("ux_user_id__game_date", "user_id", "game_date"),
)
__table_args__ = (UniqueConstraint("user_id", "game_date"),)

id: int = Field(default=None, primary_key=True)
user_id: int = Field(foreign_key="user.id")
Expand All @@ -65,7 +67,7 @@ class SecretWord(SQLModel, table=True):

id: int = Field(default=None, primary_key=True)
word: str = HebrewString(32, unique=True)
game_date: datetime.date = Field(index=True)
game_date: datetime.date
solver_count: int = 0


Expand Down

0 comments on commit 1b98b4f

Please sign in to comment.