mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-21 09:29:46 +01:00
When PID.Artist spec changes, existing artist IDs differ from newly-computed ones. Without remapping, all annotations (starred, ratings, play counts) become orphaned. This change builds an artistIDMap during phase 1 and reassigns annotations on persist, mirroring the existing albumIDMap flow. The migration logic is gated on the previous spec being non-empty and different from the current spec, so the default "name" spec (byte-identical to the historical hardcoded artistID) triggers no remapping on upgrade.
49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package scanner
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/navidrome/navidrome/conf/configtest"
|
|
"github.com/navidrome/navidrome/model"
|
|
"github.com/navidrome/navidrome/tests"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("phaseFolders", func() {
|
|
Describe("Artist re-PID migration", func() {
|
|
var (
|
|
artRepo *tests.MockArtistRepo
|
|
p *phaseFolders
|
|
)
|
|
|
|
BeforeEach(func() {
|
|
DeferCleanup(configtest.SetupConfig())
|
|
artRepo = tests.CreateMockArtistRepo()
|
|
if artRepo.ReassignAnnotationCalls == nil {
|
|
artRepo.ReassignAnnotationCalls = map[string]string{}
|
|
}
|
|
p = &phaseFolders{ctx: context.Background(), state: &scanState{}}
|
|
})
|
|
|
|
It("calls ReassignAnnotation when persisting an artist whose ID changed", func() {
|
|
oldID := "old-id"
|
|
newID := "new-id"
|
|
idMap := map[string]string{newID: oldID}
|
|
artist := model.Artist{ID: newID, Name: "Foo"}
|
|
|
|
Expect(p.persistArtist(artRepo, &artist, idMap)).To(Succeed())
|
|
Expect(artRepo.ReassignAnnotationCalls).To(HaveKeyWithValue(oldID, newID))
|
|
// Mapping should be removed after successful reassignment
|
|
Expect(idMap).ToNot(HaveKey(newID))
|
|
})
|
|
|
|
It("does not call ReassignAnnotation when no mapping exists", func() {
|
|
idMap := map[string]string{}
|
|
artist := model.Artist{ID: "some-id", Name: "Foo"}
|
|
|
|
Expect(p.persistArtist(artRepo, &artist, idMap)).To(Succeed())
|
|
Expect(artRepo.ReassignAnnotationCalls).To(BeEmpty())
|
|
})
|
|
})
|
|
})
|