Skip to content

fix(geo-data): correct country_id mismatch in states.csv and cities.csv#1681

Closed
YogeshK34 wants to merge 4 commits into
credebl:mainfrom
YogeshK34:fix/geo-data
Closed

fix(geo-data): correct country_id mismatch in states.csv and cities.csv#1681
YogeshK34 wants to merge 4 commits into
credebl:mainfrom
YogeshK34:fix/geo-data

Conversation

@YogeshK34

@YogeshK34 YogeshK34 commented Jun 18, 2026

Copy link
Copy Markdown

Problem

states.csv contains a systematic country_id corruption affecting all countries from Germany onward (~148 countries). The country_code column is correct, but country_id values don't match the IDs in countries.csv — causing states of one country to be served under another.

Example:

File name country_id (before) country_code Actual country
states.csv Andhra Pradesh 99 IN Hong Kong (99) ≠ India (102)

This means selecting India in the UI returned Iran's states. Selecting Hong Kong returned India's states. No error is thrown — the data is silently wrong.

cities.csv had the same downstream corruption.

Root Cause

The country_id column was not derived from countries.csv IDs. The country_code column was always correct, but country_id diverged for ~148 countries starting alphabetically around Germany.

Fix

Regenerated country_id in both CSVs by mapping country_code (ISO) → correct id from countries.csv.

  • states.csv — 4,581 rows corrected
  • cities.csv — 105,446 rows corrected

Impact

Scenario Impact
Fresh local setup / CI ✅ Fixed — correct geo data on first seed
Existing seeded deployment ✅ No impact — import script skips non-empty tables

Testing

-- Verify India's states return correctly
SELECT * FROM states WHERE country_id = 102 LIMIT 5;
-- All rows should have country_code = 'IN'

Summary by CodeRabbit

  • Documentation

    • Substantially enhanced local setup guide with clearer package manager requirements, PostgreSQL configuration, Keycloak setup steps, and expanded troubleshooting section including Keycloak sign-in and Docker connectivity issues.
  • Infrastructure

    • Added platform volume configuration to Docker Compose.
  • Bug Fixes

    • Improved seeding logic to properly handle existing Keycloak users and ensure required identifiers are populated.
  • Chores

    • Reorganized package dependencies.

Signed-off-by: yogeshk34 <khutwadyogesh34@gmail.com>
Signed-off-by: yogeshk34 <khutwadyogesh34@gmail.com>
…776)

Signed-off-by: yogeshk34 <khutwadyogesh34@gmail.com>
Signed-off-by: yogeshk34 <khutwadyogesh34@gmail.com>
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The Prisma seed script is refactored to handle Keycloak 409 conflict responses by looking up the existing user's ID and updating the local DB with encrypted credentials, instead of returning early. The README is substantially rewritten with pnpm, Keycloak, and Prisma setup details. A platform-volume named volume is added to docker-compose.yml, and package.json dependencies are reordered.

Changes

Platform Setup and Seed Improvements

Layer / File(s) Summary
Keycloak 409 conflict handling and DB sync helpers
libs/prisma-service/prisma/seed.ts
platformUserId is now assigned from the existing user record when the admin already exists. Two new helpers are added: one queries Keycloak by username to retrieve the existing user ID, and the other updates the platform admin DB row with AES-encrypted clientId/clientSecret and keycloakUserId. createKeycloakUser is rewired to call these on both 409 CONFLICT and 201 CREATED paths, and throws on any other status.
README local setup documentation rewrite
README.md
Intro updated to identify this repo as the backend; hosted users redirected to external docs. Install section replaced with pnpm-centric guidance (including warning against npm). PostgreSQL/Prisma section reworked with Docker Compose container naming caveats, .env localhost warnings, and prisma migrate deploy before seeding. Keycloak section expanded with step-by-step realm and dual-client configuration, .env snippets, and re-seeding behavior notes. NATS and service start commands updated; troubleshooting section rewritten with specific failure modes; Credit section reformatted.
docker-compose volume and package.json reorder
docker-compose.yml, package.json
platform-volume with local driver is declared in the docker-compose.yml volumes section. form-data, handlebars, and protobufjs entries are moved earlier in package.json dependencies, removing their prior placement immediately before devDependencies.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • credebl/platform#1428: Both PRs restructure the same README sections covering Docker/PostgreSQL/NATS setup and endpoint access instructions.
  • credebl/platform#1538: Both PRs modify createKeycloakUser in seed.ts to handle existing users (409) and sync keycloakUserId/client credentials to the local DB.
  • credebl/platform#1601: Both PRs change the Keycloak token and user creation control flow in seed.ts, with overlapping edits to credential env var handling and DB update logic.

Suggested reviewers

  • RinkalBhojani
  • shitrerohit
  • KambleSahil3

Poem

🐇 Hop hop, the seed now knows
When Keycloak says "that user exists!"
Look them up, encrypt the keys,
Update the DB with greatest ease.
README shines with pnpm's grace —
A tidy warren, a well-mapped place! 🌿

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title claims to fix country_id mismatches in geo-location CSV files, but the actual changes involve README updates, docker-compose configuration, and seed script refactoring with no visible changes to the claimed CSV files. Revise the title to accurately reflect the actual changes: documentation improvements, Docker configuration updates, and seed script enhancements for Keycloak integration and platformUserId handling.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
README.md (1)

120-121: ⚡ Quick win

Avoid :latest image tags in setup docs.

Using floating tags for Keycloak and NATS makes local setup non-reproducible and can break onboarding when upstream defaults/env contracts change. Pin tested versions in the README commands.

Also applies to: 225-226

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@README.md` around lines 120 - 121, Replace the floating `:latest` Docker
image tags with specific pinned version numbers in the README.md setup
documentation. This applies to both the Keycloak image reference in the
`quay.io/keycloak/keycloak:latest start-dev` command and the NATS image
reference (also marked in the comment). Use tested and working versions instead
of latest to ensure reproducible local setup and prevent onboarding breakage
when upstream images are updated.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@README.md`:
- Around line 120-121: Replace the floating `:latest` Docker image tags with
specific pinned version numbers in the README.md setup documentation. This
applies to both the Keycloak image reference in the
`quay.io/keycloak/keycloak:latest start-dev` command and the NATS image
reference (also marked in the comment). Use tested and working versions instead
of latest to ensure reproducible local setup and prevent onboarding breakage
when upstream images are updated.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1f3e22dc-aeb7-4c53-8edb-6bbac85a74d2

📥 Commits

Reviewing files that changed from the base of the PR and between 8380043 and b9b006f.

⛔ Files ignored due to path filters (3)
  • libs/prisma-service/prisma/data/geo-location-master-data/cities.csv is excluded by !**/*.csv
  • libs/prisma-service/prisma/data/geo-location-master-data/states.csv is excluded by !**/*.csv
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • README.md
  • docker-compose.yml
  • libs/prisma-service/prisma/seed.ts
  • package.json

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.

1 participant