44 lines
1.6 KiB
Python
44 lines
1.6 KiB
Python
import uuid
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import String, Boolean, Integer, Float, ForeignKey, Index, func, Text
|
|
from sqlalchemy import Uuid, JSON
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class CitationRecord(Base):
|
|
__tablename__ = "citation_records"
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
|
Uuid(as_uuid=True),
|
|
primary_key=True,
|
|
default=uuid.uuid4,
|
|
)
|
|
query_id: Mapped[uuid.UUID] = mapped_column(
|
|
Uuid(as_uuid=True),
|
|
ForeignKey("queries.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
)
|
|
platform: Mapped[str] = mapped_column(String(50), nullable=False)
|
|
cited: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
|
citation_position: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
citation_text: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
competitor_brands: Mapped[list] = mapped_column(JSON, default=list)
|
|
raw_response: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
confidence: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
match_type: Mapped[str | None] = mapped_column(String(20), nullable=True)
|
|
queried_at: Mapped[datetime] = mapped_column(
|
|
server_default=func.now(),
|
|
nullable=False,
|
|
)
|
|
|
|
query: Mapped["Query"] = relationship("Query", back_populates="citation_records")
|
|
|
|
__table_args__ = (
|
|
Index("idx_citation_records_query_id", "query_id"),
|
|
Index("idx_citation_records_queried_at", "queried_at"),
|
|
Index("idx_citation_records_platform", "platform"),
|
|
)
|