api / app /models /play_history.py
hanbinsite's picture
feat: complete core feature improvements
bf34e9d
Raw History Blame Contribute Delete
1.4 kB
from datetime import datetime
from sqlalchemy import DateTime, Index, Integer, String, func
from sqlalchemy.orm import Mapped, mapped_column
from app.database import Base
class PlayHistory(Base):
__tablename__ = "play_history"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
user_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="用户ID")
vod_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="影片ID")
source_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="资源站ID")
episode: Mapped[str | None] = mapped_column(String(50), comment="集名")
play_url: Mapped[str] = mapped_column(String, nullable=False, comment="播放地址")
progress: Mapped[int] = mapped_column(Integer, default=0, comment="播放进度(秒)")
duration: Mapped[int] = mapped_column(Integer, default=0, comment="总时长(秒)")
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now())
__table_args__ = (
# 历史列表:按用户 + 时间倒序
Index("ix_play_history_user_updated", "user_id", "updated_at"),
# 更新播放进度:user_id + vod_id 定位记录
Index("ix_play_history_user_vod", "user_id", "vod_id"),
)