Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""add composite index on metagraph_history for lateral join optimization

Revision ID: 187893f603bd
Revises: 8bf23e9921f1
Create Date: 2026-02-23 12:00:00.000000

"""

from typing import Sequence, Union

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "187893f603bd"
down_revision: Union[str, None] = "8bf23e9921f1"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# CREATE INDEX CONCURRENTLY cannot run inside a transaction
op.execute("COMMIT")
op.execute("""
CREATE INDEX CONCURRENTLY IF NOT EXISTS ix_metagraph_history_uid_updated_at
ON metagraph_history (neuron_uid, updated_at DESC)
INCLUDE (ip_address)
""")


def downgrade() -> None:
# DROP INDEX CONCURRENTLY cannot run inside a transaction
op.execute("COMMIT")
op.execute("""
DROP INDEX CONCURRENTLY IF EXISTS ix_metagraph_history_uid_updated_at
""")
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@


def upgrade() -> None:
# CREATE INDEX CONCURRENTLY cannot run inside a transaction
op.execute("COMMIT")

query = """CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_mp_vr_id
ON miner_predictions (validator_requests_id);"""

Expand All @@ -30,6 +33,9 @@ def upgrade() -> None:


def downgrade() -> None:
# DROP INDEX CONCURRENTLY cannot run inside a transaction
op.execute("COMMIT")

query = """DROP INDEX CONCURRENTLY IF EXISTS idx_mp_vr_id;"""
op.execute(query)

Expand Down