Skip to content

关系表

用户收藏表(tb_user_collection),评论点赞(CommentLikeORM),用户相互关注(tb_user_follows )

文章收藏表

python
# 用户收藏表,建立用户与其收藏文章多对多的关系
tb_user_collection = db.Table(
    "forum_user_collections",
    sa.Column(
        "user_id",
        sa.Integer,
        sa.ForeignKey("forum_user.id"),
        primary_key=True,
        comment="文章编号",
    ),
    sa.Column(
        "article_id",
        sa.Integer,
        sa.ForeignKey("forum_article.id"),
        primary_key=True,
        comment="分类编号",
    ),
    sa.Column("create_time", sa.DateTime, default=datetime.utcnow, comment="收藏创建时间"),
)

用户关注表

python
# 用户关注表,记录用户关注的信息
tb_user_follows = db.Table(
    "forum_user_fans",
    db.Column(
        "follower_id",
        db.Integer,
        db.ForeignKey("forum_user.id"),
        primary_key=True,
        comment="粉丝 id",
    ),
    db.Column(
        "followed_id",
        db.Integer,
        db.ForeignKey("forum_user.id"),
        primary_key=True,
        comment="被关注人的 id",
    ),
)

评论点赞表

python
class CommentLikeORM(BaseORM):
    """评论点赞"""

    __tablename__ = "forum_comment_like"

    comment_id = sa.Column(
        "comment_id",
        sa.Integer,
        sa.ForeignKey("forum_comment.id"),
        primary_key=True,
        comment="评论编号",
    )
    user_id = sa.Column(
        "user_id",
        sa.Integer,
        sa.ForeignKey("forum_user.id"),
        primary_key=True,
        comment="用户编号",
    )

    create_at = sa.Column(sa.DateTime, default=datetime.utcnow, comment="创建时间")
    update_at = sa.Column(
        sa.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, comment="更新时间"
    )