Skip to content

Comments

Fix state_abbr not globally unique across countries#29

Merged
midwire merged 2 commits intodevelopfrom
fix/state-abbr-uniqueness
Feb 14, 2026
Merged

Fix state_abbr not globally unique across countries#29
midwire merged 2 commits intodevelopfrom
fix/state-abbr-uniqueness

Conversation

@midwire
Copy link
Owner

@midwire midwire commented Feb 14, 2026

Summary

  • Scope get_state_id lookups by country using a 3-step fallback chain (exact match → abbr+country → name+country) to resolve incorrect state associations in multi-country mode
  • Add stateless country fallback in StateTable#write for countries without state subdivisions (synthesizes state from country lookup table)
  • Update state_name unique index to include country_id, allowing same-named states in different countries to coexist
  • Update all callers (CountyTable, ZipcodeTable) and tests to pass country to get_state_id

Test plan

  • All 112 existing tests pass
  • New tests for get_state_id fallback chain (exact, abbr-only, name-only, country scoping, nil return)
  • New tests for stateless country fallback (nil short_state, empty short_state, unknown country)
  • New test for same-name states in different countries coexisting
  • Zero rubocop offenses

Fixes #18
Supersedes #19

Scope state lookups by country in get_state_id using a 3-step fallback
(exact match, abbr+country, name+country). Add stateless country
fallback in StateTable for countries without state subdivisions. Update
state_name index to include country_id for multi-country uniqueness.

Fixes #18
- Fix COLLATE NOCASE placement on both indexes (apply to abbr/name
  columns, not country_id)
- Add nil guard for country_id in StateTable#write
- Add nil guard for state_id in ZipcodeTable#write
- Strengthen fallback tests to verify correct state ID returned
- Add test for nil country input to get_state_id
- Add test verifying row mutation for downstream Kiba destinations
@midwire midwire merged commit 08e89cc into develop Feb 14, 2026
@midwire midwire deleted the fix/state-abbr-uniqueness branch February 14, 2026 20:01
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.

state abbreviations are not globally unique

1 participant