""" 메모 모델 """ from sqlalchemy import Column, String, DateTime, Text, Boolean, ForeignKey from sqlalchemy.dialects.postgresql import UUID, ARRAY from sqlalchemy.orm import relationship from sqlalchemy.sql import func import uuid from ..core.database import Base class Note(Base): """메모 테이블 (하이라이트와 1:N 관계)""" __tablename__ = "notes" id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) # 연결 정보 highlight_id = Column(UUID(as_uuid=True), ForeignKey("highlights.id"), nullable=False) # 메모 내용 content = Column(Text, nullable=False) is_private = Column(Boolean, default=True) # 개인 메모 여부 # 태그 (메모 분류용) tags = Column(ARRAY(String), nullable=True) # ["중요", "질문", "아이디어"] # 메타데이터 created_at = Column(DateTime(timezone=True), server_default=func.now()) updated_at = Column(DateTime(timezone=True), onupdate=func.now()) # 관계 highlight = relationship("Highlight", back_populates="notes") @property def user_id(self): """하이라이트를 통해 사용자 ID 가져오기""" return self.highlight.user_id if self.highlight else None @property def document_id(self): """하이라이트를 통해 문서 ID 가져오기""" return self.highlight.document_id if self.highlight else None def __repr__(self): return f""