"""可恢复自动成片;仅追加字段,历史运行保留 legacy 语义。""" from alembic import op import sqlalchemy as sa revision = '007' down_revision = '006' branch_labels = None depends_on = None def upgrade(): columns = { 'visual_drafts': [sa.Column('editor_manifest', sa.JSON(), nullable=True)], 'visual_workflow_runs': [ sa.Column('run_kind', sa.String(32), nullable=False, server_default='legacy'), sa.Column('output_goal', sa.String(16), nullable=False, server_default='film'), sa.Column('base_run_id', sa.String(32), nullable=True), sa.Column('source_draft_version', sa.Integer(), nullable=True), sa.Column('plan_snapshot', sa.JSON(), nullable=True), sa.Column('result_manifest', sa.JSON(), nullable=True), sa.Column('apply_state', sa.String(16), nullable=True)], 'visual_workflow_steps': [sa.Column(name, sa.JSON(), nullable=True) for name in ('recipe_json','resolved_input_json','result_json')], } bind = op.get_bind() for table, fields in columns.items(): existing = {c['name'] for c in sa.inspect(bind).get_columns(table)} for field in fields: if field.name not in existing: op.add_column(table, field) def downgrade(): raise RuntimeError('Destructive downgrade unsupported; restore a verified joint checkpoint')