← back to NationalPaperHangers

db/migrations/009_installer_geo.sql

15 lines

-- 009 — installer geo coordinates for /map view + radius search.
-- latitude/longitude are nullable so existing rows don't break.
-- geocoded_at lets the geocoder script skip already-resolved rows.
-- accuracy gives us an honesty signal for the UI ("city-level" vs "address-level").

ALTER TABLE installers
  ADD COLUMN IF NOT EXISTS latitude  numeric(8,5),
  ADD COLUMN IF NOT EXISTS longitude numeric(9,5),
  ADD COLUMN IF NOT EXISTS geo_accuracy text,
  ADD COLUMN IF NOT EXISTS geocoded_at timestamptz;

CREATE INDEX IF NOT EXISTS idx_installers_latlng
  ON installers (latitude, longitude)
  WHERE latitude IS NOT NULL AND longitude IS NOT NULL;