Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"""Update locations expanded view

Revision ID: d4c63e23d3f0
Revises: b9317c6836e7
Create Date: 2025-09-26 17:51:41.214287

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import ENUM

from src.util.alembic_helpers import id_column, location_id_column, created_at_column

# revision identifiers, used by Alembic.
revision: str = 'd4c63e23d3f0'
down_revision: Union[str, None] = 'b9317c6836e7'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def _update_locations_expanded_view():
op.execute(
"""
CREATE OR REPLACE VIEW locations_expanded as
SELECT locations.id,
locations.type,
us_states.state_name,
us_states.state_iso,
counties.name AS county_name,
counties.fips AS county_fips,
localities.name AS locality_name,
localities.id AS locality_id,
us_states.id AS state_id,
counties.id AS county_id,
CASE
WHEN locations.type = 'Locality'::location_type THEN localities.name
WHEN locations.type = 'County'::location_type THEN counties.name::character varying
WHEN locations.type = 'State'::location_type THEN us_states.state_name::character varying
ELSE NULL::character varying
END AS display_name,
CASE
WHEN locations.type = 'Locality'::location_type THEN concat(localities.name, ', ', counties.name,
', ',
us_states.state_name)::character varying
WHEN locations.type = 'County'::location_type
THEN concat(counties.name, ', ', us_states.state_name)::character varying
WHEN locations.type = 'State'::location_type THEN us_states.state_name::character varying
WHEN locations.type = 'National'::location_type THEN 'United States'
ELSE NULL::character varying
END AS full_display_name
FROM locations
LEFT JOIN us_states
ON locations.state_id = us_states.id
LEFT JOIN counties
ON locations.county_id = counties.id
LEFT JOIN localities
ON locations.locality_id = localities.id
"""
)


def _create_new_agency_suggestion_table():
op.create_table(
'new_agency_suggestions',
id_column(),
location_id_column(),
sa.Column('name', sa.String()),
sa.Column('jurisdiction_type', ENUM(name='jurisdiction_type_enum', create_type=False), nullable=True),
sa.Column('agency_type', ENUM(name='agency_type_enum', create_type=False), nullable=True),
created_at_column()
)


def upgrade() -> None:

Check warning on line 76 in alembic/versions/2025_09_26_1751-d4c63e23d3f0_update_locations_expanded_view.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] alembic/versions/2025_09_26_1751-d4c63e23d3f0_update_locations_expanded_view.py#L76 <103>

Missing docstring in public function
Raw output
./alembic/versions/2025_09_26_1751-d4c63e23d3f0_update_locations_expanded_view.py:76:1: D103 Missing docstring in public function
_update_locations_expanded_view()
_create_new_agency_suggestion_table()




def downgrade() -> None:

Check warning on line 83 in alembic/versions/2025_09_26_1751-d4c63e23d3f0_update_locations_expanded_view.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] alembic/versions/2025_09_26_1751-d4c63e23d3f0_update_locations_expanded_view.py#L83 <103>

Missing docstring in public function
Raw output
./alembic/versions/2025_09_26_1751-d4c63e23d3f0_update_locations_expanded_view.py:83:1: D103 Missing docstring in public function

Check failure on line 83 in alembic/versions/2025_09_26_1751-d4c63e23d3f0_update_locations_expanded_view.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] alembic/versions/2025_09_26_1751-d4c63e23d3f0_update_locations_expanded_view.py#L83 <303>

too many blank lines (4)
Raw output
./alembic/versions/2025_09_26_1751-d4c63e23d3f0_update_locations_expanded_view.py:83:1: E303 too many blank lines (4)
pass
2 changes: 1 addition & 1 deletion src/api/endpoints/search/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def search_agency(
access_info: AccessInfo = Depends(get_access_info),
async_core: AsyncCore = Depends(get_async_core),
) -> list[AgencySearchResponse]:
if query is None and location_id is None:
if query is None and location_id is None and jurisdiction_type is None:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="At least one of query or location_id must be provided"
Expand Down