Repository navigation
fix(metadata): match the personal collection key when merging duplicate items - #2360
Conversation
…te items Migration 156 added sub_item_id to the primary key of user_personal_collection_items, but the merge step still named the old three-column conflict target. Postgres rejected the statement at plan time, so every duplicate-item merge rolled back, even when the source item had no collection rows. Carry sub_item_id through the merge so whole-item entries and episode entries for the same collection collapse onto the canonical item separately. Add database tests that run the full merge against a migrated schema. Closes Silo-Server#2299
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to No merge-blocking issue was established. The collection merge can proceed through normal checks. Pre-merge checks ·
|
|
This restores duplicate consolidation and changes which items remain in collections, so |
…uplicates With the merge running again, two of its steps lost data. The provider-ID step inserted a copy of each source ID for the canonical item with ON CONFLICT DO NOTHING, but the source row itself holds the unique (provider, provider_id, item_type) key, so every copy was skipped and the next step deleted the source IDs. Move the rows for providers the canonical item has no ID for instead. Ebook annotations were never moved, so deleting the source item cascaded and removed its highlights, notes, and bookmarks. Move them to the canonical item.
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Problem
Closes #2299
Related issue: N/A
Validation tasks: changes #1210 C1; changes #1211 C1
Merging a duplicate media item into its canonical item always failed, so items that share a provider ID were never merged. This breaks the provider-ID integrity repair, and an Identify that picks IDs already owned by another item. This change makes the merge use the personal collection table's current key, so the merge completes, and fixes two steps that would have lost data once merges commit again.
Migration 156 added
sub_item_idto the primary key ofuser_personal_collection_items, which is now(user_id, collection_id, media_item_id, sub_item_id). The "merge personal collection items" step incanonicalizeMediaItemReferencesTxstill named the old three-columnON CONFLICTtarget. Postgres rejects that when it plans the statement (42P10), so every merge rolled back, even when the source item had no collection rows.Approach
The merge step now carries
sub_item_idthrough the insert, the grouping and the conflict target. When the source and canonical items are in the same collection with the samesub_item_id, they collapse into one entry that keeps the lower position and the earlieradded_at, as before. Whole-item entries (sub_item_id = '') and podcast episode entries stay separate.With the merge running again, two other steps would have lost data:
ON CONFLICT DO NOTHING. The source row itself holds the unique(provider, provider_id, item_type)key, so every copy was skipped and the next step deleted the source IDs. The step now moves the rows for providers the canonical item has no ID for; the canonical item keeps its own ID for the rest.The new database tests run the full merge step list against a migrated schema. They cover a source with no collection rows (the reported failure), a collection both items are in, a collection only the source is in, episode entries, provider IDs, and ebook annotations. Because the no-rows test runs every merge step, it also checks that the other steps' conflict targets match real keys. The commit also removes the
t.SkipthatTestIdentifyConflictMergeMarksTheSurvivorPostgrescarried until this issue was fixed, so the Identify conflict-merge path is tested again.Validation
make lint-changed, and the contract, fixture, route and docs checks) passes.make test-gothe touched package passes. The failures on the test machine are ininternal/apiv2,internal/jellycompat,internal/playbackandinternal/transcodenode(GPU and FFmpeg probe tests, macOS-specific tests) andinternal/metadata/nfo(case-insensitive filesystem), and they fail the same way onmain.TestIdentifyConflictMergeMarksTheSurvivorPostgrespass against a fully migrated PostgreSQL 18 database. The new tests fail onmain: the collection tests with the42P10error, the provider-ID and annotation tests by losing the rows. They run only whenSILO_TEST_DATABASE_URLis set.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-2360/
Surface and build: web app Match Item and a personal collection at desktop and phone width, before on
mainat 8ddbc8d, after at 7df8f12.Risks
Duplicate merges start committing again on existing servers. They now keep provider IDs and annotations that the old steps dropped, but every other merge step runs in production for the first time since migration 156.
Checklist
AI Disclosure
t.Skipfor this issue, was fixed.