A restore with categories (full backup, categories only, and "Restore the
backup" of the categories migration) ran DELETE FROM categories, whose
ON DELETE CASCADE took every budget line, template line and adjustment
line with it, while the backup held none: the restore succeeded and left
the budget empty.
- SREF format 3: the two modes that carry the categories now carry
budget_entries, budget_templates (by name, with their lines) and
adjustments (with their lines). collectExportData(mode) gathers the
arrays of each mode for the export and for the pre-migration backup.
- Restore: the profile's budget lines, template lines and adjustment
lines are read and taken out before DELETE FROM categories, in both
formats, through the restore's handle. At format 3 the file's budget
lines and adjustments replace the profile's, each file template is
upserted by name with its lines replaced, and a template absent from
the file keeps its header and its lines whose category comes back.
Below format 3 the lines whose category comes back are put back as
they were.
- The restores of the two category modes take the file's format
(formatVersion), passed by useDataImport and applyBackup.
- Pure validation at the parse and at the head of each restore: a
format newer than this build is refused (newerFormat), a non-integer
or below 1 gets the malformed-file error, and at format 3 a missing
array or a line the tables cannot hold is refused (invalidBudgetRows).
- restoreCategories writes i18n_key.
- Confirmations: willDeleteCategories and willDeleteAll name the budget,
the counts of budget lines, templates and adjustments, and the note of
a backup older than format 3 in the card and in the second
confirmation of "Restore the backup"; categories.reinitializeConfirm
names what "Re-initialize" erases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>