28 lines
971 B
Python
28 lines
971 B
Python
"""World visit tracking model for discovery analytics.
|
|
|
|
docs/planning/discovery.md (task b377353b8167).
|
|
"""
|
|
|
|
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Index
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class WorldVisit(Base):
|
|
__tablename__ = "world_visits"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
world_id = Column(Integer, ForeignKey("worlds.id", ondelete="CASCADE"), nullable=False, index=True)
|
|
user_id = Column(Integer, ForeignKey("users.id", ondelete="SET NULL"), nullable=True, index=True)
|
|
anonymous_token = Column(String(255), nullable=True)
|
|
visited_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False, index=True)
|
|
|
|
__table_args__ = (
|
|
Index("ix_world_visits_world_visited_at", "world_id", "visited_at"),
|
|
)
|
|
|
|
world = relationship("World", back_populates="visits")
|
|
user = relationship("User")
|