"""llm settings field provenance Revision ID: a71e3c92fd45 Revises: 9f4a71c60d38 Create Date: 2026-07-20 18:07:44.902113 """ from typing import Sequence, Union import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. revision: str = "a71e3c92fd45" down_revision: Union[str, Sequence[str], None] = "9f4a71c60d38" branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None _FIELDS = ("base_url", "model", "api_key") def upgrade() -> None: """Upgrade schema.""" # The table changed meaning: it used to hold sparse per-field overrides # on top of the environment, and now holds the full configuration, # seeded from the environment once at first start. for field in _FIELDS: op.add_column( "llm_settings", sa.Column( f"{field}_from_env", sa.Boolean(), server_default=sa.false(), nullable=False, ), ) # The table changed meaning: it used to hold sparse per-field overrides # on top of the environment, and now holds the full configuration, # seeded from the environment at startup. Pre-existing rows are dev # leftovers — nothing is in production yet, so they are dropped rather # than translated, and `bootstrap_llm_settings()` recreates them from # `.env` on the next start. op.execute("DELETE FROM llm_settings") def downgrade() -> None: """Downgrade schema.""" for field in _FIELDS: op.drop_column("llm_settings", f"{field}_from_env")