NUMBER_OF_CHILDREN_IN_YOUR_GROUP fields add in kafka consumer service#32
NUMBER_OF_CHILDREN_IN_YOUR_GROUP fields add in kafka consumer service#32sourav-dev-hub wants to merge 1 commit into
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe PR adds two new optional columns to the User entity (userNumOfChildrenWorkingWith and userCustomField), introduces transformation logic to map custom field data to userNumOfChildrenWorkingWith, and includes a database migration script to update UserPhoneType records from source to destination databases. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/constants/transformation/transform-service.ts (1)
78-131: Consider populating theuserCustomFieldcolumn.The User entity now has a
userCustomFieldcolumn (JSONB type) that could store the entire custom fields object for future extensibility. Currently, specific fields are extracted individually, but storing the complete custom fields data would:
- Preserve all custom field data without requiring schema changes for new fields
- Provide a fallback for fields not yet mapped
- Enable easier debugging and auditing
Consider adding this mapping after line 125:
userNumOfChildrenWorkingWith: extractCustomField('NUMBER_OF_CHILDREN_IN_YOUR_GROUP'), + userCustomField: data.customFields || null, // Boolean fieldsshiksha-migration/user-update-phone-type-migration.js (2)
37-83: Consider adding transaction support for atomicity.The migration updates users one-by-one without transaction boundaries. If the migration fails partway through, it will leave the database in a partially migrated state.
Consider wrapping the update loop in a transaction:
try { await destClient.query('BEGIN'); for (const user of usersWithNullPhoneType) { const result = await updatePhoneTypeForUser(sourceClient, destClient, user.UserID); // ... tracking logic } await destClient.query('COMMIT'); console.log('[PHONE TYPE UPDATE] Transaction committed successfully'); } catch (error) { await destClient.query('ROLLBACK'); console.error('[PHONE TYPE UPDATE] Transaction rolled back due to error:', error); throw error; }Alternatively, if you prefer per-user atomicity with resilience to partial failures, the current approach is acceptable—just document that the migration can be safely re-run.
9-9: Consider adding a comment documenting the field mapping for consistency.The UUID
da594b2e-c645-4a96-af15-6e2d24587c9ais verified as consistent across all migration files (user-migration.js and user-migration-c2c.js also use this same value). The field ID is already documented in related migration files as mapping to 'UserPhoneType' / 'phone_type_accessible'. To improve maintainability, add a similar inline comment to line 9 (e.g.,// phone_type_accessible) to match the documentation pattern in the other migration files.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting
📒 Files selected for processing (3)
shiksha-migration/user-update-phone-type-migration.js(1 hunks)src/constants/transformation/transform-service.ts(1 hunks)src/entities/user.entity.ts(1 hunks)
🔇 Additional comments (5)
src/entities/user.entity.ts (2)
235-236: LGTM! Field properly mapped in transformation service.The
userNumOfChildrenWorkingWithfield is correctly defined and is populated insrc/constants/transformation/transform-service.tsat line 125 from the custom fieldNUMBER_OF_CHILDREN_IN_YOUR_GROUP.
238-239: Confirm the intended use ofuserCustomFieldcolumn and populate if needed.The
userCustomFieldcolumn (entity line 239) is not being populated in the transformation service. ThetransformUserDatamethod extracts specific custom fields by label and maps them to individual entity properties, but does not store custom fields in theuserCustomFieldJSONB column.Either:
- Confirm this is intentional (reserved for future use) and document it, or
- Add the mapping to populate it with custom fields data in the transformation service
If option 2, add to the
transformedDataobject:userCustomField: data.customFields ? Object.fromEntries(data.customFields.map((f: any) => [f.label, f.selectedValues])) : null,src/constants/transformation/transform-service.ts (1)
125-125: LGTM! Transformation logic correctly maps the new field.The
userNumOfChildrenWorkingWithfield is properly extracted from theNUMBER_OF_CHILDREN_IN_YOUR_GROUPcustom field using the establishedextractCustomFieldpattern. This aligns with the new column added to the User entity.shiksha-migration/user-update-phone-type-migration.js (2)
1-32: LGTM! Well-structured helper function and constants.The module structure, constants, and
getFirstValuehelper function are well-implemented:
- Handles multiple input formats (string, array, null) gracefully
- Returns null for empty/invalid inputs
- Clear documentation
184-196: LGTM! Proper module pattern for CLI and programmatic use.The script correctly:
- Checks if it's run directly vs imported as a module
- Exports the main function for reuse
- Handles errors appropriately with process.exit(1)


No description provided.