25 lines
756 B
Python
25 lines
756 B
Python
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(AutoID.id_length()),
|
|
ForeignKey("users.id", ondelete="CASCADE"),
|
|
index=True
|
|
)
|
|
followee_id = Column(
|
|
String(AutoID.id_length()),
|
|
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"),
|
|
) |