44 lines
1.9 KiB
Python
44 lines
1.9 KiB
Python
from sqlalchemy import Column, DateTime, String, ForeignKey, UniqueConstraint
|
|
from sqlalchemy.sql import func
|
|
from .base import AutoID, Base
|
|
|
|
class ProjectLike(Base, AutoID):
|
|
"""项目点赞表"""
|
|
__tablename__ = "project_likes"
|
|
|
|
user_id = Column(String(32), ForeignKey("users.id", ondelete="CASCADE"), index=True)
|
|
project_node_id = Column(String(32), ForeignKey("project_nodes.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"),)
|
|
|
|
|
|
class ProjectFavorite(Base, AutoID):
|
|
"""项目收藏表"""
|
|
__tablename__ = "project_favorites"
|
|
|
|
user_id = Column(String(32), ForeignKey("users.id", ondelete="CASCADE"), index=True)
|
|
project_node_id = Column(String(32), ForeignKey("project_nodes.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"),)
|
|
|
|
|
|
class ProjectShare(Base, AutoID):
|
|
"""项目转发/分享记录表"""
|
|
__tablename__ = "project_shares"
|
|
|
|
user_id = Column(String(32), ForeignKey("users.id", ondelete="CASCADE"), index=True)
|
|
project_node_id = Column(String(32), ForeignKey("project_nodes.id", ondelete="CASCADE"), index=True)
|
|
|
|
# 转发去向或渠道,例如 'internal' (转发到其他工作区), 'twitter', 'link' (复制链接)
|
|
share_target = Column(String, default="internal", nullable=False)
|
|
|
|
# 如果是转发到特定工作区,可以记录目标工作区 ID
|
|
target_workspace_id = Column(String(32), ForeignKey("workspaces.id", ondelete="SET NULL"), nullable=True)
|
|
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now()) |