create follow table: user follows user
This commit is contained in:
@@ -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"),
|
||||
)
|
||||
Reference in New Issue
Block a user