← Blog Home

OCR & Portfolio Import

#5 OCR Import Broke My Journal: Fixing Merge Logic Without Deleting History

· Build Log

OCR import moved from destructive replace behavior to append/merge with dedup safety.

OCR merge logictrade journal preservationdedup key

1) TL;DR

2) What I Tried

The first OCR flow optimized for quick import throughput.

3) What Broke

Existing journal and coach data disappeared after OCR imports.

4) Root Cause

Import logic replaced arrays in storage instead of merging into current state.

5) Before (Code Path)

public/buysell.html - trades = ocrTrades - storage overwrite with OCR array - render path lost prior records

6) After (Code Path)

public/buysell.html + normalizeOcrRowToTrade() + mergeTradesPreservingExisting() + mergeJournalPreservingExisting()

7) Evidence (Git History)

8) What I Learned

Import-by-default should be append-safe when users keep historical trading journals.

9) Frequently Asked Questions

Why is replace dangerous here?

It destroys context used by downstream journal and AI coach widgets.

How is duplicate prevention handled?

By composite keys across symbol, quantity, price, date, and source.

What changed in UX?

Existing records remain visible while imported records are added safely.