Log searches (article/category) and message-generation events to a new interaction_log table, capturing IP address and User-Agent. Also apply NOT NULL constraints to Contribution, SentMessage, FlickrUpload, and ThumbnailCache fields that are always populated, and remove stale continue_token references from category.html. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
111 lines
3.2 KiB
Python
111 lines
3.2 KiB
Python
"""SQLAlchemy models for flickr-mail."""
|
|
|
|
from sqlalchemy import ForeignKey, Index, Text
|
|
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
|
|
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
|
|
class Contribution(Base):
|
|
__tablename__ = "contributions"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
userid: Mapped[int]
|
|
user: Mapped[str]
|
|
pageid: Mapped[int]
|
|
revid: Mapped[int] = mapped_column(unique=True)
|
|
parentid: Mapped[int]
|
|
ns: Mapped[int]
|
|
title: Mapped[str]
|
|
timestamp: Mapped[str]
|
|
minor: Mapped[str | None]
|
|
top: Mapped[str | None]
|
|
comment: Mapped[str] = mapped_column(Text)
|
|
size: Mapped[int]
|
|
sizediff: Mapped[int]
|
|
tags: Mapped[str] = mapped_column(Text) # JSON array stored as text
|
|
|
|
__table_args__ = (
|
|
Index("ix_contributions_timestamp", "timestamp"),
|
|
Index("ix_contributions_pageid", "pageid"),
|
|
)
|
|
|
|
|
|
class SentMessage(Base):
|
|
__tablename__ = "sent_messages"
|
|
|
|
message_id: Mapped[str] = mapped_column(primary_key=True)
|
|
subject: Mapped[str]
|
|
url: Mapped[str]
|
|
recipient: Mapped[str]
|
|
date: Mapped[str]
|
|
body: Mapped[str] = mapped_column(Text)
|
|
body_html: Mapped[str] = mapped_column(Text)
|
|
flickr_url: Mapped[str]
|
|
normalized_flickr_url: Mapped[str]
|
|
wikipedia_url: Mapped[str]
|
|
creator_profile_url: Mapped[str]
|
|
|
|
flickr_uploads: Mapped[list["FlickrUpload"]] = relationship(
|
|
back_populates="sent_message"
|
|
)
|
|
|
|
__table_args__ = (
|
|
Index("ix_sent_messages_recipient", "recipient"),
|
|
Index("ix_sent_messages_normalized_flickr_url", "normalized_flickr_url"),
|
|
)
|
|
|
|
|
|
class FlickrUpload(Base):
|
|
__tablename__ = "flickr_uploads"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
pageid: Mapped[int]
|
|
revid: Mapped[int]
|
|
title: Mapped[str]
|
|
timestamp: Mapped[str]
|
|
flickr_url: Mapped[str]
|
|
normalized_flickr_url: Mapped[str]
|
|
creator: Mapped[str | None]
|
|
wikipedia_url: Mapped[str]
|
|
creator_profile_url: Mapped[str]
|
|
sent_message_id: Mapped[str | None] = mapped_column(
|
|
ForeignKey("sent_messages.message_id")
|
|
)
|
|
|
|
sent_message: Mapped[SentMessage | None] = relationship(
|
|
back_populates="flickr_uploads"
|
|
)
|
|
|
|
__table_args__ = (
|
|
Index("ix_flickr_uploads_normalized_flickr_url", "normalized_flickr_url"),
|
|
Index("ix_flickr_uploads_timestamp", "timestamp"),
|
|
)
|
|
|
|
|
|
class ThumbnailCache(Base):
|
|
__tablename__ = "thumbnail_cache"
|
|
|
|
title: Mapped[str] = mapped_column(primary_key=True)
|
|
thumb_url: Mapped[str]
|
|
fetched_at: Mapped[int] # Unix timestamp
|
|
|
|
|
|
class InteractionLog(Base):
|
|
__tablename__ = "interaction_log"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
timestamp: Mapped[int] # Unix timestamp
|
|
interaction_type: Mapped[str] # "search_article", "search_category", "generate_message"
|
|
ip_address: Mapped[str | None]
|
|
user_agent: Mapped[str | None] = mapped_column(Text)
|
|
query: Mapped[str | None] # search term or category name
|
|
flickr_url: Mapped[str | None]
|
|
wikipedia_url: Mapped[str | None]
|
|
|
|
__table_args__ = (
|
|
Index("ix_interaction_log_timestamp", "timestamp"),
|
|
Index("ix_interaction_log_type", "interaction_type"),
|
|
)
|