From 60999c4271cfb288299a1bea502facc6ad91b2a5 Mon Sep 17 00:00:00 2001 From: Zayden Jung Date: Mon, 18 May 2026 23:27:42 +0800 Subject: [PATCH] auto id length in bi ref: project --- app/models/project.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/models/project.py b/app/models/project.py index caa08b2..f5ebd7b 100644 --- a/app/models/project.py +++ b/app/models/project.py @@ -1,14 +1,27 @@ +from typing import TYPE_CHECKING from sqlalchemy import Column, DateTime, String, ForeignKey, Integer from sqlalchemy.sql import func from .base import AutoID, Base +if TYPE_CHECKING: + from .workspace import Workspace + class ProjectItem(Base, AutoID): """项目与文件夹的树状虚拟文件系统""" __tablename__ = "project_items" - workspace_id = Column(String(32), ForeignKey("workspaces.id", ondelete="CASCADE"), index=True) + workspace_id = Column( + String(Workspace.id_length()), + ForeignKey("workspaces.id", ondelete="CASCADE"), + index=True, + ) # 自引用外键:如果是根目录下的顶级节点,则 parent_id 为 Null - parent_id = Column(String(32), ForeignKey("project_items.id", ondelete="CASCADE"), nullable=True, index=True) + parent_id = Column( + String(AutoID.id_length()), # 其实调用的就是自身的 id_length 方法 + ForeignKey("project_items.id", ondelete="CASCADE"), + nullable=True, + index=True, + ) name = Column(String, nullable=False) # 节点类型:'folder' (文件夹) 或 'project' (代表具体文件的项目实体)