feat(ks2): enable geocoding during reimport
All checks were successful
Build and Push Docker Images / Build Backend (FastAPI) (push) Successful in 47s
Build and Push Docker Images / Build Frontend (Next.js) (push) Successful in 1m3s
Build and Push Docker Images / Build Integrator (push) Successful in 56s
Build and Push Docker Images / Build Kestra Init (push) Successful in 32s
Build and Push Docker Images / Trigger Portainer Update (push) Successful in 1s

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 <noreply@anthropic.com>
This commit is contained in:
2026-03-24 20:57:11 +00:00
parent 6ba1c42417
commit 68b15400b0
2 changed files with 5 additions and 3 deletions

View File

@@ -639,16 +639,18 @@ async def reload_data(
@limiter.limit("2/minute") @limiter.limit("2/minute")
async def reimport_ks2( async def reimport_ks2(
request: Request, request: Request,
geocode: bool = True,
_: bool = Depends(verify_admin_api_key) _: bool = Depends(verify_admin_api_key)
): ):
""" """
Re-run the full KS2 CSV migration (drop + reimport schools and results). 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. 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. Runs synchronously — expect this to take several minutes.
Requires X-API-Key header with valid admin API key. Requires X-API-Key header with valid admin API key.
""" """
loop = asyncio.get_event_loop() 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: if not success:
raise HTTPException(status_code=500, detail="Migration failed: no CSV data found in data directory") raise HTTPException(status_code=500, detail="Migration failed: no CSV data found in data directory")
clear_cache() clear_cache()

View File

@@ -22,8 +22,8 @@ def download():
def load(): def load():
"""Trigger full KS2 re-import via the backend admin endpoint.""" """Trigger full KS2 re-import via the backend admin endpoint (with geocoding)."""
url = f"{BACKEND_URL}/api/admin/reimport-ks2" url = f"{BACKEND_URL}/api/admin/reimport-ks2?geocode=true"
print(f"POST {url}") print(f"POST {url}")
resp = requests.post( resp = requests.post(
url, url,