Files
life-echo/api/alembic/versions/0002_segments_user_input_text.py
Kevin ea97427767 fix(dev): idempotent Alembic chain for squashed 0001 + clearer dev scripts
- Make migrations 0002–0008 skip schema changes already applied when
  0001_initial creates current ORM (rename segments column, timeline FK,
  memoir phase flags, drop content_tsv, eval_* tables).
- development.sh / internal-eval.sh: surface Alembic stderr, warn on
  docker-style DB hosts, TCP port checks without lsof, verify Uvicorn
  listens before claiming started.
2026-04-07 10:34:18 +08:00

36 lines
1.1 KiB
Python

"""segments: rename transcript_text -> user_input_text
语义:用户输入正文(语音 ASR 或键盘输入),不仅限于「转写」。
Revision ID: 0002_segments_user_input_text
Revises: 0001_initial
"""
from typing import Sequence, Union
import sqlalchemy as sa
from alembic import op
revision: str = "0002_segments_user_input_text"
down_revision: Union[str, None] = "0001_initial"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def _column_names(table_name: str) -> set[str]:
bind = op.get_bind()
inspector = sa.inspect(bind)
return {column["name"] for column in inspector.get_columns(table_name)}
def upgrade() -> None:
columns = _column_names("segments")
if "transcript_text" in columns and "user_input_text" not in columns:
op.execute("ALTER TABLE segments RENAME COLUMN transcript_text TO user_input_text")
def downgrade() -> None:
columns = _column_names("segments")
if "user_input_text" in columns and "transcript_text" not in columns:
op.execute("ALTER TABLE segments RENAME COLUMN user_input_text TO transcript_text")