50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
"""read path indexes
|
|
|
|
Revision ID: a6d2f8b41c9e
|
|
Revises: f2b8d3c9a51e
|
|
Create Date: 2026-09-01 12:00:00.000000
|
|
|
|
"""
|
|
|
|
from collections.abc import Sequence
|
|
|
|
from alembic import op
|
|
|
|
revision: str = "a6d2f8b41c9e"
|
|
down_revision: str | None = "f2b8d3c9a51e"
|
|
branch_labels: str | Sequence[str] | None = None
|
|
depends_on: str | Sequence[str] | None = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.execute("CREATE INDEX ix_jobs_account_id ON jobs (account_id, id DESC)")
|
|
op.execute(
|
|
"CREATE INDEX ix_messages_deleted ON messages "
|
|
"(account_id, deleted_at DESC) WHERE deleted_at IS NOT NULL"
|
|
)
|
|
op.execute(
|
|
"CREATE INDEX ix_messages_pinned ON messages "
|
|
"(account_id, chat_id, date DESC, message_id DESC) "
|
|
"WHERE raw->>'service' LIKE '%PINNED_MESSAGE%'"
|
|
)
|
|
op.execute("CREATE INDEX ix_watches_account ON watches (account_id, id DESC)")
|
|
op.execute("CREATE INDEX ix_alerts_account_ts ON alerts (account_id, ts DESC)")
|
|
op.execute(
|
|
"CREATE INDEX ix_stories_account_date ON stories "
|
|
"(account_id, date DESC NULLS LAST)"
|
|
)
|
|
op.execute(
|
|
"CREATE INDEX ix_annotations_account_msg ON annotations "
|
|
"(account_id, chat_id, message_id)"
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.execute("DROP INDEX IF EXISTS ix_annotations_account_msg")
|
|
op.execute("DROP INDEX IF EXISTS ix_stories_account_date")
|
|
op.execute("DROP INDEX IF EXISTS ix_alerts_account_ts")
|
|
op.execute("DROP INDEX IF EXISTS ix_watches_account")
|
|
op.execute("DROP INDEX IF EXISTS ix_messages_pinned")
|
|
op.execute("DROP INDEX IF EXISTS ix_messages_deleted")
|
|
op.execute("DROP INDEX IF EXISTS ix_jobs_account_id")
|