15dac50367
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
37 lines
1.4 KiB
Python
37 lines
1.4 KiB
Python
"""Post — provenance anchor for content downloaded from a Source.
|
|
|
|
A Post is one creator post; it may contain many images/videos.
|
|
"""
|
|
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import JSON, DateTime, ForeignKey, Integer, String, Text, UniqueConstraint, func
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from .base import Base
|
|
|
|
|
|
class Post(Base):
|
|
__tablename__ = "post"
|
|
__table_args__ = (
|
|
UniqueConstraint("source_id", "external_post_id", name="uq_post_source_external_id"),
|
|
)
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
source_id: Mapped[int] = mapped_column(
|
|
ForeignKey("source.id", ondelete="CASCADE"), nullable=False, index=True
|
|
)
|
|
external_post_id: Mapped[str] = mapped_column(String(128), nullable=False)
|
|
post_url: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
post_title: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
post_date: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
|
|
|
raw_metadata: Mapped[dict | None] = mapped_column(JSON, nullable=True)
|
|
|
|
description: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
attachment_count: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
|
|
downloaded_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), nullable=False, server_default=func.now()
|
|
)
|