27 lines
840 B
Python
27 lines
840 B
Python
from sqlalchemy import Column, DateTime, ForeignKey, Index, Integer, String
|
|
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
|
|
)
|
|
user_id = Column(
|
|
Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=True
|
|
)
|
|
anonymous_token = Column(String(255), nullable=True)
|
|
visited_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
__table_args__ = (
|
|
Index("ix_world_visits_world_id_visited_at", "world_id", "visited_at"),
|
|
)
|
|
|
|
world = relationship("World", back_populates="visits")
|
|
user = relationship("User")
|