35 lines
1.7 KiB
Python
35 lines
1.7 KiB
Python
"""采集素材(图片/视频):分组、源站 URL、转存 URL、状态。"""
|
|
from __future__ import annotations
|
|
|
|
import uuid
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import DateTime, Enum, ForeignKey, Integer, String, Text, Uuid, func
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from db import Base
|
|
from models.enums import AssetStatus
|
|
|
|
|
|
class ProductAsset(Base):
|
|
__tablename__ = "product_assets"
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(Uuid(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
product_id: Mapped[uuid.UUID] = mapped_column(
|
|
Uuid(as_uuid=True), ForeignKey("products.id", ondelete="CASCADE"), index=True
|
|
)
|
|
group_key: Mapped[str] = mapped_column(String(16), default="main") # main/sku/detail/video/param/generated
|
|
variant_name: Mapped[str | None] = mapped_column(String(128), nullable=True) # SKU 规格名
|
|
sort_order: Mapped[int] = mapped_column(Integer, default=0)
|
|
type: Mapped[str] = mapped_column(String(8), default="img") # img / video
|
|
source_url: Mapped[str] = mapped_column(Text, default="")
|
|
stored_url: Mapped[str | None] = mapped_column(Text, nullable=True) # 本地路径或七牛公网 URL
|
|
status: Mapped[AssetStatus] = mapped_column(
|
|
Enum(AssetStatus, native_enum=False, length=16), default=AssetStatus.pending, index=True
|
|
)
|
|
dedupe_key: Mapped[str | None] = mapped_column(String(512), nullable=True, index=True)
|
|
width: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
height: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
error: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|