# MonacoUSA Portal - Snake Case Field Migration Guide ## ๐ŸŽฏ Overview This document provides complete instructions for migrating from space-separated field names (e.g., "First Name") to snake_case field names (e.g., "first_name") to eliminate data corruption issues when editing records directly in NocoDB. ## ๐Ÿ“Š Required NocoDB Field Name Changes You need to rename the following fields in your NocoDB Members table: | **Current Field Name** | **New Snake Case Name** | **Type** | |----------------------------|----------------------------|-------------| | `First Name` | `first_name` | Text | | `Last Name` | `last_name` | Text | | `Email` | `email` | Email | | `Phone` | `phone` | Text | | `Date of Birth` | `date_of_birth` | Date | | `Nationality` | `nationality` | Text | | `Address` | `address` | LongText | | `Membership Status` | `membership_status` | SingleSelect| | `Member Since` | `member_since` | Date | | `Current Year Dues Paid` | `current_year_dues_paid` | Text | | `Membership Date Paid` | `membership_date_paid` | Date | | `Payment Due Date` | `payment_due_date` | Date | ### ๐Ÿ”ง How to Rename Fields in NocoDB 1. **Open your NocoDB Members table** 2. **For each field above:** - Click on the field header - Select "Edit" or click the gear icon - Change the field name from the old name to the new snake_case name - Click "Save" โš ๏ธ **Important**: Do NOT change the field types, only the names. ## ๐Ÿ—๏ธ Backend Files Updated The following files have been completely updated to use snake_case field names: ### Type Definitions - โœ… `utils/types.ts` - Member interface updated ### NocoDB Utilities - โœ… `server/utils/nocodb.ts` - All CRUD operations updated ### API Endpoints - โœ… `server/api/members/index.get.ts` - List members API - โœ… `server/api/members/[id].get.ts` - Get single member API - โœ… `server/api/members/index.post.ts` - Create member API - โœ… `server/api/members/[id].put.ts` - Update member API ## ๐ŸŽจ Frontend Files That Need Updates The following frontend components still reference the old field names and need to be updated: ### Vue Components - `components/ViewMemberDialog.vue` - `components/MemberCard.vue` - `components/EditMemberDialog.vue` - `components/AddMemberDialog.vue` - `pages/dashboard/member-list.vue` ## ๐Ÿ”„ Complete Field Mapping Reference ### Data Access Patterns **Before (โŒ Old)**: ```javascript member['First Name'] member['Last Name'] member['Membership Status'] member['Current Year Dues Paid'] ``` **After (โœ… New)**: ```javascript member.first_name member.last_name member.membership_status member.current_year_dues_paid ``` ### API Request/Response Format **Create/Update Member Payload**: ```json { "first_name": "John", "last_name": "Doe", "email": "john.doe@example.com", "phone": "+1234567890", "nationality": "US", "membership_status": "Active", "current_year_dues_paid": "true", "date_of_birth": "1990-01-15", "member_since": "2023-01-01", "membership_date_paid": "2024-01-15", "payment_due_date": "2025-01-15", "address": "123 Main St, City, State" } ``` ## ๐Ÿงช Testing Checklist After making the NocoDB field changes, test the following: ### Backend API Testing - [ ] `GET /api/members` - List all members - [ ] `GET /api/members/{id}` - Get single member - [ ] `POST /api/members` - Create new member - [ ] `PUT /api/members/{id}` - Update existing member - [ ] `DELETE /api/members/{id}` - Delete member ### Data Integrity Testing - [ ] Create member via portal โ†’ Verify in NocoDB - [ ] Edit member via portal โ†’ Verify in NocoDB - [ ] Edit member in NocoDB directly โ†’ Verify portal displays correctly - [ ] All fields display properly (names, flags, contact info) ### Frontend Display Testing - [ ] Member list page loads and displays all members - [ ] Member cards show correct information - [ ] Country flags display properly - [ ] Search and filtering work correctly - [ ] Add member dialog works - [ ] Edit member dialog works and pre-populates correctly - [ ] View member dialog shows all details ## ๐Ÿšจ Critical Success Criteria The migration is successful when: 1. โœ… **No "undefined undefined" names appear** in member cards 2. โœ… **Country flags display properly** for all nationalities 3. โœ… **Direct NocoDB edits sync properly** with portal display 4. โœ… **All CRUD operations work** through the portal 5. โœ… **No TypeScript errors** in the console 6. โœ… **No API errors** in browser network tab ## ๐Ÿ”ง Rollback Plan If issues occur, you can temporarily rollback by: 1. **Revert NocoDB field names** back to the original space-separated format 2. **Revert the backend files** using git: ```bash git checkout HEAD~1 -- utils/types.ts server/utils/nocodb.ts server/api/members/ ``` ## ๐Ÿ“ˆ Next Steps After Migration 1. **Update frontend components** to use snake_case field names 2. **Test thoroughly** across all functionality 3. **Update any documentation** that references old field names 4. **Consider adding validation** to prevent future field name inconsistencies ## ๐Ÿ’ก Benefits After Migration - โœ… **Consistent data display** regardless of edit source (portal vs NocoDB) - โœ… **No more "undefined undefined" member names** - โœ… **Proper country flag rendering** - โœ… **Standard database naming conventions** - โœ… **Easier debugging and maintenance** - โœ… **Better API consistency** ## ๐Ÿ†˜ Troubleshooting ### Issue: Members showing "undefined undefined" - **Cause**: NocoDB field names don't match backend expectations - **Solution**: Verify all field names in NocoDB match the snake_case format exactly ### Issue: Country flags not displaying - **Cause**: Nationality field not properly mapped - **Solution**: Ensure `Nationality` field is renamed to `nationality` in NocoDB ### Issue: API errors in console - **Cause**: Field name mismatch between frontend and backend - **Solution**: Update frontend components to use snake_case field names ### Issue: Direct NocoDB edits causing corruption - **Cause**: This was the original problem - should be fixed after migration - **Solution**: This migration specifically addresses this issue --- **๐ŸŽ‰ Once you complete the NocoDB field renaming, the backend will be fully compatible with snake_case field names and the data corruption issue should be completely resolved!**