Files

31 lines
1.0 KiB
Python
Raw Permalink Normal View History

2026-06-09 23:30:55 +00:00
from datetime import datetime
from sqlalchemy import String, DateTime, ForeignKey, func, Index
from sqlalchemy.orm import Mapped, mapped_column, relationship
2026-06-09 23:30:55 +00:00
from app.database import Base
2026-06-09 23:30:55 +00:00
class Comment(Base):
__tablename__ = "comments"
id: Mapped[int] = mapped_column(primary_key=True)
record_id: Mapped[int] = mapped_column(
ForeignKey("records.id", ondelete="CASCADE"), nullable=False, index=True
)
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=True)
content: Mapped[str] = mapped_column(String, nullable=False)
created_at: Mapped[datetime] = mapped_column(DateTime, default=func.now())
updated_at: Mapped[datetime] = mapped_column(
DateTime, default=func.now(), onupdate=func.now()
)
# Relationships
record = relationship("Record", back_populates="comments")
user = relationship("User", back_populates="comments")
__table_args__ = (Index("idx_comments_record", "record_id"),)
2026-06-09 23:30:55 +00:00
def __repr__(self):
return f"<Comment(id={self.id}, record_id={self.record_id})>"