Skip to content

Commit

Permalink
Add index for the users deduplication step
Browse files Browse the repository at this point in the history
Add index for the users deduplication step
  • Loading branch information
marcospri committed Aug 12, 2024
1 parent 613ffc8 commit 77b7537
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Add index for user deduplication."""

import sqlalchemy as sa
from alembic import op

revision = "7858a12c4e4a"
down_revision = "f6c442c861c4"


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

op.create_index(
"ix__user_h_user_updated",
"user",
["h_userid", sa.text("updated DESC")],
unique=False,
postgresql_concurrently=True,
)


def downgrade() -> None:
op.drop_index("ix__user_h_user_updated", table_name="user")
1 change: 1 addition & 0 deletions lms/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class User(CreatedUpdatedMixin, Base):
"h_userid",
name="uq__user__application_instance_id__h_userid",
),
sa.Index("ix__user_h_user_updated", "h_userid", sa.desc("updated")),
)

id = sa.Column(sa.Integer, autoincrement=True, primary_key=True)
Expand Down

0 comments on commit 77b7537

Please sign in to comment.