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:
parent
308878749f
commit
eb31d09782
2 changed files with 40 additions and 1 deletions
38
alembic/versions/0023_lang_index_and_qd_symbol_widen.py
Normal file
38
alembic/versions/0023_lang_index_and_qd_symbol_widen.py
Normal 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")
|
||||
|
|
@ -59,7 +59,7 @@ class Quote(Base):
|
|||
class QuoteDaily(Base):
|
||||
"""Daily rollup — sparkline source. PK on (symbol, date)."""
|
||||
__tablename__ = "quotes_daily"
|
||||
symbol: Mapped[str] = mapped_column(String(64), primary_key=True)
|
||||
symbol: Mapped[str] = mapped_column(String(128), primary_key=True)
|
||||
date: Mapped[date] = mapped_column(Date, primary_key=True)
|
||||
close: Mapped[float | None] = mapped_column(Float)
|
||||
high: Mapped[float | None] = mapped_column(Float)
|
||||
|
|
@ -228,6 +228,7 @@ class User(Base):
|
|||
# app/services/i18n.py before writing.
|
||||
lang: Mapped[str] = mapped_column(
|
||||
String(8), nullable=False, default="en", server_default="en",
|
||||
index=True,
|
||||
)
|
||||
# Polar (MoR) linkage — populated by the polar_webhook handler the
|
||||
# first time we see a subscription/order event for the user. The
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue