alembic: 0023 — users.lang index + widen quotes_daily.symbol

Two related schema fixes from the code review:

- users.lang gets a single-column index. The ai_log_job and
  email_digest_job both SELECT DISTINCT on this column every cycle;
  even at low cardinality an index is the right shape.
- quotes_daily.symbol widened to VARCHAR(128) to match quotes.symbol
  (widened back in 0005). Long Eurostat/ONS symbols would silently
  truncate during rollup otherwise.

Models updated to match (User.lang gains index=True, QuoteDaily.symbol
goes to String(128)).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Giorgio Gilestro 2026-05-27 19:35:09 +02:00
parent 308878749f
commit eb31d09782
2 changed files with 40 additions and 1 deletions

View file

@ -0,0 +1,38 @@
"""users.lang index + widen quotes_daily.symbol to VARCHAR(128).
Revision ID: 0023
Revises: 0022
Create Date: 2026-05-27
"""
from typing import Sequence, Union
import sqlalchemy as sa
from alembic import op
revision: str = "0023"
down_revision: Union[str, None] = "0022"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.create_index("ix_users_lang", "users", ["lang"])
op.alter_column(
"quotes_daily",
"symbol",
existing_type=sa.String(length=64),
type_=sa.String(length=128),
existing_nullable=False,
)
def downgrade() -> None:
op.alter_column(
"quotes_daily",
"symbol",
existing_type=sa.String(length=128),
type_=sa.String(length=64),
existing_nullable=False,
)
op.drop_index("ix_users_lang", table_name="users")