- 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.
55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
"""segments:Phase1/Phase2 标志(叙事延迟管线)
|
||
|
||
Revision ID: 0006_segment_memoir_phases
|
||
Revises: 0005_cleanup_story_links
|
||
"""
|
||
|
||
from typing import Sequence, Union
|
||
|
||
import sqlalchemy as sa
|
||
|
||
from alembic import op
|
||
|
||
revision: str = "0006_segment_memoir_phases"
|
||
down_revision: Union[str, None] = "0005_cleanup_story_links"
|
||
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 "narrated" not in columns:
|
||
op.add_column(
|
||
"segments",
|
||
sa.Column(
|
||
"narrated",
|
||
sa.Boolean(),
|
||
nullable=False,
|
||
server_default=sa.text("false"),
|
||
),
|
||
)
|
||
if "skip_narrative" not in columns:
|
||
op.add_column(
|
||
"segments",
|
||
sa.Column(
|
||
"skip_narrative",
|
||
sa.Boolean(),
|
||
nullable=False,
|
||
server_default=sa.text("false"),
|
||
),
|
||
)
|
||
|
||
|
||
def downgrade() -> None:
|
||
columns = _column_names("segments")
|
||
if "skip_narrative" in columns:
|
||
op.drop_column("segments", "skip_narrative")
|
||
if "narrated" in columns:
|
||
op.drop_column("segments", "narrated")
|