fix(seed): make UpsertIATADetails a true upsert

UpsertIATADetails was a plain UPDATE that silently affected zero rows
when the iata_codes row did not yet exist.  Adding a new IATA to the
config for the first time resulted in display_name, approx_lat, and
approx_lng remaining NULL.

Change the query to INSERT ... ON CONFLICT DO UPDATE so the row is
atomically created (if missing) or updated (if present), matching the
function's name and the pattern used by UpsertTransportScope.
This commit is contained in:
gadgethd
2026-06-12 08:25:14 -07:00
committed by Ded
parent f143ff1b0a
commit 87239bd4b8
2 changed files with 12 additions and 10 deletions
+6 -5
View File
@@ -17,11 +17,12 @@ SELECT * FROM iata_codes WHERE iata = $1;
SELECT * FROM iata_codes ORDER BY iata;
-- name: UpsertIATADetails :exec
UPDATE iata_codes SET
display_name = $2,
approx_lat = $3,
approx_lng = $4
WHERE iata = $1;
INSERT INTO iata_codes (iata, display_name, approx_lat, approx_lng)
VALUES ($1, $2, $3, $4)
ON CONFLICT (iata) DO UPDATE SET
display_name = EXCLUDED.display_name,
approx_lat = EXCLUDED.approx_lat,
approx_lng = EXCLUDED.approx_lng;
-- ============================================================
-- TRANSPORT CODES
+6 -5
View File
@@ -3025,11 +3025,12 @@ func (q *Queries) UpsertIATA(ctx context.Context, iata string) error {
}
const upsertIATADetails = `-- name: UpsertIATADetails :exec
UPDATE iata_codes SET
display_name = $2,
approx_lat = $3,
approx_lng = $4
WHERE iata = $1
INSERT INTO iata_codes (iata, display_name, approx_lat, approx_lng)
VALUES ($1, $2, $3, $4)
ON CONFLICT (iata) DO UPDATE SET
display_name = EXCLUDED.display_name,
approx_lat = EXCLUDED.approx_lat,
approx_lng = EXCLUDED.approx_lng
`
type UpsertIATADetailsParams struct {