2025-12-20 11:18:59 +00:00
|
|
|
|
"""
|
|
|
|
|
|
项目模型
|
|
|
|
|
|
"""
|
|
|
|
|
|
from sqlalchemy import Column, BigInteger, String, Integer, DateTime, SmallInteger, Enum
|
|
|
|
|
|
from sqlalchemy.sql import func
|
|
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
import enum
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProjectMemberRole(str, enum.Enum):
|
|
|
|
|
|
"""项目成员角色枚举"""
|
|
|
|
|
|
ADMIN = "admin"
|
|
|
|
|
|
EDITOR = "editor"
|
|
|
|
|
|
VIEWER = "viewer"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Project(Base):
|
|
|
|
|
|
"""项目表模型"""
|
|
|
|
|
|
|
|
|
|
|
|
__tablename__ = "projects"
|
|
|
|
|
|
|
|
|
|
|
|
id = Column(BigInteger, primary_key=True, autoincrement=True, comment="项目ID")
|
|
|
|
|
|
name = Column(String(100), nullable=False, index=True, comment="项目名称")
|
|
|
|
|
|
description = Column(String(500), comment="项目描述")
|
|
|
|
|
|
storage_key = Column(String(36), nullable=False, unique=True, comment="磁盘存储UUID")
|
|
|
|
|
|
owner_id = Column(BigInteger, nullable=False, index=True, comment="项目所有者ID")
|
|
|
|
|
|
is_public = Column(SmallInteger, default=0, comment="是否公开:0-私有 1-公开")
|
|
|
|
|
|
is_template = Column(SmallInteger, default=0, comment="是否模板项目:0-否 1-是")
|
|
|
|
|
|
status = Column(SmallInteger, default=1, index=True, comment="状态:0-归档 1-活跃")
|
|
|
|
|
|
cover_image = Column(String(255), comment="封面图")
|
|
|
|
|
|
sort_order = Column(Integer, default=0, comment="排序号")
|
|
|
|
|
|
visit_count = Column(Integer, default=0, comment="访问次数")
|
|
|
|
|
|
access_pass = Column(String(100), comment="访问密码(用于分享链接)")
|
|
|
|
|
|
created_at = Column(DateTime, server_default=func.now(), index=True, comment="创建时间")
|
|
|
|
|
|
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), comment="更新时间")
|
|
|
|
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
|
|
return f"<Project(id={self.id}, name='{self.name}')>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProjectMember(Base):
|
|
|
|
|
|
"""项目成员表模型"""
|
|
|
|
|
|
|
|
|
|
|
|
__tablename__ = "project_members"
|
|
|
|
|
|
|
|
|
|
|
|
id = Column(BigInteger, primary_key=True, autoincrement=True, comment="成员ID")
|
|
|
|
|
|
project_id = Column(BigInteger, nullable=False, index=True, comment="项目ID")
|
|
|
|
|
|
user_id = Column(BigInteger, nullable=False, index=True, comment="用户ID")
|
|
|
|
|
|
role = Column(
|
2025-12-29 12:53:50 +00:00
|
|
|
|
String(20),
|
|
|
|
|
|
default="viewer",
|
2025-12-20 11:18:59 +00:00
|
|
|
|
index=True,
|
2025-12-29 12:53:50 +00:00
|
|
|
|
comment="项目角色: admin/editor/viewer"
|
2025-12-20 11:18:59 +00:00
|
|
|
|
)
|
|
|
|
|
|
invited_by = Column(BigInteger, comment="邀请人ID")
|
|
|
|
|
|
joined_at = Column(DateTime, server_default=func.now(), comment="加入时间")
|
|
|
|
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
|
|
return f"<ProjectMember(project_id={self.project_id}, user_id={self.user_id}, role='{self.role}')>"
|