feat(sync,schema,db): unify primary keys on String/UUID format, revert casting bypasses, and add pull-sync conflict protection - #18
Merged
Conversation
…te records to preserve local-only credential fields
…s across all workspace scoped models
…e and update actions
…itory to correctly match legacy ObjectId documents
…String/UUID format, revert casting bypasses, and add pull-sync conflict protection
…alized) and remote API (uppercase) during sync
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
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.
📝 Summary of Changes
This PR unifies the primary key format across the hybrid architecture of LeadForge OS. By transitioning all MongoDB collections from binary
ObjectIdidentifiers to client-authoritativeString(UUID/ObjectId-string) values, we align the cloud schemas with the local SQLite schemas, removing the need for query-casting bypasses and preventing key mismatches during bi-directional synchronization.Additionally, this PR upgrades the local SQLite repository to protect un-synced client-side modifications from being discarded, and introduces client-side casing translation for campaign statuses to conform to API specifications.
🛠️ Key Technical Details
1. Database Schema Overrides
workspacePluginand system-level schemas (User,Workspace,BetaApplicant) to map_id: { type: String }with standard default generators._id: stringon Mongoose document interfaces utilizingmongoose.Document<any>constraints. This allows Mongoose to accept string IDs while preserving compile-time type-safety.objectIdFieldandobjectIdFieldNullableschemas in@leadforge/schemato support any string input, ensuring client-generated UUIDs do not fail server-side validation.2. Cleaned Up Repository Code
BaseRepository(apps/api/src/repositories/base/base.repository.ts) andOutreachService(apps/api/src/services/outreach/outreach.service.ts) back to standard, typed Mongoose helper methods (findOne,findOneAndUpdate,deleteOne), as Mongoose now natively handles string query filters correctly.3. Sync Conflict Protection
LocalCRMRepository.saveManyto check forexisting.syncStatus === 'pending'. If a local record contains un-synced mutations, the sync engine will skip overwriting it during a remote pull, protecting local offline edits.4. Client-First Status Casing Mapper
SyncEngine(apps/desktop/src/main/services/sync-engine.ts) to handle campaign status formatting differences:'Draft' | 'Active') to API-required uppercase ('DRAFT' | 'ACTIVE') on push.🧪 Verification & Evidence
turbo run buildacross all workspace modules successfully with zero compilation errors.leadforge-os. All SQLite workspace database tables were successfully wiped. Both databases migrated cleanly on server startup.