- Add 10-SUMMARY.md with full execution details - Update STATE.md with quick task 10 entry and session info
4.2 KiB
4.2 KiB
phase, plan, subsystem, tags, dependency_graph, tech_stack, key_files, decisions, metrics
| phase | plan | subsystem | tags | dependency_graph | tech_stack | key_files | decisions | metrics | |||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| quick-10 | 10 | database, library |
|
|
|
|
|
|
Quick Task 10: Fix Duplicate Album Merging Bug
Composite unique constraint on (name, album_artist_credit_id) for release_groups, with migration 5 to rebuild existing tables and entity cache fix to key by album+artist.
Task Summary
| # | Task | Commit | Key Changes |
|---|---|---|---|
| 1 | Fix schema, queries, and regenerate sqlc | 999ab96 |
UNIQUE(name, album_artist_credit_id) in schema; ON CONFLICT updated; GetReleaseGroupByNameAndArtist |
| 2 | Add migration 5 and fix entity cache | d43ba7b |
Migration 5 rebuilds table; cache keys by album+artistID; VIEW drop/recreate |
What Changed
Schema (release_groups.sql)
- Removed
UNIQUEfromname TEXT NOT NULL UNIQUE - Added table-level
UNIQUE(name, album_artist_credit_id)— SQLite treats NULL as unique, so albums without an artist won't collide
Queries (release_groups.sql)
UpsertReleaseGroup:ON CONFLICT(name)→ON CONFLICT(name, album_artist_credit_id)GetReleaseGroupByName→GetReleaseGroupByNameAndArtistwith two params (name + album_artist_credit_id)
Migration 5 (database.go)
- Disables FK checks temporarily
- Drops
track_metadataVIEW (depends on release_groups) - Creates
release_groups_newwith composite unique constraint - Copies data, drops old, renames new
- Recreates both indexes and the
track_metadataVIEW - Re-enables FK checks, bumps user_version to 5
Entity Cache (library.go)
- Cache key changed from
tags.Albumtofmt.Sprintf("%s\x00%d", tags.Album, artistID)where artistID is -1 when no album artist credit exists - All 3 cache access points updated (lookup, cover art update, store after upsert)
Deviations from Plan
Auto-fixed Issues
1. [Rule 1 - Bug] track_metadata VIEW blocking table rename
- Found during: Task 2
- Issue: SQLite refuses to rename
release_groups_newtorelease_groupswhen thetrack_metadataVIEW references the old table - Fix: Drop the VIEW before table rebuild, recreate it after rename (VIEW definition matches embedded schema exactly)
- Files modified: backend/database/database.go
- Commit:
d43ba7b
2. [Rule 1 - Bug] Tests using old cache key format
- Found during: Task 2
- Issue:
TestResolveReleaseGroupandTestResolveReleaseGroup_CacheHituse bare album name as cache key - Fix: Updated test assertions to use composite cache key format (
albumName\x00artistCreditID) - Files modified: backend/library/scan_test.go
- Commit:
d43ba7b
Verification
go build ./...— passesgo test ./...— all 14 test packages passgo vet ./...— no issues- Schema has
UNIQUE(name, album_artist_credit_id)✓ - UpsertReleaseGroup uses
ON CONFLICT(name, album_artist_credit_id)✓ - Migration 5 exists and rebuilds table ✓
- Entity cache key includes artist credit ID ✓
Notes
- Existing databases: Migration 5 changes the constraint but does NOT split already-merged albums. Users must trigger a full library rescan after upgrading.
- NULL handling: SQLite's UNIQUE treats each NULL as distinct, so albums without
album_artist_credit_idwill each get their own row — this is desired behavior.