ran treefmt

This commit is contained in:
2026-03-28 14:07:27 -04:00
parent dae38ffd9b
commit c5babf8bad
3 changed files with 4 additions and 18 deletions

View File

@@ -46,12 +46,7 @@ ALREADY_ATTACHED_QUERY = text("""
def upgrade() -> None: def upgrade() -> None:
"""Attach all weekly partition tables to the posts parent table.""" """Attach all weekly partition tables to the posts parent table."""
connection = op.get_bind() connection = op.get_bind()
already_attached = { already_attached = {row[0] for row in connection.execute(ALREADY_ATTACHED_QUERY, {"parent": f"{schema}.posts"})}
row[0]
for row in connection.execute(
ALREADY_ATTACHED_QUERY, {"parent": f"{schema}.posts"}
)
}
for year in range(PARTITION_START_YEAR, PARTITION_END_YEAR + 1): for year in range(PARTITION_START_YEAR, PARTITION_END_YEAR + 1):
for week in range(1, iso_weeks_in_year(year) + 1): for week in range(1, iso_weeks_in_year(year) + 1):
@@ -74,7 +69,4 @@ def downgrade() -> None:
for year in range(PARTITION_START_YEAR, PARTITION_END_YEAR + 1): for year in range(PARTITION_START_YEAR, PARTITION_END_YEAR + 1):
for week in range(1, iso_weeks_in_year(year) + 1): for week in range(1, iso_weeks_in_year(year) + 1):
table_name = f"posts_{year}_{week:02d}" table_name = f"posts_{year}_{week:02d}"
op.execute( op.execute(f"ALTER TABLE {schema}.posts DETACH PARTITION {schema}.{table_name}")
f"ALTER TABLE {schema}.posts "
f"DETACH PARTITION {schema}.{table_name}"
)

View File

@@ -3,7 +3,6 @@
from __future__ import annotations from __future__ import annotations
import logging import logging
import re
import sys import sys
from pathlib import Path from pathlib import Path
from typing import TYPE_CHECKING, Any, Literal from typing import TYPE_CHECKING, Any, Literal

View File

@@ -252,9 +252,7 @@ def ingest_votes(engine: Engine, congress_dirs: list[Path]) -> None:
logger.info("Loaded %d bills into lookup map", len(bill_map)) logger.info("Loaded %d bills into lookup map", len(bill_map))
existing_votes = { existing_votes = {
(row.congress, row.chamber, row.session, row.number) (row.congress, row.chamber, row.session, row.number)
for row in session.execute( for row in session.execute(select(Vote.congress, Vote.chamber, Vote.session, Vote.number)).all()
select(Vote.congress, Vote.chamber, Vote.session, Vote.number)
).all()
} }
logger.info("Found %d existing votes in DB", len(existing_votes)) logger.info("Found %d existing votes in DB", len(existing_votes))
@@ -281,10 +279,7 @@ def ingest_votes(engine: Engine, congress_dirs: list[Path]) -> None:
def _build_legislator_map(session: Session) -> dict[str, int]: def _build_legislator_map(session: Session) -> dict[str, int]:
"""Build a mapping of bioguide_id -> legislator.id.""" """Build a mapping of bioguide_id -> legislator.id."""
return { return {row.bioguide_id: row.id for row in session.execute(select(Legislator.bioguide_id, Legislator.id)).all()}
row.bioguide_id: row.id
for row in session.execute(select(Legislator.bioguide_id, Legislator.id)).all()
}
def _build_bill_map(session: Session) -> dict[tuple[int, str, int], int]: def _build_bill_map(session: Session) -> dict[tuple[int, str, int], int]: