57 lines
2.3 KiB
Python
57 lines
2.3 KiB
Python
"""互动域:comments / likes / favorites"""
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import DateTime, Index, SmallInteger, String, func
|
|
from sqlalchemy.dialects.mysql import BIGINT
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.models.base import Base
|
|
|
|
|
|
class Comment(Base):
|
|
__tablename__ = "comments"
|
|
|
|
id: Mapped[int] = mapped_column(BIGINT(unsigned=True), primary_key=True, autoincrement=True)
|
|
video_id: Mapped[int] = mapped_column(BIGINT(unsigned=True))
|
|
user_id: Mapped[int] = mapped_column(BIGINT(unsigned=True))
|
|
parent_id: Mapped[int] = mapped_column(BIGINT(unsigned=True), default=0, comment="0=一级评论")
|
|
reply_to_user_id: Mapped[int | None] = mapped_column(BIGINT(unsigned=True))
|
|
content: Mapped[str] = mapped_column(String(500))
|
|
like_count: Mapped[int] = mapped_column(default=0)
|
|
status: Mapped[int] = mapped_column(SmallInteger, default=1, comment="1正常 2已删除 3审核中")
|
|
reward_counted: Mapped[int] = mapped_column(SmallInteger, default=0, comment="是否已计入评论奖励进度")
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
|
|
|
__table_args__ = (
|
|
Index("idx_video", "video_id", "status", "created_at"),
|
|
Index("idx_user_video", "user_id", "video_id"),
|
|
)
|
|
|
|
|
|
class Like(Base):
|
|
__tablename__ = "likes"
|
|
|
|
id: Mapped[int] = mapped_column(BIGINT(unsigned=True), primary_key=True, autoincrement=True)
|
|
user_id: Mapped[int] = mapped_column(BIGINT(unsigned=True))
|
|
video_id: Mapped[int] = mapped_column(BIGINT(unsigned=True))
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
|
|
|
__table_args__ = (
|
|
Index("uk_user_video", "user_id", "video_id", unique=True),
|
|
Index("idx_video", "video_id"),
|
|
)
|
|
|
|
|
|
class Favorite(Base):
|
|
__tablename__ = "favorites"
|
|
|
|
id: Mapped[int] = mapped_column(BIGINT(unsigned=True), primary_key=True, autoincrement=True)
|
|
user_id: Mapped[int] = mapped_column(BIGINT(unsigned=True))
|
|
video_id: Mapped[int] = mapped_column(BIGINT(unsigned=True))
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
|
|
|
__table_args__ = (
|
|
Index("uk_user_video", "user_id", "video_id", unique=True),
|
|
Index("idx_video", "video_id"),
|
|
)
|