Skip to content

fix: write geography columns explicitly instead of inferring points from value shape - #506

Merged
joaquimds merged 3 commits into
mainfrom
fix/explicit-geometry-writes
Sep 21, 2026
Merged

joaquimds merged 3 commits into
mainfrom
fix/explicit-geometry-writes

Conversation

@joaquimds

Copy link
Copy Markdown
Member

Problem

An Airtable data source whose records have columns named lat and lng failed to import with invalid input syntax for type json. The PointPlugin converted any object with lat and lng keys into a PostGIS point before every query, so the whole JSON row was turned into SRID=4326;POINT(...) and rejected by the jsonb column. This affects any data source type with those two column names.

Fix

Geometry is no longer inferred from a value's shape.

  • PointPlugin now only parses geography values on read (unchanged behaviour).
  • Geography columns (data_record.geocode_point, placed_marker.point, geocode_cache.point) are typed as GeographyColumn<...> so their insert/update type is a SQL expression. A raw { lat, lng } object is a type error at the write site.
  • New helper toGeography(point) builds the ST_SetSRID(ST_MakePoint(...), 4326)::geography expression.
  • upsertDataRecords and upsertPlacedMarker wrap the point internally, so callers are unchanged. The two direct geocodeCache writes wrap it themselves.
  • Turfs and areas already used explicit expressions and are untouched.
  • AGENTS.md updated to describe the rule.

Tests

  • New tests/feature/geography.test.ts: regression test importing a CSV with lat/lng columns, and a round-trip test for toGeography on both geography columns.
  • Import, geocode cache, geojson API and data record tests pass.
  • The original failing Airtable source imports all 142 records locally with the fix.

🤖 Generated with Claude Code

joaquimds and others added 3 commits September 21, 2026 18:53
…rom value shape

The PointPlugin converted any object with `lat` and `lng` keys into a
PostGIS point before every query. A data source whose records have
columns named `lat` and `lng` therefore had its whole JSON row turned
into `SRID=4326;POINT(...)`, which Postgres rejected for the jsonb
column ("invalid input syntax for type json").

Geometry is no longer inferred from a value's shape. Geography columns
are typed as `GeographyColumn<...>` so their insert/update type is a SQL
expression, and every write goes through `toGeography(point)`. The
plugin now only parses geography values on read. Repositories that
accept a domain object (`upsertDataRecords`, `upsertPlacedMarker`) wrap
the point themselves so callers are unchanged.

Adds a regression test importing a CSV with `lat`/`lng` columns and a
round-trip test for `toGeography`.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…able

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…n comment

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@joaquimds
joaquimds merged commit d34842e into main Sep 21, 2026
1 check passed
@joaquimds
joaquimds deleted the fix/explicit-geometry-writes branch September 21, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant