feat(library): keep one saved entry per book across editions and languages #3

Merged
chris-paganon merged 5 commits from feat/one-entry-per-book into master 2026-11-14 18:16:57 +00:00

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

  • Schema: library_book unique key (user_id, work_id, language) → (user_id, work_id). language stays as metadata of the preferred edition.
  • Migration 0008 reconciles existing same-work rows per user (rules below), then adds the new constraint.
  • Saving (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.
  • Search / bibliography / recommendation resolve dialog: bookSearchIdentity is now the work id, so a result in any language shows as saved, with its lists.
  • Card controls (BookLibraryControls):
    • "Edit lists" on a saved book now uses PUT /api/library/books/:id, which only changes memberships. Editing lists from a French result no longer quietly replaces the saved English edition.
    • When the result is a different edition than the saved one, the card shows "Saved as another edition: “…” · Language" and a Use this edition button that switches the displayed edition. The lists are kept.
  • Goodreads import (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.md is updated. Import matching already grouped candidates by work.
  • Recommendation exclusion: already keyed by work id, no change needed.

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:

    1. The row in the user's recommendation reading language (recommendation_preference.language), if set and present.
    2. Otherwise, the earliest saved row.
    3. Ties are broken by id.

    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_at is 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_id pointing 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-full passes on every commit.

  • Migration: tested on a clone of the dev DB, seeded with three duplicate groups:

    • an English-preference row added later than an unknown-language row;
    • an earlier Spanish row with no cover or status;
    • a French row with Read + a custom list next to a To-read original.

    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):

    1. Saved "Dune messiah" (English) to To read + a custom list.
    2. Searched in French: "Le Messie de Dune" showed the same lists and "Saved as another edition: “Dune messiah” · English".
    3. Edit lists → Reading kept the English edition.
    4. "Use this edition" switched it to French.
    5. The library shows a single entry (French, Reading + custom list). The DB has one row for the work.

Demo

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.

## 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 - **Schema**: `library_book` unique key `(user_id, work_id, language)` → `(user_id, work_id)`. `language` stays as metadata of the preferred edition. - **Migration `0008`** reconciles existing same-work rows per user (rules below), then adds the new constraint. - **Saving** (`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. - **Search / bibliography / recommendation resolve dialog**: `bookSearchIdentity` is now the work id, so a result in any language shows as saved, with its lists. - **Card controls** (`BookLibraryControls`): - "Edit lists" on a saved book now uses `PUT /api/library/books/:id`, which only changes memberships. Editing lists from a French result no longer quietly replaces the saved English edition. - When the result is a different edition than the saved one, the card shows "Saved as another edition: “…” · Language" and a **Use this edition** button that switches the displayed edition. The lists are kept. - **Goodreads import** (`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.md` is updated. Import matching already grouped candidates by work. - **Recommendation exclusion**: already keyed by work id, no change needed. ## 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**: 1. The row in the user's recommendation reading language (`recommendation_preference.language`), if set and present. 2. Otherwise, the earliest saved row. 3. Ties are broken by id. 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_at` is 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_id` pointing 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-full` passes on every commit. - **Migration**: tested on a clone of the dev DB, seeded with three duplicate groups: - an English-preference row added later than an unknown-language row; - an earlier Spanish row with no cover or status; - a French row with Read + a custom list next to a To-read original. 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): 1. Saved "Dune messiah" (English) to To read + a custom list. 2. Searched in French: "Le Messie de Dune" showed the same lists and "Saved as another edition: “Dune messiah” · English". 3. Edit lists → Reading kept the English edition. 4. "Use this edition" switched it to French. 5. The library shows a single entry (French, Reading + custom list). The DB has one row for the work. ## Demo ![demo](https://forgejo.chrispaganon.com/attachments/81915653-ef25-47f2-9b5e-ade307193982) [Demo video (43 s)](https://forgejo.chrispaganon.com/attachments/81915653-ef25-47f2-9b5e-ade307193982): 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.
Language and edition become display metadata of the saved work. The
migration merges existing same-work rows per user, keeping list
memberships, the most advanced reading status and import links.
Author
Owner

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 awaiting props.mutate(). The mutation refreshes the library before returning (app/composables/usePrivateLibrary.ts:12–13), which updates props.saved on 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-full passes.

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 awaiting `props.mutate()`. The mutation refreshes the library before returning (`app/composables/usePrivateLibrary.ts:12–13`), which updates `props.saved` on 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-full` passes.
Author
Owner

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.

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.
chris-paganon deleted branch feat/one-entry-per-book 2026-11-14 18:16:57 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
chris-paganon/chrisp-books!3
No description provided.