optimize index

pull/21891/head
ytqh 1 year ago
parent 5cb2c464c4
commit fe9639e659

@ -0,0 +1,33 @@
"""add index of model
Revision ID: ad332d76d058
Revises: 69f4e59ecafb
Create Date: 2025-04-21 10:11:53.584079
"""
from alembic import op
import models as models
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'ad332d76d058'
down_revision = '69f4e59ecafb'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('messages', schema=None) as batch_op:
batch_op.create_index('message_end_user_org_created_idx', ['from_end_user_id', 'organization_id', 'created_at'], unique=False)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('messages', schema=None) as batch_op:
batch_op.drop_index('message_end_user_org_created_idx')
# ### end Alembic commands ###

@ -793,6 +793,7 @@ class Message(db.Model): # type: ignore[name-defined]
db.Index("message_workflow_run_id_idx", "conversation_id", "workflow_run_id"),
db.Index("message_created_at_idx", "created_at"),
db.Index("message_organization_id_idx", "organization_id"),
db.Index("message_end_user_org_created_idx", "from_end_user_id", "organization_id", "created_at"),
)
id: Mapped[str] = mapped_column(StringUUID, server_default=db.text("uuid_generate_v4()"))

Loading…
Cancel
Save