create follow table: user follows user

This commit is contained in:
2026-05-17 22:35:52 +08:00
parent a4c30b0557
commit 7a583c0486
+17
View File
@@ -0,0 +1,17 @@
from sqlalchemy import Column, DateTime, String, ForeignKey, UniqueConstraint
from sqlalchemy.sql import func
from .base import AutoID, Base
class Follow(Base, AutoID):
"""用户关注关系表"""
__tablename__ = "follows"
follower_id = Column(String(32), ForeignKey("users.id", ondelete="CASCADE"), index=True)
followee_id = Column(String(32), ForeignKey("users.id", ondelete="CASCADE"), index=True)
created_at = Column(DateTime(timezone=True), server_default=func.now())
# 联合唯一索引:防止重复关注
__table_args__ = (
UniqueConstraint("follower_id", "followee_id", name="uq_follower_followee"),
)