trips/spatial/import.sh
Greg Pomerantz c367eba5cb Live web enrichment (SearXNG) + PostGIS spatial stack
Milestone 1 — live web search:
- mock/server.js: /search + /search-status proxy to the self-hosted
  SearXNG (third leg of the 3-source blend; engine endpoint stays
  server-side), /spatial + /spatial-status proxy to the spatial service
- mock/app.js: background enrichment of suggestion cards — each
  candidate gets a web element (discovery cards + "you might like"
  rows) that is checked via SearXNG in the background (one in-flight
  query per place, 1 h TTL, failures retry in ~5 min) and APPENDS
  sourced facts with provenance URLs; never reorders/rewrites the plan.
  New LLM tools: web_search (cite URLs) and poi_near (PostGIS). Status
  badge gains 'web' / 'spatial'.
- styles.css: .cc-web live-facts blocks, t-web verified chip

Milestone 2 — PostGIS spatial DB (code complete; needs docker access
to run — see spatial/README.md):
- spatial/: docker-compose (postgis/postgis:16-3.4 + osm2pgsql:16
  one-shot importer + spatiald), schema.sql (poi table w/ GIST index,
  spatial_extract bookkeeping, refresh_poi()), import.sh for the PBF
  extracts in ../osm, spatiald (Go, lib/pq): /health, /near
  (ST_DWithin), /nearest (KNN), /corridor (ST_Buffer along a route),
  with kind/name/extract/limit filters
2026-09-10 09:43:30 -04:00

53 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Import an OSM PBF extract into the local PostGIS stack via osm2pgsql.
#
# ./import.sh [file.osm.pbf] [extract-name]
#
# file.osm.pbf default: ../osm/nh.osm.pbf (path may be absolute)
# extract-name default: basename without extension
#
# The PBF must be readable by uid 1001 (the osm2pgsql image user) — the
# script bind-mounts its directory read-only. After the load, the poi
# table is refreshed (refresh_poi()) and the spatial_extract row updated.
set -euo pipefail
cd "$(dirname "$0")"
PBF=${1:-../osm/nh.osm.pbf}
NAME=${2:-$(basename "${PBF%.osm.pbf}")}
ABS=$(realpath "$PBF")
[[ -f $ABS ]] || { echo "no such PBF: $ABS" >&2; exit 1; }
# 1. DB up (first boot runs schema.sql)
docker compose up -d postgis
echo "waiting for postgis to be healthy…"
for i in $(seq 1 60); do
if docker compose exec -T postgis pg_isready -U trips -d trips >/dev/null 2>&1; then break; fi
sleep 2
[[ $i -eq 60 ]] && { echo "postgis never became healthy" >&2; exit 1; }
done
# 2. osm2pgsql load (one-shot container, PBF bind-mounted ro)
docker run --rm \
--user 1001:1001 \
--network "trips_default" \
-v "$(dirname "$ABS"):/data:ro" \
-e PBF_FILE="/data/$(basename "$ABS")" \
-e ARGS="--host=postgis --port=5432 --database=trips --user=trips --password=trips \
--create --clean --slim --flat-nodes=/tmp/flat.nodes --disable-operations" \
osm2pgsql/osm2pgsql:16
# 3. refresh the queryable poi table + extract bookkeeping
docker compose exec -T postgis psql -U trips -d trips -v ON_ERROR_STOP=1 <<SQL
INSERT INTO spatial_extract (name) VALUES ('${NAME}')
ON CONFLICT (name) DO NOTHING;
SELECT refresh_poi('${NAME}');
SQL
# 4. report
docker compose exec -T postgis psql -U trips -d trips -c \
"SELECT name, poi_count, to_char(imported_at,'YYYY-MM-DD HH24:MI') AS imported
FROM spatial_extract ORDER BY name;"
echo "done — extract '$NAME' is queryable. Start the service:"
echo " docker compose up -d spatiald # :5005, proxied by the mock server at /spatial/*"