poi-index: stream selectors SQL into psql stdin (fix \i container path)

poi-import.sh ran the classifier selectors via psql \i, but psql executes
inside the postgres container (docker compose exec), so it couldn't find the
host path /opt/trails-cool/scripts/poi-selectors.sql. Concatenate BEGIN + the
selectors file contents + the build statements on the host and pipe them into
psql stdin instead, keeping the ON COMMIT DROP temp table in one transaction.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ullrich Schäfer 2026-07-13 00:27:48 +02:00
parent 115c76a69a
commit a6f8595c4b
No known key found for this signature in database
GPG key ID: A32FF691A0F752D9

View file

@ -105,10 +105,16 @@ gunzip -c "$ARTIFACT" | psql -c \
# One transaction: temp selector table (from map-core) → pois_staging built
# LIKE the live table so structure/defaults match the Drizzle schema exactly →
# classified insert → indexes. The 70% guard + swap run in step 5.
#
# The selector SQL is streamed from the host into psql's stdin (not `\i`, which
# would look for the file inside the postgres container, where it doesn't
# exist). BEGIN + selectors + the build statements are concatenated into one
# session so the ON COMMIT DROP temp table lives for the whole transaction.
log "building classified staging table"
psql <<SQL || fail "staging build failed"
BEGIN;
\\i $SELECTORS_SQL
{
echo "BEGIN;"
cat "$SELECTORS_SQL"
cat <<'SQL'
DROP TABLE IF EXISTS planner.pois_staging;
CREATE TABLE planner.pois_staging (LIKE planner.pois INCLUDING DEFAULTS);
INSERT INTO planner.pois_staging (osm_type, osm_id, category, name, geom, tags, imported_at)
@ -127,6 +133,7 @@ CREATE INDEX pois_staging_geom_idx ON planner.pois_staging USING gist (geom);
CREATE INDEX pois_staging_category_idx ON planner.pois_staging (category);
COMMIT;
SQL
} | psql || fail "staging build failed"
STAGING_ROWS="$(psql -tA -c "SELECT count(*) FROM planner.pois_staging;")"
LIVE_ROWS="$(psql -tA -c "SELECT count(*) FROM planner.pois;")"