cmvr-visual/backend/app/models/folders.py
zhanghao 88cf14d794 feat: consolidate story studio and editable automatic production
Restructure backend and frontend modules; add story, library, and editor schema migrations.

Support editable automatic production, manual confirmation modes, account and user lifecycle management, compact container scrolling, consistent forms, and per-task result previews.

Update inference and TTS scheduling, deployment guidance, and regression coverage; remove obsolete standalone pages and temporary acceptance artifacts.
2026-11-14 14:07:26 +08:00

32 lines
1.4 KiB
Python

from datetime import datetime
from sqlalchemy import ForeignKey, String, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import Base, Timestamp, new_id, utcnow
class Folder(Base):
__tablename__ = "visual_folders"
__table_args__ = (
UniqueConstraint("owner_id", "parent_key", "name", name="uq_visual_folders_sibling"),
)
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=new_id)
owner_id: Mapped[str] = mapped_column(ForeignKey("visual_users.id"), index=True)
name: Mapped[str] = mapped_column(String(255))
parent_id: Mapped[str | None] = mapped_column(
ForeignKey("visual_folders.id", ondelete="CASCADE"), nullable=True, index=True
)
# 根目录使用空字符串,避免 MySQL 唯一键对 NULL 允许重复。
parent_key: Mapped[str] = mapped_column(String(32), default="", server_default="")
created_at: Mapped[datetime] = mapped_column(Timestamp, default=utcnow)
updated_at: Mapped[datetime] = mapped_column(Timestamp, default=utcnow)
class AssetFolder(Base):
__tablename__ = "visual_asset_folders"
asset_id: Mapped[str] = mapped_column(
ForeignKey("visual_assets.id", ondelete="CASCADE"), primary_key=True
)
folder_id: Mapped[str] = mapped_column(
ForeignKey("visual_folders.id", ondelete="CASCADE"), primary_key=True, index=True
)