From 68b15400b01e3828b7ba8d306d887ab4602e7172 Mon Sep 17 00:00:00 2001 From: Tudor Date: Tue, 24 Mar 2026 20:57:11 +0000 Subject: [PATCH] feat(ks2): enable geocoding during reimport Add geocode query param to /api/admin/reimport-ks2 (defaults true). ks2.py passes ?geocode=true so postcodes are resolved to lat/lng in the same migration pass. Co-Authored-By: Claude Sonnet 4.6 --- backend/app.py | 4 +++- integrator/scripts/sources/ks2.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/backend/app.py b/backend/app.py index 3c3d264..2f6536c 100644 --- a/backend/app.py +++ b/backend/app.py @@ -639,16 +639,18 @@ async def reload_data( @limiter.limit("2/minute") async def reimport_ks2( request: Request, + geocode: bool = True, _: bool = Depends(verify_admin_api_key) ): """ Re-run the full KS2 CSV migration (drop + reimport schools and results). Use when the database has been wiped and needs repopulating from the CSV files. + Pass ?geocode=false to skip postcode → lat/lng resolution. Runs synchronously — expect this to take several minutes. Requires X-API-Key header with valid admin API key. """ loop = asyncio.get_event_loop() - success = await loop.run_in_executor(None, run_full_migration) + success = await loop.run_in_executor(None, lambda: run_full_migration(geocode=geocode)) if not success: raise HTTPException(status_code=500, detail="Migration failed: no CSV data found in data directory") clear_cache() diff --git a/integrator/scripts/sources/ks2.py b/integrator/scripts/sources/ks2.py index fb8d34b..4961585 100644 --- a/integrator/scripts/sources/ks2.py +++ b/integrator/scripts/sources/ks2.py @@ -22,8 +22,8 @@ def download(): def load(): - """Trigger full KS2 re-import via the backend admin endpoint.""" - url = f"{BACKEND_URL}/api/admin/reimport-ks2" + """Trigger full KS2 re-import via the backend admin endpoint (with geocoding).""" + url = f"{BACKEND_URL}/api/admin/reimport-ks2?geocode=true" print(f"POST {url}") resp = requests.post( url,