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>
24 lines
940 B
Python
24 lines
940 B
Python
from datetime import datetime, timezone
|
|
from sqlalchemy import Integer, Float, DateTime, ForeignKey, Index
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from backend.models.base import Base
|
|
|
|
|
|
class MetricSnapshot(Base):
|
|
__tablename__ = "metric_snapshots"
|
|
__table_args__ = (
|
|
Index("ix_metric_snapshots_post_snapshot", "post_id", "snapshot_at"),
|
|
)
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
post_id: Mapped[int] = mapped_column(ForeignKey("posts.id"), nullable=False)
|
|
score: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
num_comments: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
upvote_ratio: Mapped[float | None] = mapped_column(Float)
|
|
snapshot_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)
|
|
)
|
|
|
|
post: Mapped["Post"] = relationship(back_populates="metric_snapshots") # noqa: F821
|