table follow requires the id length of user
This commit is contained in:
+17
-2
@@ -1,13 +1,28 @@
|
||||
from typing import TYPE_CHECKING
|
||||
from sqlalchemy import Column, DateTime, String, ForeignKey, UniqueConstraint
|
||||
from sqlalchemy.sql import func
|
||||
from .base import AutoID, Base
|
||||
|
||||
# 只有在静态检查时才导入
|
||||
# 运行阶段这段代码会被跳过,彻底避免循环导入
|
||||
# 不确定是否用得上,但感觉这是个好习惯,尤其在模型之间有外键关系时
|
||||
if TYPE_CHECKING:
|
||||
from .user import User
|
||||
|
||||
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)
|
||||
follower_id = Column(
|
||||
String(User.id_length()),
|
||||
ForeignKey("users.id", ondelete="CASCADE"),
|
||||
index=True
|
||||
)
|
||||
followee_id = Column(
|
||||
String(User.id_length()),
|
||||
ForeignKey("users.id", ondelete="CASCADE"),
|
||||
index=True
|
||||
)
|
||||
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user