Skip to content

Commit

Permalink
Add indexes for courses, assignment and user names
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Aug 5, 2024
1 parent b2e1f70 commit 5abf47f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Add indexes for names we sort by in the dashboards."""

import sqlalchemy as sa
from alembic import op

revision = "afa53b7464be"
down_revision = "ca27e52b7303"


def upgrade() -> None:
# CONCURRENTLY can't be used inside a transaction. Finish the current one.
op.execute("COMMIT")

op.create_index(
op.f("ix__assignment_title"),
"assignment",
["title"],
unique=False,
postgresql_concurrently=True,
)
op.create_index(
op.f("ix__grouping_lms_name"),
"grouping",
["lms_name"],
unique=False,
postgresql_concurrently=True,
)
op.create_index(
op.f("ix__user_display_name"),
"user",
["display_name"],
unique=False,
postgresql_concurrently=True,
)


def downgrade() -> None:
op.drop_index(op.f("ix__user_display_name"), table_name="user")
op.drop_index(op.f("ix__grouping_lms_name"), table_name="grouping")
op.drop_index(op.f("ix__assignment_title"), table_name="assignment")
2 changes: 1 addition & 1 deletion lms/models/assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Assignment(CreatedUpdatedMixin, Base):
)
"""Whether this assignment is gradable or not."""

title: Mapped[str | None] = mapped_column(sa.Unicode)
title: Mapped[str | None] = mapped_column(sa.Unicode, index=True)
"""The resource link title from LTI params."""

description = sa.Column(sa.Unicode, nullable=True)
Expand Down
2 changes: 1 addition & 1 deletion lms/models/grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Type(str, Enum):
lms_id = sa.Column(sa.Unicode(), nullable=False)

#: Full name given on the LMS (e.g. "A course name 101")
lms_name: Mapped[str] = mapped_column(sa.UnicodeText())
lms_name: Mapped[str] = mapped_column(sa.UnicodeText(), index=True)

type = varchar_enum(Type, nullable=False)

Expand Down
2 changes: 1 addition & 1 deletion lms/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ class User(CreatedUpdatedMixin, Base):
email: Mapped[str | None] = mapped_column(sa.Unicode)
"""Email address of the user"""

display_name: Mapped[str | None] = mapped_column(sa.Unicode)
display_name: Mapped[str | None] = mapped_column(sa.Unicode, index=True)
"""The user's display name."""

0 comments on commit 5abf47f

Please sign in to comment.