Three recently-added tables (strategic_log_translations, indicator_summary_translations, csv_format_templates) drifted from the codebase's existing naming convention: - llm_model -> model - llm_cost_usd -> cost_usd - content_md -> content (on the two translation tables; csv_format doesn't have a content field) Also added prompt_tokens and completion_tokens to the three tables; they were silently dropped at write time despite LogResult exposing them. All writer call sites (ai_log_job, indicator_summary_job, llm_csv_parser) and reader call sites (api.py localized helpers) updated to match. Tests realigned. Migration 0025 uses batch_alter_table for SQLite compatibility. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
79 lines
3.9 KiB
Python
79 lines
3.9 KiB
Python
"""align translation column naming + add token counts.
|
|
|
|
Revision ID: 0025
|
|
Revises: 0024
|
|
Create Date: 2026-05-27
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
|
|
revision: str = "0025"
|
|
down_revision: Union[str, None] = "0024"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# strategic_log_translations
|
|
with op.batch_alter_table("strategic_log_translations") as bop:
|
|
bop.alter_column("llm_model", new_column_name="model",
|
|
existing_type=sa.String(length=64), existing_nullable=True)
|
|
bop.alter_column("llm_cost_usd", new_column_name="cost_usd",
|
|
existing_type=sa.Float(), existing_nullable=True)
|
|
bop.alter_column("content_md", new_column_name="content",
|
|
existing_type=sa.Text(), existing_nullable=False)
|
|
bop.add_column(sa.Column("prompt_tokens", sa.Integer(), nullable=True))
|
|
bop.add_column(sa.Column("completion_tokens", sa.Integer(), nullable=True))
|
|
|
|
# indicator_summary_translations
|
|
with op.batch_alter_table("indicator_summary_translations") as bop:
|
|
bop.alter_column("llm_model", new_column_name="model",
|
|
existing_type=sa.String(length=64), existing_nullable=True)
|
|
bop.alter_column("llm_cost_usd", new_column_name="cost_usd",
|
|
existing_type=sa.Float(), existing_nullable=True)
|
|
bop.alter_column("content_md", new_column_name="content",
|
|
existing_type=sa.Text(), existing_nullable=False)
|
|
bop.add_column(sa.Column("prompt_tokens", sa.Integer(), nullable=True))
|
|
bop.add_column(sa.Column("completion_tokens", sa.Integer(), nullable=True))
|
|
|
|
# csv_format_templates
|
|
with op.batch_alter_table("csv_format_templates") as bop:
|
|
bop.alter_column("llm_model", new_column_name="model",
|
|
existing_type=sa.String(length=64), existing_nullable=True)
|
|
bop.alter_column("llm_cost_usd", new_column_name="cost_usd",
|
|
existing_type=sa.Float(), existing_nullable=True)
|
|
bop.add_column(sa.Column("prompt_tokens", sa.Integer(), nullable=True))
|
|
bop.add_column(sa.Column("completion_tokens", sa.Integer(), nullable=True))
|
|
|
|
|
|
def downgrade() -> None:
|
|
with op.batch_alter_table("csv_format_templates") as bop:
|
|
bop.drop_column("completion_tokens")
|
|
bop.drop_column("prompt_tokens")
|
|
bop.alter_column("cost_usd", new_column_name="llm_cost_usd",
|
|
existing_type=sa.Float(), existing_nullable=True)
|
|
bop.alter_column("model", new_column_name="llm_model",
|
|
existing_type=sa.String(length=64), existing_nullable=True)
|
|
|
|
with op.batch_alter_table("indicator_summary_translations") as bop:
|
|
bop.drop_column("completion_tokens")
|
|
bop.drop_column("prompt_tokens")
|
|
bop.alter_column("content", new_column_name="content_md",
|
|
existing_type=sa.Text(), existing_nullable=False)
|
|
bop.alter_column("cost_usd", new_column_name="llm_cost_usd",
|
|
existing_type=sa.Float(), existing_nullable=True)
|
|
bop.alter_column("model", new_column_name="llm_model",
|
|
existing_type=sa.String(length=64), existing_nullable=True)
|
|
|
|
with op.batch_alter_table("strategic_log_translations") as bop:
|
|
bop.drop_column("completion_tokens")
|
|
bop.drop_column("prompt_tokens")
|
|
bop.alter_column("content", new_column_name="content_md",
|
|
existing_type=sa.Text(), existing_nullable=False)
|
|
bop.alter_column("cost_usd", new_column_name="llm_cost_usd",
|
|
existing_type=sa.Float(), existing_nullable=True)
|
|
bop.alter_column("model", new_column_name="llm_model",
|
|
existing_type=sa.String(length=64), existing_nullable=True)
|