49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
"""Block model: a hard deny that also hides content and prevents DMs."""
|
|
|
|
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 Block(Base):
|
|
__tablename__ = "blocks"
|
|
__table_args__ = (
|
|
UniqueConstraint(
|
|
"blocker_id",
|
|
"blocked_id",
|
|
name="uq_blocks_blocker_blocked",
|
|
),
|
|
CheckConstraint(
|
|
"blocker_id <> blocked_id",
|
|
name="ck_blocks_no_self",
|
|
),
|
|
)
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
blocker_id = Column(
|
|
Integer,
|
|
ForeignKey("users.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
index=True,
|
|
)
|
|
blocked_id = Column(
|
|
Integer,
|
|
ForeignKey("users.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
index=True,
|
|
)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
blocker = relationship(
|
|
"User",
|
|
foreign_keys=[blocker_id],
|
|
back_populates="blocks_given",
|
|
)
|
|
blocked = relationship(
|
|
"User",
|
|
foreign_keys=[blocked_id],
|
|
back_populates="blocks_received",
|
|
)
|