Backup entry-restore is broken - INSERT omits NOT NULL project_id and uses invalid certainty #84
Labels
No labels
bug
duplicate
enhancement
future
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
rbrooks/TeaLeaves#84
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Severity: High · Confidence: High · Effort: S · Category: code
Evidence
api/src/services/backup.ts:407-424-applyRestoreEntryINSERT omitsproject_id; defaultscertaintyto'possible'.api/src/db/migrations/026_projects.sql:97-entries.project_id SET NOT NULL, no default.api/src/db/migrations/002_entries_tags_audit.sql:10-certainty CHECK IN ('confirmed','likely','speculative').Problem
The restore INSERT does not supply
project_id(NOT NULL, no default → Postgres23502), and itscertaintyfallback'possible'is not in the CHECK set (?23514). Every staged-entry apply throws.Impact
Granular entry restore is completely broken. It fails loudly (400 per entry), but at exactly the moment recovery is needed. Directly violates the spec's first principle ("her data is irreplaceable").
Fix
Source
project_idfrom the stagedentry_data(the COPY parser already captures it) or require a target project id; change thecertaintyfallback to a valid value ('confirmed'). Add a restore integration test.Acceptance criteria
appliedwith a validproject_id.Related: backup can also silently stop (F-09).
Filed from the 2026-07-15 codebase audit. Full report:
docs/.internal/report-2026-07-15.md(gitignored).Fixed in
b640072(v7.1.0 wave 3).applyRestoreEntrynow:project_id(NOT NULL with no default since migration 026 → was throwing23502on every apply). Sourced from the stagedentry_data, with a guard: if that project no longer exists (or was soft-deleted) it falls back to the user's active/default project viadefaultProjectId(userId), and throws a clear error only if the user has no project at all.certaintyagainst the real CHECK set (confirmed|likely|speculative, migration 002). The old'possible'fallback wasn't in that set →23514. Invalid/missing values now default to'confirmed'.Acceptance criteria:
appliedwith a validproject_id.api/src/test/integration/backup.test.ts›restore apply (#84):project_idandcertainty: 'likely', and the staging row flips toapplied;project_idand the invalid'possible'certainty) and asserts it now applies, falling back to the active project withcertainty: 'confirmed'.Verified on the dev server: 234/234 tests pass. CI green.
Related: #86 (backup can also silently stop) fixed in the same wave.