Skip to content

Add acquisitions table and interface for Trusted Book Providers#12851

Merged
cdrini merged 3 commits into
internetarchive:masterfrom
ronibhakta1:12844/feature/acquisitions-table
Jun 21, 2026
Merged

Add acquisitions table and interface for Trusted Book Providers#12851
cdrini merged 3 commits into
internetarchive:masterfrom
ronibhakta1:12844/feature/acquisitions-table

Conversation

@ronibhakta1

@ronibhakta1 ronibhakta1 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Closes #12844

Feature:
Subtask 2 #12844

Technical

Testing

Screenshot

Stakeholders

@mekarpeles @cdrini

Copilot AI review requested due to automatic review settings June 3, 2026 16:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a new “acquisitions” persistence layer to store trusted book provider metadata per (edition, provider), along with schema and tests.

Changes:

  • Introduces openlibrary.core.acquisitions.Acquisition with query/upsert and edition-merge remapping logic.
  • Adds acquisitions table + indexes to the core Postgres schema.
  • Adds sqlite-backed unit tests for acquisitions CRUD/merge behaviors.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
openlibrary/core/acquisitions.py New model helpers for reading/upserting acquisitions and handling edition merges.
openlibrary/core/schema.sql Adds acquisitions table and supporting indexes in the main schema.
openlibrary/tests/core/test_acquisitions.py Adds sqlite-based tests validating acquisitions behavior.

Comment thread openlibrary/core/acquisitions.py Outdated
Comment thread openlibrary/core/acquisitions.py Outdated
Comment thread openlibrary/tests/core/test_acquisitions.py
Comment thread openlibrary/core/acquisitions.py Outdated
Comment thread openlibrary/core/acquisitions.py
Comment thread openlibrary/core/acquisitions.py Outdated
@mekarpeles

Copy link
Copy Markdown
Member

Thanks for the contribution, @ronibhakta1.

Copilot has been assigned for an initial review.

The linked issue (#12844) hasn't been triaged yet — triage happens on Mondays and Fridays. There are currently 73 open non-draft PRs ahead of yours.

Possible improvements for this PR

  • PR description is incomplete — the Technical and Testing sections are empty. For future PRs, please follow the PR template and provide a description. Here's a draft based on the diff and linked issue:

    This PR implements subtask 2 of Open Library OPDS Registry. Trusted Book Providers (TBP) Ingestion Pipeline. #12844 (Trusted Book Providers ingestion pipeline). It adds the acquisitions table to schema.sql to store provider-specific acquisition metadata keyed on (edition_id, provider_name) with a JSON blob for prices, formats, and other provider data. The Acquisition class in openlibrary/core/acquisitions.py provides get_by_edition, get_by_work, and upsert methods, plus an update_edition_id method that handles edition merges by remapping or dropping conflicting rows. Tests in test_acquisitions.py cover the core read and upsert paths.

  • Proof of testing — the Testing section is empty. Since this is a backend change with no UI, a brief note on how the tests were run (e.g., the pytest command used) would help reviewers.

PR triage checklist (maintainers / Pam)
  • PR description — not empty; explains what the change does and how to verify it
  • References an issue — PR body contains a #NNN reference
    • Linked issue is triaged — has a Priority: * label (not just Needs: Triage)
    • Linked issue is assigned — has at least one assignee
  • Commit history clean — no WIP/fixup/conflict noise; commit messages are meaningful
  • CI passing — no failing check-runs
  • Test cases present — if the change touches substantive logic, test coverage exists or is explained
  • Proof of testing — PR body includes a description of what was tested, a screenshot, or a video

Note

This comment was automatically generated by Pam, Open Library's Project AI Manager, on behalf of @mekarpeles. Pam is designed to provide status visibility, perform basic project management functions and relevant codebase research, and provide actionable feedback so contributors aren't left waiting.

@mekarpeles mekarpeles added the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label Jun 3, 2026
@github-actions github-actions Bot removed the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label Jun 3, 2026

@cdrini cdrini left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Niiiice looks great Roni! I made a few improvements, namely:

  • Use (provider_name, local_id) as the unique constraint for acquisitions to allow for a provider to have multiple acquisitions for the same edition
  • Remove update_edition_id; out-of-scope, should be done once edition merging is implemented
  • Use modern postgres ON CONFLICT for upserting

To avoid git conflict nightmares, I'm actually going to close this one and push my changes to your aggregate PR, #12852 .

Comment thread openlibrary/core/acquisitions.py Outdated
Comment thread openlibrary/core/acquisitions.py Outdated
Comment thread openlibrary/core/acquisitions.py
def get_by_edition(edition_id: int, provider_name: str | None = None) -> list[Acquisition]:
if provider_name is None:
rows: ResultSet = db.query(
"SELECT * FROM acquisitions WHERE edition_id=$edition_id ORDER BY provider_name",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason these are ordered by default?

Suggested change
"SELECT * FROM acquisitions WHERE edition_id=$edition_id ORDER BY provider_name",
"SELECT * FROM acquisitions WHERE edition_id=$edition_id",

Comment thread openlibrary/core/schema.sql Outdated
Comment thread openlibrary/core/schema.sql Outdated
Comment thread openlibrary/tests/core/test_acquisitions.py Outdated
Comment thread openlibrary/core/acquisitions.py
@ronibhakta1

Copy link
Copy Markdown
Contributor Author

That will be a great help. I was expecting a few changes cause I didn't have overall edge cases understanding but covered most of them I know

ronibhakta1 and others added 3 commits June 21, 2026 02:33
- Use (provider_name, local_id) as the unique constraint for
  acquisitions to allow for a provider to have multiple acquisitions for
  the same edition
- Remove update_edition_id; out-of-scope, should be done once edition
  merging is implemented
- Use modern postgres ON CONFLICT for upserting

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cdrini
cdrini force-pushed the 12844/feature/acquisitions-table branch from 4079ba5 to f9f8c9c Compare June 21, 2026 00:35
@cdrini

cdrini commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

Actually, the rebase was pretty simple! So I'm going to go ahead and merge this one as-is, and then force push the rebase to your aggregate PR 👍 And remove the commit I added to that one :P

@cdrini
cdrini merged commit 9eb7687 into internetarchive:master Jun 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Open Library OPDS Registry. Trusted Book Providers (TBP) Ingestion Pipeline.

4 participants