Repository navigation
feat(data): implement core local-first data model, CRUD, and conflict… - #17
Merged
Merged
Conversation
… resolution tests
priyanshuvishwakarma273403
requested review from
Aidmann,
BixbyCodes,
DenizAltunkapan,
GideonBa and
MaximilianRau04
as code owners
August 23, 2026 11:56
MaximilianRau04
left a comment
Contributor
There was a problem hiding this comment.
Solid CRUD/migration layer with good test coverage. One thing worth fixing before this touches real remote data.
Merged
…T and UPDATE dynamic queries to prevent SQL injection
MaximilianRau04
approved these changes
Aug 24, 2026
MaximilianRau04
left a comment
Contributor
There was a problem hiding this comment.
Verified: allowlist is real and enforced in both the INSERT and UPDATE paths, table name isn't attacker-controlled. Approving.
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.
Description
This PR designs and implements the core offline-first storage and reconciliation layer for DocsGraph. It provides the schema migrations, data store class (LocalStore), conflict-resolution mechanics, and automated unit tests required to support clean offline operations and synchronization with the remote backend.
Key Implementation Details
Created tables for all core entities: documents, parties, clauses, and relationships (representing the document graph).
Created an append-only sync_ops table to track client mutations (create, update, delete) and their server synchronization/sequence state (seq).
Added indexes on foreign keys (clauses.document_id), relationship lookups, and sequence tracking to ensure high-performance lookups.
Implemented a unified LocalStore data access layer interacting through the SqliteAdapter interface.
Offline CRUD: Complete transaction-safe CRUD operations for all entities. Any local mutation automatically records a corresponding SyncOp to the log with a seq set to NULL to denote unsynced status.
Auto-Migrations: Implemented the schema verification loop (initialize()) to detect database state and apply pending migrations sequentially.
Documented and implemented a field-level Last-Write-Wins strategy.
When applying incoming remote operations (applyRemoteOps):
If the entity has no pending offline edits (seq IS NULL in sync_ops), remote changes are applied directly, and last_seq advances to the server's sequence number.
If the entity has unsynced offline updates, the local modifications take precedence on a field-by-field level. Fields modified locally offline are preserved, while other non-overlapping fields are updated with remote values.
Remote deletion is ignored if there are unsynced edits, preserving user input.
Introduced a lightweight, memory-efficient in-memory SQLite database simulator.
Added comprehensive unit tests covering:
Idempotent schema migrations and meta version setting.
Full CRUD lifecycle for documents, parties, clauses, and relationships.
Transaction-safe local operational logging.
Server acknowledgment mapping (applyAck updating sequences).
Field-level conflict resolution (verifying overlapping offline edits are preserved while non-overlapping fields are updated).