Draft: Rearchitect users with the help of Kilocode with GKG
What does this MR do and why?
Rearchitect users with the help of Kilocode with GKG
Relates to #213
Video of Execution Kilo with GKG
Summary
Took ~2.5 minutes
Result:
Summary
I have successfully rearchitected the users table to support non-GitLab contributors in the Contributor Platform. Here's what was implemented:
Key Changes Made:
-
Database Schema Update: Added a
gitlab_user_id
column to theusers
table, nullable integer with unique index. Existing GitLab users have this set to their currentid
value. -
User Model Updates:
- Added validation for
gitlab_user_id
uniqueness - Modified
web_url
method to returnnil
for non-GitLab users (instead of invalid GitLab URLs) - Maintained all existing functionality for GitLab users
- Added validation for
-
Data Import Services Updated:
- Discord: Now creates users for Discord contributors without GitLab accounts, using Discord username (with uniqueness handling)
- Discourse: Creates users for Discourse contributors not linked to GitLab accounts
-
Crowdin: Creates users for Crowdin translators without GitLab accounts, linking via
user_profiles.crowdin_username
-
Backward Compatibility: All existing GitLab users retain full functionality. Foreign keys and relationships remain intact since
id
continues to serve as the primary key. -
Leaderboard & User Profiles: These already work with non-GitLab users since they use
username
for identification, and the API returns appropriate data (GitLab-specific fields are empty for non-GitLab users, which is correct).
How It Works:
-
GitLab Users:
gitlab_user_id
= their GitLab user ID,web_url
returns GitLab profile URL -
Non-GitLab Users:
gitlab_user_id
=nil
,web_url
=nil
, identified by uniqueusername
- All users have the same
id
(internal primary key), maintaining referential integrity - Points, activities, and leaderboard participation work identically for both user types
MCP Usage:
The GitLab Knowledge Graph MCP was instrumental in this implementation. It helped by:
- Providing a comprehensive repository map showing the Rails app structure
- Listing all User-related definitions and migrations
- Finding references to the User model across the codebase (41 references analyzed)
- Enabling quick understanding of how users are used in controllers, services, and views
- Assisting in identifying foreign key relationships and potential impact areas
This allowed for efficient investigation and ensured all necessary code paths were updated without missing critical dependencies.