feat: PocketVeto v1.0.0 — initial public release
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
This commit is contained in:
38
backend/app/models/__init__.py
Normal file
38
backend/app/models/__init__.py
Normal file
@@ -0,0 +1,38 @@
|
||||
from app.models.bill import Bill, BillAction, BillDocument, BillCosponsor
|
||||
from app.models.brief import BillBrief
|
||||
from app.models.collection import Collection, CollectionBill
|
||||
from app.models.follow import Follow
|
||||
from app.models.member import Member
|
||||
from app.models.member_interest import MemberTrendScore, MemberNewsArticle
|
||||
from app.models.news import NewsArticle
|
||||
from app.models.note import BillNote
|
||||
from app.models.notification import NotificationEvent
|
||||
from app.models.setting import AppSetting
|
||||
from app.models.trend import TrendScore
|
||||
from app.models.committee import Committee, CommitteeBill
|
||||
from app.models.user import User
|
||||
from app.models.vote import BillVote, MemberVotePosition
|
||||
|
||||
__all__ = [
|
||||
"Bill",
|
||||
"BillAction",
|
||||
"BillCosponsor",
|
||||
"BillDocument",
|
||||
"BillBrief",
|
||||
"BillNote",
|
||||
"BillVote",
|
||||
"Collection",
|
||||
"CollectionBill",
|
||||
"Follow",
|
||||
"Member",
|
||||
"MemberTrendScore",
|
||||
"MemberNewsArticle",
|
||||
"MemberVotePosition",
|
||||
"NewsArticle",
|
||||
"NotificationEvent",
|
||||
"AppSetting",
|
||||
"TrendScore",
|
||||
"Committee",
|
||||
"CommitteeBill",
|
||||
"User",
|
||||
]
|
||||
113
backend/app/models/bill.py
Normal file
113
backend/app/models/bill.py
Normal file
@@ -0,0 +1,113 @@
|
||||
from sqlalchemy import (
|
||||
Column, String, Integer, Date, DateTime, Text, ForeignKey, Index, UniqueConstraint
|
||||
)
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class Bill(Base):
|
||||
__tablename__ = "bills"
|
||||
|
||||
# Natural key: "{congress}-{bill_type_lower}-{bill_number}" e.g. "119-hr-1234"
|
||||
bill_id = Column(String, primary_key=True)
|
||||
congress_number = Column(Integer, nullable=False)
|
||||
bill_type = Column(String(10), nullable=False) # hr, s, hjres, sjres, hconres, sconres, hres, sres
|
||||
bill_number = Column(Integer, nullable=False)
|
||||
title = Column(Text)
|
||||
short_title = Column(Text)
|
||||
sponsor_id = Column(String, ForeignKey("members.bioguide_id"), nullable=True)
|
||||
introduced_date = Column(Date)
|
||||
latest_action_date = Column(Date)
|
||||
latest_action_text = Column(Text)
|
||||
status = Column(String(100))
|
||||
chamber = Column(String(50))
|
||||
congress_url = Column(String)
|
||||
govtrack_url = Column(String)
|
||||
|
||||
bill_category = Column(String(20), nullable=True) # substantive | commemorative | administrative
|
||||
cosponsors_fetched_at = Column(DateTime(timezone=True))
|
||||
|
||||
# Ingestion tracking
|
||||
last_checked_at = Column(DateTime(timezone=True))
|
||||
actions_fetched_at = Column(DateTime(timezone=True))
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
|
||||
sponsor = relationship("Member", back_populates="bills", foreign_keys=[sponsor_id])
|
||||
actions = relationship("BillAction", back_populates="bill", order_by="desc(BillAction.action_date)")
|
||||
documents = relationship("BillDocument", back_populates="bill")
|
||||
briefs = relationship("BillBrief", back_populates="bill", order_by="desc(BillBrief.created_at)")
|
||||
news_articles = relationship("NewsArticle", back_populates="bill", order_by="desc(NewsArticle.published_at)")
|
||||
trend_scores = relationship("TrendScore", back_populates="bill", order_by="desc(TrendScore.score_date)")
|
||||
committee_bills = relationship("CommitteeBill", back_populates="bill")
|
||||
notes = relationship("BillNote", back_populates="bill", cascade="all, delete-orphan")
|
||||
cosponsors = relationship("BillCosponsor", back_populates="bill", cascade="all, delete-orphan")
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_bills_congress_number", "congress_number"),
|
||||
Index("ix_bills_latest_action_date", "latest_action_date"),
|
||||
Index("ix_bills_introduced_date", "introduced_date"),
|
||||
Index("ix_bills_chamber", "chamber"),
|
||||
Index("ix_bills_sponsor_id", "sponsor_id"),
|
||||
)
|
||||
|
||||
|
||||
class BillAction(Base):
|
||||
__tablename__ = "bill_actions"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
bill_id = Column(String, ForeignKey("bills.bill_id", ondelete="CASCADE"), nullable=False)
|
||||
action_date = Column(Date)
|
||||
action_text = Column(Text)
|
||||
action_type = Column(String(100))
|
||||
chamber = Column(String(50))
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
bill = relationship("Bill", back_populates="actions")
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_bill_actions_bill_id", "bill_id"),
|
||||
Index("ix_bill_actions_action_date", "action_date"),
|
||||
)
|
||||
|
||||
|
||||
class BillDocument(Base):
|
||||
__tablename__ = "bill_documents"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
bill_id = Column(String, ForeignKey("bills.bill_id", ondelete="CASCADE"), nullable=False)
|
||||
doc_type = Column(String(50)) # bill_text | committee_report | amendment
|
||||
doc_version = Column(String(50)) # Introduced, Enrolled, etc.
|
||||
govinfo_url = Column(String)
|
||||
raw_text = Column(Text)
|
||||
fetched_at = Column(DateTime(timezone=True))
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
bill = relationship("Bill", back_populates="documents")
|
||||
briefs = relationship("BillBrief", back_populates="document")
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_bill_documents_bill_id", "bill_id"),
|
||||
)
|
||||
|
||||
|
||||
class BillCosponsor(Base):
|
||||
__tablename__ = "bill_cosponsors"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
bill_id = Column(String, ForeignKey("bills.bill_id", ondelete="CASCADE"), nullable=False)
|
||||
bioguide_id = Column(String, ForeignKey("members.bioguide_id", ondelete="SET NULL"), nullable=True)
|
||||
name = Column(String(200))
|
||||
party = Column(String(50))
|
||||
state = Column(String(10))
|
||||
sponsored_date = Column(Date, nullable=True)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
bill = relationship("Bill", back_populates="cosponsors")
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_bill_cosponsors_bill_id", "bill_id"),
|
||||
Index("ix_bill_cosponsors_bioguide_id", "bioguide_id"),
|
||||
)
|
||||
34
backend/app/models/brief.py
Normal file
34
backend/app/models/brief.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from sqlalchemy import Column, Integer, String, Text, ForeignKey, DateTime, Index
|
||||
from sqlalchemy.dialects import postgresql
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class BillBrief(Base):
|
||||
__tablename__ = "bill_briefs"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
bill_id = Column(String, ForeignKey("bills.bill_id", ondelete="CASCADE"), nullable=False)
|
||||
document_id = Column(Integer, ForeignKey("bill_documents.id", ondelete="SET NULL"), nullable=True)
|
||||
brief_type = Column(String(20), nullable=False, server_default="full") # full | amendment
|
||||
summary = Column(Text)
|
||||
key_points = Column(JSONB) # list[{text, citation, quote}]
|
||||
risks = Column(JSONB) # list[{text, citation, quote}]
|
||||
deadlines = Column(JSONB) # list[{date: str, description: str}]
|
||||
topic_tags = Column(JSONB) # list[str]
|
||||
llm_provider = Column(String(50))
|
||||
llm_model = Column(String(100))
|
||||
govinfo_url = Column(String, nullable=True)
|
||||
share_token = Column(postgresql.UUID(as_uuid=False), nullable=True, server_default=func.gen_random_uuid())
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
bill = relationship("Bill", back_populates="briefs")
|
||||
document = relationship("BillDocument", back_populates="briefs")
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_bill_briefs_bill_id", "bill_id"),
|
||||
Index("ix_bill_briefs_topic_tags", "topic_tags", postgresql_using="gin"),
|
||||
)
|
||||
51
backend/app/models/collection.py
Normal file
51
backend/app/models/collection.py
Normal file
@@ -0,0 +1,51 @@
|
||||
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"),
|
||||
)
|
||||
33
backend/app/models/committee.py
Normal file
33
backend/app/models/committee.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from sqlalchemy import Column, Integer, String, Date, ForeignKey, Index
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class Committee(Base):
|
||||
__tablename__ = "committees"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
committee_code = Column(String(20), unique=True, nullable=False)
|
||||
name = Column(String(500))
|
||||
chamber = Column(String(10))
|
||||
committee_type = Column(String(50)) # Standing, Select, Joint, etc.
|
||||
|
||||
committee_bills = relationship("CommitteeBill", back_populates="committee")
|
||||
|
||||
|
||||
class CommitteeBill(Base):
|
||||
__tablename__ = "committee_bills"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
committee_id = Column(Integer, ForeignKey("committees.id", ondelete="CASCADE"), nullable=False)
|
||||
bill_id = Column(String, ForeignKey("bills.bill_id", ondelete="CASCADE"), nullable=False)
|
||||
referral_date = Column(Date)
|
||||
|
||||
committee = relationship("Committee", back_populates="committee_bills")
|
||||
bill = relationship("Bill", back_populates="committee_bills")
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_committee_bills_bill_id", "bill_id"),
|
||||
Index("ix_committee_bills_committee_id", "committee_id"),
|
||||
)
|
||||
22
backend/app/models/follow.py
Normal file
22
backend/app/models/follow.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, UniqueConstraint
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class Follow(Base):
|
||||
__tablename__ = "follows"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
|
||||
follow_type = Column(String(20), nullable=False) # bill | member | topic
|
||||
follow_value = Column(String, nullable=False) # bill_id | bioguide_id | tag string
|
||||
follow_mode = Column(String(20), nullable=False, default="neutral") # neutral | pocket_veto | pocket_boost
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
user = relationship("User", back_populates="follows")
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint("user_id", "follow_type", "follow_value", name="uq_follows_user_type_value"),
|
||||
)
|
||||
45
backend/app/models/member.py
Normal file
45
backend/app/models/member.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import Column, Integer, JSON, String, DateTime
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class Member(Base):
|
||||
__tablename__ = "members"
|
||||
|
||||
bioguide_id = Column(String, primary_key=True)
|
||||
name = Column(String, nullable=False)
|
||||
first_name = Column(String)
|
||||
last_name = Column(String)
|
||||
party = Column(String(50))
|
||||
state = Column(String(50))
|
||||
chamber = Column(String(50))
|
||||
district = Column(String(50))
|
||||
photo_url = Column(String)
|
||||
official_url = Column(String)
|
||||
congress_url = Column(String)
|
||||
birth_year = Column(String(10))
|
||||
address = Column(String)
|
||||
phone = Column(String(50))
|
||||
terms_json = Column(JSON)
|
||||
leadership_json = Column(JSON)
|
||||
sponsored_count = Column(Integer)
|
||||
cosponsored_count = Column(Integer)
|
||||
effectiveness_score = Column(sa.Float, nullable=True)
|
||||
effectiveness_percentile = Column(sa.Float, nullable=True)
|
||||
effectiveness_tier = Column(String(20), nullable=True) # junior | mid | senior
|
||||
detail_fetched = Column(DateTime(timezone=True))
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
|
||||
bills = relationship("Bill", back_populates="sponsor", foreign_keys="Bill.sponsor_id")
|
||||
trend_scores = relationship(
|
||||
"MemberTrendScore", back_populates="member",
|
||||
order_by="desc(MemberTrendScore.score_date)", cascade="all, delete-orphan"
|
||||
)
|
||||
news_articles = relationship(
|
||||
"MemberNewsArticle", back_populates="member",
|
||||
order_by="desc(MemberNewsArticle.published_at)", cascade="all, delete-orphan"
|
||||
)
|
||||
47
backend/app/models/member_interest.py
Normal file
47
backend/app/models/member_interest.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from sqlalchemy import Column, Integer, String, Date, Float, Text, DateTime, ForeignKey, Index, UniqueConstraint
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class MemberTrendScore(Base):
|
||||
__tablename__ = "member_trend_scores"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
member_id = Column(String, ForeignKey("members.bioguide_id", ondelete="CASCADE"), nullable=False)
|
||||
score_date = Column(Date, nullable=False)
|
||||
newsapi_count = Column(Integer, default=0)
|
||||
gnews_count = Column(Integer, default=0)
|
||||
gtrends_score = Column(Float, default=0.0)
|
||||
composite_score = Column(Float, default=0.0)
|
||||
|
||||
member = relationship("Member", back_populates="trend_scores")
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint("member_id", "score_date", name="uq_member_trend_scores_member_date"),
|
||||
Index("ix_member_trend_scores_member_id", "member_id"),
|
||||
Index("ix_member_trend_scores_score_date", "score_date"),
|
||||
Index("ix_member_trend_scores_composite", "composite_score"),
|
||||
)
|
||||
|
||||
|
||||
class MemberNewsArticle(Base):
|
||||
__tablename__ = "member_news_articles"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
member_id = Column(String, ForeignKey("members.bioguide_id", ondelete="CASCADE"), nullable=False)
|
||||
source = Column(String(200))
|
||||
headline = Column(Text)
|
||||
url = Column(String)
|
||||
published_at = Column(DateTime(timezone=True))
|
||||
relevance_score = Column(Float, default=0.0)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
member = relationship("Member", back_populates="news_articles")
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint("member_id", "url", name="uq_member_news_member_url"),
|
||||
Index("ix_member_news_articles_member_id", "member_id"),
|
||||
Index("ix_member_news_articles_published_at", "published_at"),
|
||||
)
|
||||
26
backend/app/models/news.py
Normal file
26
backend/app/models/news.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from sqlalchemy import Column, Integer, String, Text, Float, DateTime, ForeignKey, Index, UniqueConstraint
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class NewsArticle(Base):
|
||||
__tablename__ = "news_articles"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
bill_id = Column(String, ForeignKey("bills.bill_id", ondelete="CASCADE"), nullable=False)
|
||||
source = Column(String(200))
|
||||
headline = Column(Text)
|
||||
url = Column(String)
|
||||
published_at = Column(DateTime(timezone=True))
|
||||
relevance_score = Column(Float, default=0.0)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
bill = relationship("Bill", back_populates="news_articles")
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint("bill_id", "url", name="uq_news_articles_bill_url"),
|
||||
Index("ix_news_articles_bill_id", "bill_id"),
|
||||
Index("ix_news_articles_published_at", "published_at"),
|
||||
)
|
||||
26
backend/app/models/note.py
Normal file
26
backend/app/models/note.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Index, Integer, String, Text, UniqueConstraint
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class BillNote(Base):
|
||||
__tablename__ = "bill_notes"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
|
||||
bill_id = Column(String, ForeignKey("bills.bill_id", ondelete="CASCADE"), nullable=False)
|
||||
content = Column(Text, nullable=False)
|
||||
pinned = Column(Boolean, nullable=False, default=False)
|
||||
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="bill_notes")
|
||||
bill = relationship("Bill", back_populates="notes")
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint("user_id", "bill_id", name="uq_bill_notes_user_bill"),
|
||||
Index("ix_bill_notes_user_id", "user_id"),
|
||||
Index("ix_bill_notes_bill_id", "bill_id"),
|
||||
)
|
||||
27
backend/app/models/notification.py
Normal file
27
backend/app/models/notification.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from sqlalchemy import Column, DateTime, ForeignKey, Index, Integer, String
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class NotificationEvent(Base):
|
||||
__tablename__ = "notification_events"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
|
||||
bill_id = Column(String, ForeignKey("bills.bill_id", ondelete="CASCADE"), nullable=False)
|
||||
# new_document | new_amendment | bill_updated
|
||||
event_type = Column(String(50), nullable=False)
|
||||
# {bill_title, bill_label, brief_summary, bill_url}
|
||||
payload = Column(JSONB)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
dispatched_at = Column(DateTime(timezone=True), nullable=True)
|
||||
|
||||
user = relationship("User", back_populates="notification_events")
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_notification_events_user_id", "user_id"),
|
||||
Index("ix_notification_events_dispatched_at", "dispatched_at"),
|
||||
)
|
||||
12
backend/app/models/setting.py
Normal file
12
backend/app/models/setting.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from sqlalchemy import Column, String, DateTime
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class AppSetting(Base):
|
||||
__tablename__ = "app_settings"
|
||||
|
||||
key = Column(String, primary_key=True)
|
||||
value = Column(String)
|
||||
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
25
backend/app/models/trend.py
Normal file
25
backend/app/models/trend.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from sqlalchemy import Column, Integer, String, Date, Float, ForeignKey, Index, UniqueConstraint
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class TrendScore(Base):
|
||||
__tablename__ = "trend_scores"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
bill_id = Column(String, ForeignKey("bills.bill_id", ondelete="CASCADE"), nullable=False)
|
||||
score_date = Column(Date, nullable=False)
|
||||
newsapi_count = Column(Integer, default=0)
|
||||
gnews_count = Column(Integer, default=0)
|
||||
gtrends_score = Column(Float, default=0.0)
|
||||
composite_score = Column(Float, default=0.0)
|
||||
|
||||
bill = relationship("Bill", back_populates="trend_scores")
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint("bill_id", "score_date", name="uq_trend_scores_bill_date"),
|
||||
Index("ix_trend_scores_bill_id", "bill_id"),
|
||||
Index("ix_trend_scores_score_date", "score_date"),
|
||||
Index("ix_trend_scores_composite", "composite_score"),
|
||||
)
|
||||
24
backend/app/models/user.py
Normal file
24
backend/app/models/user.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from sqlalchemy import Boolean, Column, DateTime, Integer, String
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "users"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
email = Column(String, unique=True, nullable=False, index=True)
|
||||
hashed_password = Column(String, nullable=False)
|
||||
is_admin = Column(Boolean, nullable=False, default=False)
|
||||
notification_prefs = Column(JSONB, nullable=False, default=dict)
|
||||
rss_token = Column(String, unique=True, nullable=True, index=True)
|
||||
email_unsubscribe_token = Column(String(64), unique=True, nullable=True, index=True)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
follows = relationship("Follow", back_populates="user", cascade="all, delete-orphan")
|
||||
notification_events = relationship("NotificationEvent", back_populates="user", cascade="all, delete-orphan")
|
||||
bill_notes = relationship("BillNote", back_populates="user", cascade="all, delete-orphan")
|
||||
collections = relationship("Collection", back_populates="user", cascade="all, delete-orphan")
|
||||
53
backend/app/models/vote.py
Normal file
53
backend/app/models/vote.py
Normal file
@@ -0,0 +1,53 @@
|
||||
from sqlalchemy import Column, Date, DateTime, ForeignKey, Index, Integer, String, Text, UniqueConstraint
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class BillVote(Base):
|
||||
__tablename__ = "bill_votes"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
bill_id = Column(String, ForeignKey("bills.bill_id", ondelete="CASCADE"), nullable=False)
|
||||
congress = Column(Integer, nullable=False)
|
||||
chamber = Column(String(50), nullable=False)
|
||||
session = Column(Integer, nullable=False)
|
||||
roll_number = Column(Integer, nullable=False)
|
||||
question = Column(Text)
|
||||
description = Column(Text)
|
||||
vote_date = Column(Date)
|
||||
yeas = Column(Integer)
|
||||
nays = Column(Integer)
|
||||
not_voting = Column(Integer)
|
||||
result = Column(String(200))
|
||||
source_url = Column(String)
|
||||
fetched_at = Column(DateTime(timezone=True))
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
positions = relationship("MemberVotePosition", back_populates="vote", cascade="all, delete-orphan")
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_bill_votes_bill_id", "bill_id"),
|
||||
UniqueConstraint("congress", "chamber", "session", "roll_number", name="uq_bill_votes_roll"),
|
||||
)
|
||||
|
||||
|
||||
class MemberVotePosition(Base):
|
||||
__tablename__ = "member_vote_positions"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
vote_id = Column(Integer, ForeignKey("bill_votes.id", ondelete="CASCADE"), nullable=False)
|
||||
bioguide_id = Column(String, ForeignKey("members.bioguide_id", ondelete="SET NULL"), nullable=True)
|
||||
member_name = Column(String(200))
|
||||
party = Column(String(50))
|
||||
state = Column(String(10))
|
||||
position = Column(String(50), nullable=False)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
vote = relationship("BillVote", back_populates="positions")
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_member_vote_positions_vote_id", "vote_id"),
|
||||
Index("ix_member_vote_positions_bioguide_id", "bioguide_id"),
|
||||
)
|
||||
Reference in New Issue
Block a user