feat(library): keep one saved entry per book across editions and languages #3
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/one-entry-per-book"
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?
Summary
Implements One saved entry per book (
docs/EXPLORATION_IDEAS.md): a saved book is now its Open Library work. Edition and language are display metadata (preferred title, cover, language, source edition), not separate library identities.Changes
library_bookunique key(user_id, work_id, language)→(user_id, work_id).languagestays as metadata of the preferred edition.0008reconciles existing same-work rows per user (rules below), then adds the new constraint.saveBook): conflicts on(user, work). Saving another edition of a saved work keeps the entry and its lists, and makes that edition the displayed one.bookSearchIdentityis now the work id, so a result in any language shows as saved, with its lists.BookLibraryControls):PUT /api/library/books/:id, which only changes memberships. Editing lists from a French result no longer quietly replaces the saved English edition.mergeImportedBook): finds the saved book by work only, so any edition or language merges into the existing entry. Existing metadata wins, as before.docs/goodreads-import.mdis updated. Import matching already grouped candidates by work.Decisions
Identity rule: one entry per
(user, Open Library work). Merging distinct works is left to the later "Canonical book mapping" feature.Migration: which row's metadata wins:
recommendation_preference.language), if set and present.The kept row's id, title, cover, language and source edition stay together, so the displayed edition is coherent. Fields missing on the kept row (cover, year, authors, author ids, series) are filled in from the others. The rating snapshot with the most ratings wins. The earliest
created_atis kept so library order stays stable.Migration: conflicting statuses: custom list memberships are unioned. Among reading statuses, the most advanced one wins: Read > Reading > To read. No reread or progress semantics are inferred.
Import links:
library_import_item.book_idpointing at merged rows is repointed to the kept row, so repeat imports still reuse prior confirmed matches.Metadata on save: an explicit save or "Use this edition" sets the displayed edition. List edits never change it. Imports never override it, only fill in gaps.
Verification
pnpm lint-fullpasses on every commit.Migration: tested on a clone of the dev DB, seeded with three duplicate groups:
Results: 66 rows → 63 rows. Expected rows kept (preference language, else earliest). Statuses resolved to Read/Reading as per the rule. Custom lists unioned. Missing cover/year filled in. Highest-count rating kept. Earliest date kept. Import items repointed. New unique constraint in place.
Browser (dev server, test account):
Demo
Demo video (43 s): save "Dune messiah" in English → search in French shows "Le Messie de Dune" as the same saved book → edit lists keeps the edition → "Use this edition" → library shows one entry.
Review of
master...HEAD(four commits).Nit picks — 1 optional finding
app/components/book/BookLibraryControls.vue:56: Capture whether the book was already saved before awaitingprops.mutate(). The mutation refreshes the library before returning (app/composables/usePrivateLibrary.ts:12–13), which updatesprops.savedon the search/bibliography card. Consequently, saving a new book can report “Lists updated.” instead of “Saved to your library.” Use the pre-mutation saved state to choose the success message. Optional; does not need to block merge.Important: 0. Pre-existing: 0. Security: 0. No added Open Library requests found. Reviewed migration ordering, multi-row duplicate groups, membership constraints, metadata selection, import repointing, and work-based saved indicators. Null book languages and orphan memberships are prevented by the existing schema. Database inspection was read-only; migration execution was not repeated.
pnpm lint-fullpasses.Fixed the nit in
299f1c9: the saved state is captured before the mutation, so a new save shows “Saved to your library.” Master had no new commits, so no rebase or migration renumbering was needed.