eat(db): standardize UUID format to hyphenated representation across all models#2931
Draft
Lang-Akshay wants to merge 4 commits intomainfrom
Draft
eat(db): standardize UUID format to hyphenated representation across all models#2931Lang-Akshay wants to merge 4 commits intomainfrom
Lang-Akshay wants to merge 4 commits intomainfrom
Conversation
…ross models Signed-off-by: Akshay Shinde <akshay.shinde26@ibm.com>
… and tests Signed-off-by: Akshay Shinde <akshay.shinde26@ibm.com>
Signed-off-by: Akshay Shinde <akshay.shinde26@ibm.com>
… correct UUID format in test case for validated team ID parameter Signed-off-by: Akshay Shinde <akshay.shinde26@ibm.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.
Resolves
Closes #1324
Issue Summary
The codebase used inconsistent UUID string representations:
550e8400-e29b-41d4-a716-446655440000(6 models)550e8400e29b41d4a716446655440000(18 models)This inconsistency caused:
Solution
Standardized all UUID primary keys to the hyphenated format (
str(uuid.uuid4())) across all 18 affected models, as recommended in issue #1324. This approach:Changes Made
1. Model Definitions (mcpgateway/db.py)
Updated 12 models from hex (
uuid.uuid4().hex) to hyphenated format (str(uuid.uuid4())):String(32)→String(36)String(32)→String(36)String(32)→String(36)String(32)→String(36)String(32)→String(36)String(32)→String(36)String(32)→String(36)String(32)→String(36)String(32)→String(36)String(32)→String(36)String(32)→String(36)String(32)→String(36)Note: 6 models (Role, UserRole, PendingUserApproval, RegisteredOAuthClient, EmailApiToken, SSOAuthSession) already used hyphenated format and required no changes.
2. Database Migration (Alembic)
File:
mcpgateway/alembic/versions/*71e35d2065b6_convert_hex_uuids_to_hyphenated.pyConverts existing hex UUIDs to hyphenated format:
Handles all 12 affected tables and their foreign key relationships.
3. Validation Updates (mcpgateway/common/validators.py)
4. Schema Updates (mcpgateway/schemas.py)
5. Test Updates (6 files)
Updated all test assertions to expect hyphenated UUIDs:
tests/mcpgateway/services/test_server_service.pytests/mcpgateway/test_display_name_uuid_features.pytests/unit/mcpgateway/test_admin.pytests/unit/mcpgateway/test_admin_module.py6. Verification Scripts
Created helper scripts for validation:
test_uuid_format.py— Unit tests for UUID conversion logicverify_uuid_changes.py— Post-migration verification scriptMigration Details
Idempotent Pattern
The migration checks if conversion already occurred using
WHERE id NOT LIKE '%-%-%-%-'to safely handle:Database Support
SUBSTR+CONCAT)substring+concatenation)SUBSTR+CONCAT)Testing
✅ All existing tests updated and passing:
Verification scripts validate:
Benefits
Storage Overhead
Future Optimization Options
Commits
feat: convert UUID generation to hyphenated format for consistency across modelsfeat: normalize UUID format to hyphenated representation across models and testsfixup: formattingfix: add nosec comments for SQL queries in UUID conversion scriptChecklist
Migration Runbook
Rollback (if needed)
Related Issues