Summary
Add a upsertItems(items, dependencyEdges?) method to the Database class that saves items via INSERT OR REPLACE without calling clearWorkItems(), eliminating the destructive clear-and-replace pattern.
User Story
As a developer working on GitHub integration flows, I want a safe method to update a subset of work items in the database without risking deletion of unrelated items, so that partial-set updates (delegate, push, import) cannot cause data loss.
Acceptance Criteria
db.upsertItems(items) saves each item using saveWorkItem() (INSERT OR REPLACE) without clearing existing items.
- When
dependencyEdges is provided, only edges for the affected item IDs are upserted (not a full clear-and-replace).
- After upserting,
exportToJsonl() and triggerAutoSync() are called exactly once.
- Calling
upsertItems([itemA]) when itemB and itemC exist does not delete itemB or itemC.
- Calling
upsertItems([itemA]) when itemA already exists updates itemA in place.
- Calling
upsertItems([]) with an empty array does not delete any items and does not trigger export/sync.
- The existing
db.import() method is not modified.
Minimal Implementation
- Add
upsertItems(items: WorkItem[], dependencyEdges?: DependencyEdge[]): void to src/database.ts.
- Iterate items calling
this.store.saveWorkItem(item). For edges, upsert only edges where fromId or toId is in the provided items.
- Call
exportToJsonl() and triggerAutoSync() once at the end (skip if items array is empty).
- Add unit tests in
tests/unit/database-upsert.test.ts.
Key Files
src/database.ts:1668-1686 — location for new method (adjacent to existing import())
src/persistent-store.ts:584-586 — clearWorkItems() (what we are avoiding)
src/persistent-store.ts — saveWorkItem() uses INSERT OR REPLACE (the safe path)
Dependencies
None (foundational).
Deliverables
- Source change in
src/database.ts
- Unit test file
tests/unit/database-upsert.test.ts
Summary
Add a
upsertItems(items, dependencyEdges?)method to the Database class that saves items via INSERT OR REPLACE without callingclearWorkItems(), eliminating the destructive clear-and-replace pattern.User Story
As a developer working on GitHub integration flows, I want a safe method to update a subset of work items in the database without risking deletion of unrelated items, so that partial-set updates (delegate, push, import) cannot cause data loss.
Acceptance Criteria
db.upsertItems(items)saves each item usingsaveWorkItem()(INSERT OR REPLACE) without clearing existing items.dependencyEdgesis provided, only edges for the affected item IDs are upserted (not a full clear-and-replace).exportToJsonl()andtriggerAutoSync()are called exactly once.upsertItems([itemA])when itemB and itemC exist does not delete itemB or itemC.upsertItems([itemA])when itemA already exists updates itemA in place.upsertItems([])with an empty array does not delete any items and does not trigger export/sync.db.import()method is not modified.Minimal Implementation
upsertItems(items: WorkItem[], dependencyEdges?: DependencyEdge[]): voidtosrc/database.ts.this.store.saveWorkItem(item). For edges, upsert only edges where fromId or toId is in the provided items.exportToJsonl()andtriggerAutoSync()once at the end (skip if items array is empty).tests/unit/database-upsert.test.ts.Key Files
src/database.ts:1668-1686— location for new method (adjacent to existingimport())src/persistent-store.ts:584-586—clearWorkItems()(what we are avoiding)src/persistent-store.ts—saveWorkItem()uses INSERT OR REPLACE (the safe path)Dependencies
None (foundational).
Deliverables
src/database.tstests/unit/database-upsert.test.ts