auto id length in bi ref: library
This commit is contained in:
+22
-4
@@ -1,23 +1,41 @@
|
||||
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' (真实文件)
|
||||
item_type = Column(String, default="file", nullable=False)
|
||||
|
||||
# --- 以下为真实文件(item_type='file')的核心字段 ---
|
||||
s3_key = Column(String, nullable=True) # S3 中的 Object Key
|
||||
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)
|
||||
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())
|
||||
Reference in New Issue
Block a user