feat(postcodes): backfill state_id on 19,272 rows across 7 countries (#1039)#1542
Open
dr5hn wants to merge 1 commit into
Open
feat(postcodes): backfill state_id on 19,272 rows across 7 countries (#1039)#1542dr5hn wants to merge 1 commit into
dr5hn wants to merge 1 commit into
Conversation
β¦1039) Earlier postcode imports for 7 countries shipped with state_id=null because upstream sources only carried (code, locality) pairs. CSC's own contributions/cities/<iso2>.json already has city β state_id, so unambiguous folded-name matching recovers the FKs without external data. | iso2 | total | backfilled | match% | |------|------:|-----------:|-------:| | SE | 16,392| 13,162 | 80% | | ZA | 5,685| 2,906 | 51% | | NL | 4,072| 2,463 | 60% | | RS | 1,170| 343 | 29% | | SI | 522| 271 | 51% | | GB | 124| 98 | 79% | | VN | 63| 29 | 46% | Names that map to multiple distinct states are dropped (postcode data alone can't disambiguate). Strict improvement: rows still unmatched remain state_id=null as before. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Backfills
state_id(andstate_code) on 19,272 existing postcode rows that previously shipped withstate_id: null. No new external data β uses CSC's owncontributions/cities/<iso2>.jsonas acity β state_idlookup table.Why this is a strict improvement
state_id: nullβ the same as before.Rijswijkexists in both Noord-Brabant and Zuid-Holland) are deliberately not matched, since postcode data alone can't disambiguate. 15 ambiguous names were dropped from the NL lookup, 24 from SE, 29 from GB.Why these 7 countries (and not others)
Audit of all 0%-FK postcode files vs cities.json:
locality_name(no field to match)Implementation
bin/scripts/sync/backfill_postcode_state_fk.pyβ single pass, idempotent, supports--dry-runand--only=<iso2[,iso2...]>. NFKD-fold names for diacritic-insensitive matching. Skips rows whosestate_idis already set.The diff size is large because the existing files were re-emitted with consistent JSON formatting (existing
id,created_at,updated_at,flagfields preserved verbatim; onlystate_idandstate_codemutated where matchable).π€ Generated with Claude Code