auto id length in bi ref: library

This commit is contained in:
2026-05-18 23:28:44 +08:00
parent 60999c4271
commit 41fc874481
+21 -3
View File
@@ -1,14 +1,28 @@
from typing import TYPE_CHECKING
from sqlalchemy import Column, DateTime, String, ForeignKey, BigInteger
from sqlalchemy.sql import func
from .base import AutoID, Base
if TYPE_CHECKING:
from .user import User
from .workspace import Workspace
class LibraryItem(Base, AutoID):
"""工作区共享媒体/文件资源库"""
__tablename__ = "library_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 = Column(String(32), ForeignKey("library_items.id", ondelete="CASCADE"), nullable=True, index=True)
parent_id = Column(
String(AutoID.id_length()),
ForeignKey("library_items.id", ondelete="CASCADE"),
nullable=True,
index=True,
)
name = Column(String, nullable=False)
# 节点类型:'folder' (文件夹) 或 'file' (真实文件)
@@ -19,5 +33,9 @@ class LibraryItem(Base, AutoID):
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)
uploaded_by = Column(
String(User.id_length()),
ForeignKey("users.id", ondelete="SET NULL"),
nullable=True,
)
created_at = Column(DateTime(timezone=True), server_default=func.now())