You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.0 KiB
Python
61 lines
2.0 KiB
Python
"""add performance indexes for CalculatedMetrics and AttentionFeaturesDaily
|
|
|
|
Revision ID: b3c4d5e6f7a8
|
|
Revises: a1b2c3d4e5f6
|
|
Create Date: 2026-03-19
|
|
|
|
Adds standalone indexes that were missing from the initial schema:
|
|
- calculated_metrics.calculation_date (date-only range queries)
|
|
- calculated_metrics.period_date (period-based lookups)
|
|
- attention_features_daily.ticker (ticker-only scans)
|
|
"""
|
|
|
|
from typing import Sequence, Union
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision: str = "b3c4d5e6f7a8"
|
|
down_revision: Union[str, Sequence[str], None] = "a1b2c3d4e5f6"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
conn = op.get_bind()
|
|
|
|
# CalculatedMetrics — standalone date indexes
|
|
_indexes = conn.dialect.get_indexes(conn, "calculated_metrics")
|
|
existing = {idx["name"] for idx in _indexes}
|
|
|
|
if "idx_metrics_calculation_date" not in existing:
|
|
op.create_index(
|
|
"idx_metrics_calculation_date",
|
|
"calculated_metrics",
|
|
["calculation_date"],
|
|
)
|
|
|
|
if "idx_metrics_period_date" not in existing:
|
|
op.create_index(
|
|
"idx_metrics_period_date",
|
|
"calculated_metrics",
|
|
["period_date"],
|
|
)
|
|
|
|
# AttentionFeaturesDaily — standalone ticker index
|
|
_attn_indexes = conn.dialect.get_indexes(conn, "attention_features_daily")
|
|
existing_attn = {idx["name"] for idx in _attn_indexes}
|
|
|
|
if "idx_attention_features_daily_ticker" not in existing_attn:
|
|
op.create_index(
|
|
"idx_attention_features_daily_ticker",
|
|
"attention_features_daily",
|
|
["ticker"],
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("idx_metrics_calculation_date", table_name="calculated_metrics")
|
|
op.drop_index("idx_metrics_period_date", table_name="calculated_metrics")
|
|
op.drop_index("idx_attention_features_daily_ticker", table_name="attention_features_daily")
|