"""create product_images table Revision ID: 020 Revises: 019 Create Date: 2026-06-18 R5 产品多图:一产品多张参考图,每张标 scene 场景类型(primary/scene/ texture/ingredient/model),生图按分镜 role 选用对应图,取不到回落主图。 product.image_path 仍保留当主图(向后兼容,零破坏)。 """ from alembic import op import sqlalchemy as sa revision = "020" down_revision = "019" branch_labels = None depends_on = None _SCENES = ("primary", "scene", "texture", "ingredient", "model") def upgrade(): op.create_table( "product_images", sa.Column("id", sa.BigInteger, primary_key=True, autoincrement=True), sa.Column( "product_id", sa.BigInteger, sa.ForeignKey("products.id", ondelete="CASCADE"), nullable=False, ), sa.Column("path", sa.String(512), nullable=False, comment="绝对路径,worker直接open"), sa.Column( "scene", sa.Enum(*_SCENES, name="productimagescene"), nullable=False, server_default="primary", comment="场景类型:白底主图/使用场景/质地/成分/上脸", ), sa.Column("is_primary", sa.Boolean, nullable=False, server_default=sa.false(), comment="主图(同步 product.image_path)"), sa.Column("sort_order", sa.Integer, nullable=False, server_default="0"), sa.Column("created_at", sa.DateTime, server_default=sa.func.now(), nullable=False), ) op.create_index("idx_product_images_product_id", "product_images", ["product_id"]) def downgrade(): op.drop_index("idx_product_images_product_id", table_name="product_images") op.drop_table("product_images")