[RFC] Add Special Administrative Regions (SARs) support to states table #1132
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.
Problem
Special Administrative Regions like Hong Kong and Macau presented a data modeling challenge: they should be classified as states/provinces under their parent country (China), but they have unique attributes typically associated with countries—distinct phone codes, currencies, and flags. Previously, this created a dilemma:
Current Implementation (Under Review)
This PR currently extends the
statestable schema with 6 optional country-level fields specifically for Special Administrative Regions. However, based on maintainer feedback, this approach may be revised.Current Schema Changes
Added 6 new optional fields to the
statestable:These fields remain
NULLfor regular states/provinces and are only populated for SARs.Concern raised: Adding 6 columns for just 2 SARs creates unnecessary schema complexity.
Alternative proposed (see
ALTERNATIVE_SOLUTION.md): Use a singlesar_metadataJSON column instead of 6 separate columns:Benefits of JSON approach:
Example with JSON field:
{ "id": 2267, "name": "Hong Kong SAR", "country_id": 45, "sar_metadata": { "phonecode": "852", "currency": "HKD", "currency_name": "Hong Kong dollar", "currency_symbol": "$", "emoji": "🇭🇰", "emojiU": "U+1F1ED U+1F1F0" } }Status: Awaiting maintainer direction on preferred implementation approach before proceeding.
Data Example (Current Implementation)
Hong Kong SAR is currently represented as:
{ "id": 2267, "name": "Hong Kong SAR", "country_id": 45, "country_code": "CN", "type": "special administrative region", "phonecode": "852", "currency": "HKD", "currency_name": "Hong Kong dollar", "currency_symbol": "$", "emoji": "🇭🇰", "emojiU": "U+1F1ED U+1F1F0" }Similarly for Macau SAR (phonecode: 853, currency: MOP, emoji: 🇲🇴).
Query Examples
The enhanced schema enables powerful queries:
Changes (Current Implementation)
Benefits
✅ Geographically accurate - SARs properly classified under parent countries
✅ Data complete - No loss of important attributes
✅ Backward compatible - Existing queries continue to work unchanged
✅ Extensible - Can accommodate other autonomous territories (Åland Islands, Faroe Islands, Greenland, Puerto Rico, etc.)
✅ Standards compliant - Follows ISO 3166-2 subdivision codes
Testing
python3 scripts/validate_sar.py)Documentation
Comprehensive documentation provided:
docs/SPECIAL_ADMINISTRATIVE_REGIONS.md- Technical guide and usagedocs/SAR_VISUALIZATION.md- Visual before/after comparisonsIMPLEMENTATION_SUMMARY.md- Complete implementation detailsALTERNATIVE_SOLUTION.md- NEW: Single JSON field alternative approach with detailed comparisonBreaking Changes
None - This is a fully backward-compatible extension:
Next Steps
Awaiting maintainer decision on implementation approach:
Fixes the issue raised about Hong Kong and Macau representation while providing a sustainable solution for similar cases worldwide.
Fixes #1025
Original prompt
Fixes #1025
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.