diff --git a/app/models/library.py b/app/models/library.py new file mode 100644 index 0000000..ab722be --- /dev/null +++ b/app/models/library.py @@ -0,0 +1,23 @@ +from sqlalchemy import Column, DateTime, String, ForeignKey, BigInteger +from sqlalchemy.sql import func +from .base import AutoID, Base + +class LibraryItem(Base, AutoID): + """工作区共享媒体/文件资源库""" + __tablename__ = "library_items" + + workspace_id = Column(String(32), ForeignKey("workspaces.id", ondelete="CASCADE"), index=True) + # 自引用外键,支持无限级文件夹嵌套 + parent_id = Column(String(32), ForeignKey("library_items.id", ondelete="CASCADE"), nullable=True, index=True) + + name = Column(String, nullable=False) + # 节点类型:'folder' (文件夹) 或 'file' (真实文件) + item_type = Column(String, default="file", nullable=False) + + # --- 以下为真实文件(item_type='file')的核心字段 --- + s3_key = Column(String, nullable=True) # S3 中的 Object Key + file_size = Column(BigInteger, nullable=True) # 文件大小(字节数 Bytes),用于统计容量占用 + mime_type = Column(String, nullable=True) # 媒体类型,例如 'image/jpeg', 'video/mp4', 'application/pdf' + + uploaded_by = Column(String(32), ForeignKey("users.id", ondelete="SET NULL"), nullable=True) + created_at = Column(DateTime(timezone=True), server_default=func.now()) \ No newline at end of file diff --git a/app/models/project.py b/app/models/project.py new file mode 100644 index 0000000..4a380da --- /dev/null +++ b/app/models/project.py @@ -0,0 +1,20 @@ +from sqlalchemy import Column, DateTime, String, ForeignKey +from sqlalchemy.sql import func +from .base import AutoID, Base + +class ProjectNode(Base, AutoID): + """项目与文件夹的树状虚拟文件系统""" + __tablename__ = "project_nodes" + + workspace_id = Column(String(32), ForeignKey("workspaces.id", ondelete="CASCADE"), index=True) + # 自引用外键:如果是根目录下的顶级节点,则 parent_id 为 Null + parent_id = Column(String(32), ForeignKey("project_nodes.id", ondelete="CASCADE"), nullable=True, index=True) + + name = Column(String, nullable=False) + # 节点类型:'folder' (文件夹) 或 'project' (代表具体文件的项目实体) + node_type = Column(String, default="project", nullable=False) + + # 如果是 project 节点,可以用这一列来存储其内容或配置快照(如 JSON 文本) + content = Column(String, nullable=True) + + created_at = Column(DateTime(timezone=True), server_default=func.now()) \ No newline at end of file