Files
reddit-bot/backend/models/comment.py
dat972 bc2203524f Add Reddit monitoring bot — backend, frontend, and Docker config
Python/FastAPI backend with PostgreSQL for collecting Reddit data via
public .json endpoints. React/Vite dashboard for analytics. Docker Compose
setup with API and worker services connecting to shared PostgreSQL.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 19:29:58 -05:00

35 lines
1.5 KiB
Python

from datetime import datetime, timezone
from sqlalchemy import String, Integer, DateTime, ForeignKey
from sqlalchemy.orm import Mapped, mapped_column, relationship
from backend.models.base import Base
class Comment(Base):
__tablename__ = "comments"
id: Mapped[int] = mapped_column(primary_key=True)
reddit_id: Mapped[str] = mapped_column(String(20), unique=True, nullable=False)
post_id: Mapped[int] = mapped_column(ForeignKey("posts.id"), nullable=False, index=True)
parent_comment_id: Mapped[int | None] = mapped_column(
ForeignKey("comments.id"), index=True
)
author_id: Mapped[int | None] = mapped_column(ForeignKey("authors.id"), index=True)
body: Mapped[str] = mapped_column(nullable=False)
score: Mapped[int] = mapped_column(Integer, default=0)
created_utc: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False)
collected_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)
)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
default=lambda: datetime.now(timezone.utc),
onupdate=lambda: datetime.now(timezone.utc),
)
post: Mapped["Post"] = relationship(back_populates="comments") # noqa: F821
author: Mapped["Author | None"] = relationship(back_populates="comments") # noqa: F821
parent_comment: Mapped["Comment | None"] = relationship(
remote_side="Comment.id", foreign_keys=[parent_comment_id]
)