Skip to content

Commit

Permalink
Fix: add index on comment.object_id column (#988)
Browse files Browse the repository at this point in the history
  • Loading branch information
psrok1 authored Oct 4, 2024
1 parent d593f69 commit cee2503
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mwdb/model/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ class Comment(db.Model):
timestamp = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)

object_id = db.Column(
db.Integer, db.ForeignKey("object.id", ondelete="CASCADE"), nullable=False
db.Integer,
db.ForeignKey("object.id", ondelete="CASCADE"),
nullable=False,
index=True,
)
user_id = db.Column(
db.Integer, db.ForeignKey("user.id", ondelete="SET NULL"), nullable=True
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Add index on comment.object_id
Revision ID: 2c44b2073670
Revises: 72a94f88d2b6
Create Date: 2024-10-04 15:52:04.736269
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "2c44b2073670"
down_revision = "72a94f88d2b6"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_index(
op.f("ix_comment_object_id"), "comment", ["object_id"], unique=False
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f("ix_comment_object_id"), table_name="comment")
# ### end Alembic commands ###

0 comments on commit cee2503

Please sign in to comment.