"""006_image_role_varchar — image_candidates.role 从 enum 改 varchar(32)

根因：storyboard 角色名仍在演进（hook/product_closeup/ingredient/texture/
applied_proof/closer/pain_scene/social_proof/scenario/tutorial…），固定 enum
每加一个新角色就要迁一次，且旧 enum 漏了 product_closeup/ingredient 直接导致
落库 "Data truncated for column 'role'" → 生图任务无限重试卡死。
改 varchar 后落库不再受 enum 约束，角色名由 ImageRole 枚举在应用层定义。
"""
from alembic import op
import sqlalchemy as sa


revision = "006"
down_revision = "005"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.alter_column(
        "image_candidates",
        "role",
        existing_type=sa.Enum(
            "hook", "pain", "proof", "quality", "credit", "convert", "main",
            name="role",
        ),
        type_=sa.String(32),
        existing_nullable=False,
        server_default="hook",
        comment="分镜角色名（storyboard 输出，应用层 ImageRole 定义，不在 DB 约束）",
    )


def downgrade() -> None:
    op.alter_column(
        "image_candidates",
        "role",
        existing_type=sa.String(32),
        type_=sa.Enum(
            "hook", "pain", "proof", "quality", "credit", "convert", "main",
            name="role",
        ),
        existing_nullable=False,
        server_default="main",
    )
