import uuid from sqlalchemy import Column, String, Text, Boolean, DateTime, ForeignKey from sqlalchemy.sql import func from sqlalchemy.orm import relationship from app.core.database import Base class Comment(Base): __tablename__ = "pjctrl_comments" id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4())) task_id = Column(String(36), ForeignKey("pjctrl_tasks.id", ondelete="CASCADE"), nullable=False) parent_comment_id = Column(String(36), ForeignKey("pjctrl_comments.id", ondelete="CASCADE"), nullable=True) author_id = Column(String(36), ForeignKey("pjctrl_users.id"), nullable=False) content = Column(Text, nullable=False) is_edited = Column(Boolean, default=False, nullable=False) is_deleted = Column(Boolean, default=False, nullable=False) created_at = Column(DateTime, server_default=func.now(), nullable=False) updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), nullable=False) # Relationships task = relationship("Task", back_populates="comments") author = relationship("User", back_populates="comments") parent_comment = relationship("Comment", remote_side=[id], back_populates="replies") replies = relationship("Comment", back_populates="parent_comment", cascade="all, delete-orphan") mentions = relationship("Mention", back_populates="comment", cascade="all, delete-orphan")