Files
rf4-spotter/apps/api/alembic/versions/0011_query_indexes.py
T
ik 5e27a5b066
CI / backend-and-migrations (push) Canceled after 0s
CI / astro-build (push) Canceled after 0s
CI / compose-e2e (push) Canceled after 0s
perf: stabilize list queries for pilot
2026-09-07 08:02:37 +07:00

30 lines
1.8 KiB
Python

"""Add composite indexes for pilot list and maintenance queries."""
from alembic import op
revision = "0011"
down_revision = "0010"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.create_index("ix_catch_report_activity_lookup", "catch_report", ["moderation_status", "deleted_at", "reported_at"])
op.create_index("ix_catch_report_spot_feed", "catch_report", ["spot_id", "moderation_status", "deleted_at", "reported_at"])
op.create_index("ix_catch_report_moderation_queue", "catch_report", ["source_type", "moderation_status", "deleted_at", "reported_at"])
op.create_index("ix_catch_report_official_records", "catch_report", ["source_type", "caught_at", "weight_g"])
op.create_index("ix_official_import_source_status_started", "official_record_import", ["source_url", "status", "started_at"])
op.create_index("ix_external_observation_review_queue", "external_observation", ["status", "source_system", "last_seen_at"])
op.create_index("ix_submission_attempt_client_created", "submission_attempt", ["client_hash", "created_at"])
op.create_index("ix_moderation_event_created_at", "moderation_event", ["created_at"])
def downgrade() -> None:
op.drop_index("ix_moderation_event_created_at", table_name="moderation_event")
op.drop_index("ix_submission_attempt_client_created", table_name="submission_attempt")
op.drop_index("ix_external_observation_review_queue", table_name="external_observation")
op.drop_index("ix_official_import_source_status_started", table_name="official_record_import")
op.drop_index("ix_catch_report_official_records", table_name="catch_report")
op.drop_index("ix_catch_report_moderation_queue", table_name="catch_report")
op.drop_index("ix_catch_report_spot_feed", table_name="catch_report")
op.drop_index("ix_catch_report_activity_lookup", table_name="catch_report")