"""#632 - 一键生成输出分辨率可配置 Revision ID: 051 Revises: 050 Create Date: 2026-07-23 Changes: 1. generation_tasks 表新增 resolution 字段,存储用户指定的输出分辨率(如 "1280x720") 2. 为空时使用默认值(1280x720) """ import sqlalchemy as sa from alembic import context, op revision = "051_generation_task_resolution" down_revision = "050_video_shares" branch_labels = None depends_on = None def upgrade() -> None: conn = op.get_bind() if context.get_context().dialect.name == "postgresql": # 检查列是否已存在(幂等) result = conn.execute( sa.text( "SELECT column_name FROM information_schema.columns " "WHERE table_name = 'generation_tasks' AND column_name = 'resolution'" ) ) if result.scalar() is not None: return op.add_column( "generation_tasks", sa.Column("resolution", sa.String(20), nullable=False, server_default=""), ) def downgrade() -> None: conn = op.get_bind() if context.get_context().dialect.name == "postgresql": result = conn.execute( sa.text( "SELECT column_name FROM information_schema.columns " "WHERE table_name = 'generation_tasks' AND column_name = 'resolution'" ) ) if result.scalar() is None: return op.drop_column("generation_tasks", "resolution")