Self-hosted US Congress monitoring platform with AI policy briefs, bill/member/topic follows, ntfy + RSS + email notifications, alignment scoring, collections, and draft-letter generator. Authored by: Jack Levy
52 lines
2.2 KiB
Python
52 lines
2.2 KiB
Python
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Index, Integer, String, UniqueConstraint
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class Collection(Base):
|
|
__tablename__ = "collections"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
|
|
name = Column(String(100), nullable=False)
|
|
slug = Column(String(120), nullable=False)
|
|
is_public = Column(Boolean, nullable=False, default=False, server_default="false")
|
|
share_token = Column(UUID(as_uuid=False), nullable=False, server_default=func.gen_random_uuid())
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
|
|
|
user = relationship("User", back_populates="collections")
|
|
collection_bills = relationship(
|
|
"CollectionBill",
|
|
cascade="all, delete-orphan",
|
|
order_by="CollectionBill.added_at.desc()",
|
|
)
|
|
|
|
__table_args__ = (
|
|
UniqueConstraint("user_id", "slug", name="uq_collections_user_slug"),
|
|
UniqueConstraint("share_token", name="uq_collections_share_token"),
|
|
Index("ix_collections_user_id", "user_id"),
|
|
Index("ix_collections_share_token", "share_token"),
|
|
)
|
|
|
|
|
|
class CollectionBill(Base):
|
|
__tablename__ = "collection_bills"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
collection_id = Column(Integer, ForeignKey("collections.id", ondelete="CASCADE"), nullable=False)
|
|
bill_id = Column(String, ForeignKey("bills.bill_id", ondelete="CASCADE"), nullable=False)
|
|
added_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
collection = relationship("Collection", back_populates="collection_bills")
|
|
bill = relationship("Bill")
|
|
|
|
__table_args__ = (
|
|
UniqueConstraint("collection_id", "bill_id", name="uq_collection_bills_collection_bill"),
|
|
Index("ix_collection_bills_collection_id", "collection_id"),
|
|
Index("ix_collection_bills_bill_id", "bill_id"),
|
|
)
|