fix: restore a backup's split lines with their parent (#518) #531

Merged
maximus merged 4 commits from issue-518-restore-split-ids into main 2026-11-07 18:58:08 +00:00

4 commits

Author SHA1 Message Date
le king fu
1539b42bb3 docs(state): name the manual checks of the backup restore (#518)
All checks were successful
PR Check — Frontend / frontend (pull_request) Successful in 3m2s
One line at the end of "Vérifications dues à la release suivante": the
procedure lives in the body of PR #531, section "Vérifications manuelles
dues (prochaine release)". Links 2 and 3 of the stack extend this line.

Resolves #518

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 21:46:55 -05:00
le king fu
4089eb29d1 docs: the restore of split lines, its new file and the CSV id column (#518)
All checks were successful
PR Check — Frontend / frontend (pull_request) Successful in 3m6s
- CHANGELOG.md / CHANGELOG.fr.md, Fixed / Corrigé: a backup holding a
  split restores, the CSV export starts with an id column, an older CSV
  holding splits is refused, "Rétablir la sauvegarde" says why a file is
  refused.
- User guide and in-app docs (docs.settings.tips, appended last so that
  tips[6], which REVIEW.md cites, keeps its index): the id column and the
  refusal of an older CSV holding splits.
- docs/architecture.md: dataRestoreService.ts row (30 services, 24
  detailed), dataExportService.ts row, the ids of the SREF section, the
  node:sqlite tests.
- Facts the move made false: REVIEW.md line 109 (runRestore lives in
  dataRestoreService.ts), the ADR 0022 table, the tests that execute
  consolidated_schema.sql (REVIEW.md line 197), the service count of
  CLAUDE.md. REVIEW.md line 50, in "Niveaux", names the new file next to
  dataExportService.ts: no level changes, no pattern of the Haut table
  moves (scripts/review-levels.py --check green).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 21:42:56 -05:00
le king fu
4a579f10f9 fix: restore a backup's split lines with their parent (#518)
The restore inserted every transaction without its id and copied the
exported parent_transaction_id. In the same profile the AUTOINCREMENT
sequence survives the DELETE, so the first split line pointed at an id
that no longer existed: FOREIGN KEY constraint failed and the whole
restore rolled back, in both modes and through "Rétablir la sauvegarde".
In a new profile the split lines hung, without a word, off whichever row
had taken their parent's old id.

- attachTransactions puts each row back with its exported id, as the
  categories, suppliers and keywords already are, in two passes: the
  rows without a parent, then the split lines, file order kept in each.
- validateImportedTransactionIds (pure, dataExportService.ts) runs at
  the parse (JSON and CSV) and again at the head of both restores. The
  rows keep their ids only when each bears a safe integer from 1 to
  2147483647 that no other row bears; otherwise SQLite gives new ones,
  and a file holding a split line is refused before anything is deleted
  (SrefValidationError, orphanSplitLines), as is a split line that does
  not name a row of the file without a parent.
- The CSV export starts with an id column; parseImportedCsv reads id and
  parent_transaction_id as /^\d+$/ only and never takes the line number
  for an id, so a CSV exported before the fix that holds a split is
  refused with the message.
- restoreFromBackup no longer wraps an SrefValidationError in a
  RestoreError, and the restore window shows t(e.i18nKey, e.params).

Regression test src/__integration__/restore.test.ts (real services on
node:sqlite, consolidated_schema.sql, foreign keys on): 13 of its 14
cases red on the base, all green here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 21:36:55 -05:00
le king fu
beae42e5ca refactor: move the restore into dataRestoreService.ts (#518)
Pure move, no behaviour change: runRestore, the five restore helpers,
attachTransactions with its host source (HOST_SOURCE_NAME,
HOST_SOURCE_MAPPING, used by it alone) and the three import entry points
leave dataExportService.ts, byte for byte, for the new
src/services/dataRestoreService.ts. The envelope types, the export, the
parse and the validations of the import boundary stay where they were.

useDataImport.ts and categoryRestoreService.ts import the restore from
its new place; dataExportService.test.ts imports it from there, and
category-migration.test.ts mocks it there. Readable by
git diff --color-moved=zebra: only imports and the header of the new
file are not moved lines.

npm run build green; vitest 177 files / 2902 tests green, as on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 21:24:45 -05:00