diff --git a/app/models/__init__.py b/app/models/__init__.py index 45d7ee4..87a3c57 100644 --- a/app/models/__init__.py +++ b/app/models/__init__.py @@ -3,7 +3,7 @@ from .user import User from .message import Message from .follow import Follow from .workspace import Workspace, WorkspaceMember -from .project import ProjectNode +from .project import ProjectItem from .library import LibraryItem from .interaction import ProjectLike, ProjectFavorite, ProjectShare @@ -14,7 +14,7 @@ __all__ = [ "Follow", "Workspace", "WorkspaceMember", - "ProjectNode", + "ProjectItem", "LibraryItem", "ProjectLike", "ProjectFavorite", diff --git a/app/models/interaction.py b/app/models/interaction.py index 0ab3f92..625291e 100644 --- a/app/models/interaction.py +++ b/app/models/interaction.py @@ -5,7 +5,7 @@ from .base import AutoID, Base if TYPE_CHECKING: from .user import User - from .project import ProjectNode + from .project import ProjectItem from .workspace import Workspace class ProjectLike(Base, AutoID): @@ -17,16 +17,16 @@ class ProjectLike(Base, AutoID): ForeignKey("users.id", ondelete="CASCADE"), index=True ) - project_node_id = Column( - String(ProjectNode.id_length()), - ForeignKey("project_nodes.id", ondelete="CASCADE"), + project_item_id = Column( + String(ProjectItem.id_length()), + ForeignKey("project_items.id", ondelete="CASCADE"), index=True ) created_at = Column(DateTime(timezone=True), server_default=func.now()) # 联合唯一约束,防止同一用户重复点赞 - __table_args__ = (UniqueConstraint("user_id", "project_node_id", name="uq_user_project_like"),) + __table_args__ = (UniqueConstraint("user_id", "project_item_id", name="uq_user_project_like"),) class ProjectFavorite(Base, AutoID): @@ -38,16 +38,16 @@ class ProjectFavorite(Base, AutoID): ForeignKey("users.id", ondelete="CASCADE"), index=True ) - project_node_id = Column( - String(ProjectNode.id_length()), - ForeignKey("project_nodes.id", ondelete="CASCADE"), + project_item_id = Column( + String(ProjectItem.id_length()), + ForeignKey("project_items.id", ondelete="CASCADE"), index=True ) created_at = Column(DateTime(timezone=True), server_default=func.now()) # 联合唯一约束,防止重复收藏 - __table_args__ = (UniqueConstraint("user_id", "project_node_id", name="uq_user_project_favorite"),) + __table_args__ = (UniqueConstraint("user_id", "project_item_id", name="uq_user_project_favorite"),) class ProjectShare(Base, AutoID): @@ -59,9 +59,9 @@ class ProjectShare(Base, AutoID): ForeignKey("users.id", ondelete="CASCADE"), index=True ) - project_node_id = Column( - String(ProjectNode.id_length()), - ForeignKey("project_nodes.id", ondelete="CASCADE"), + project_item_id = Column( + String(ProjectItem.id_length()), + ForeignKey("project_items.id", ondelete="CASCADE"), index=True ) diff --git a/app/models/project.py b/app/models/project.py index 108b6f4..caa08b2 100644 --- a/app/models/project.py +++ b/app/models/project.py @@ -2,13 +2,13 @@ from sqlalchemy import Column, DateTime, String, ForeignKey, Integer from sqlalchemy.sql import func from .base import AutoID, Base -class ProjectNode(Base, AutoID): +class ProjectItem(Base, AutoID): """项目与文件夹的树状虚拟文件系统""" - __tablename__ = "project_nodes" + __tablename__ = "project_items" 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) + parent_id = Column(String(32), ForeignKey("project_items.id", ondelete="CASCADE"), nullable=True, index=True) name = Column(String, nullable=False) # 节点类型:'folder' (文件夹) 或 'project' (代表具体文件的项目实体)