WIP checkpoint: Friends/follow/block models + Alembic migration
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
"""Follow model: a one-way relationship requiring no approval."""
|
||||
|
||||
from sqlalchemy import CheckConstraint, Column, DateTime, ForeignKey, Integer, UniqueConstraint
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class Follow(Base):
|
||||
__tablename__ = "follows"
|
||||
__table_args__ = (
|
||||
UniqueConstraint(
|
||||
"follower_id",
|
||||
"followed_id",
|
||||
name="uq_follows_follower_followed",
|
||||
),
|
||||
CheckConstraint(
|
||||
"follower_id <> followed_id",
|
||||
name="ck_follows_no_self",
|
||||
),
|
||||
)
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
follower_id = Column(
|
||||
Integer,
|
||||
ForeignKey("users.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
followed_id = Column(
|
||||
Integer,
|
||||
ForeignKey("users.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
follower = relationship(
|
||||
"User",
|
||||
foreign_keys=[follower_id],
|
||||
back_populates="follows_given",
|
||||
)
|
||||
followed = relationship(
|
||||
"User",
|
||||
foreign_keys=[followed_id],
|
||||
back_populates="followers",
|
||||
)
|
||||
Reference in New Issue
Block a user