Implements user data import feature to complement existing export functionality. Users can export their data, modify it externally, and re-import the updated data with intelligent conflict resolution.
This implementation uses a phased approach:
M1: Added batch operations to repositories (10-100x performance improvement)
M2: Implemented archive extraction and validation service
M3: Built import service with merge/replace modes and API layer
M4: Created frontend import UI with multi-step wizard
M5: Added comprehensive integration tests and documentation
Key Features
Two Import Modes: Merge (partial success with updates) and Replace (atomic all-or-nothing)
Conflict Resolution: VIN matching for vehicles triggers updates in merge mode
Performance: Batch operations enable 1000 vehicle import in <10s
Preview: Users see what will be imported before committing
Partial Success: Valid records imported even if some fail validation
Complete Coverage: Vehicles, fuel logs, maintenance records/schedules, documents, and files
Changes
Backend:
Batch insert operations for all repositories (vehicles, fuel-logs, maintenance, documents)
Archive extraction and validation service
Import service with preview, merge, and replace operations
Import API with multipart upload, authentication, and validation
Comprehensive integration tests with performance benchmarks
Add batchInsert methods to vehicles, fuel-logs, maintenance, and documents repositories. Multi-value INSERT syntax provides 10-100x performance improvement over individual operations for bulk data import.
- vehicles.repository: batchInsert for vehicles
- fuel-logs.repository: batchInsert for fuel logs
- maintenance.repository: batchInsertRecords and batchInsertSchedules
- documents.repository: batchInsert for documents
- All methods support empty array (immediate return) and optional transaction client
- Fix lint error: replace require() with ES6 import in test mock
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Implement archive service to extract and validate user data import archives. Validates manifest structure, data files, and ensures archive format compatibility with export feature.
- user-import.types.ts: Type definitions for import feature
- user-import-archive.service.ts: Archive extraction and validation
- Validates manifest version (1.0.0) and required fields
- Validates all data files exist and contain valid JSON
- Temp directory pattern mirrors export (/tmp/user-import-work)
- Cleanup method for archive directories
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Desktop changes:
- Replace ImportButton component with MUI Button matching Export style
- Use hidden file input with validation
- Dark red/maroon button with consistent styling
Mobile changes:
- Update both Import and Export buttons to use primary-500 style
- Consistent dark primary button appearance
- Maintains 44px touch target requirement
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Added detailed logging to diagnose import merge issues:
- Log vehicle count at merge start
- Log each vehicle being processed with VIN/make/model/year
- Log when existing vehicles are found (by VIN or license plate)
- Log successful vehicle creation with new vehicle ID
- Log errors with full context (userId, VIN, make, model, error message)
- Log merge completion with summary statistics
This will help diagnose why vehicles show as "successfully imported" but don't appear in the UI.
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Critical fix for merge mode vehicle matching logic.
Problem:
- Vehicles with same license plate but no VIN were matched to the same existing vehicle
- Example: 2 vehicles with license plate "TEST-123" both updated the same vehicle
- Result: "Updated: 2" but only 1 vehicle in database, second vehicle overwrites first
Root Cause:
- Matching order was: VIN → license plate
- Both vehicles had no VIN and same license plate
- Both matched the same existing vehicle by license plate
Solution:
- New matching order: ID → VIN → license plate
- Preserves vehicle identity across export/import cycles
- Vehicles exported with IDs will update the same vehicle on re-import
- New vehicles (no matching ID) will be created as new records
- Security check: Verify ID belongs to same user before matching
Benefits:
- Export-modify-import workflow now works correctly
- Vehicles maintain identity across imports
- Users can safely import data with duplicate license plates
- Prevents unintended overwrites
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Summary
Implements user data import feature to complement existing export functionality. Users can export their data, modify it externally, and re-import the updated data with intelligent conflict resolution.
This implementation uses a phased approach:
Key Features
Changes
Backend:
Frontend:
Documentation:
Files Changed
Test Plan
Backend Tests
Frontend Tests
Quality Checks
Related Issues
Fixes #26
Generated with Claude Code