From e766a5d78085060573d86ada40b004341d1e295e Mon Sep 17 00:00:00 2001 From: Deluan Date: Tue, 17 Feb 2026 10:42:05 -0500 Subject: [PATCH] refactor: extend NATURALSORT collation to playlist and radio indexes Signed-off-by: Deluan --- ...000_add_natural_sort_collation_indexes.sql | 22 +++++++++++++++++-- persistence/collation_test.go | 8 +++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/db/migrations/20260216200000_add_natural_sort_collation_indexes.sql b/db/migrations/20260216200000_add_natural_sort_collation_indexes.sql index d9eea1b8b..a92234ba6 100644 --- a/db/migrations/20260216200000_add_natural_sort_collation_indexes.sql +++ b/db/migrations/20260216200000_add_natural_sort_collation_indexes.sql @@ -6,7 +6,7 @@ PRAGMA writable_schema = ON; UPDATE sqlite_master SET sql = replace(sql, 'collate NOCASE', 'collate NATURALSORT') -WHERE type = 'table' AND name IN ('artist', 'album', 'media_file'); +WHERE type = 'table' AND name IN ('artist', 'album', 'media_file', 'playlist', 'radio'); PRAGMA writable_schema = OFF; -- Recreate indexes on order_* and sort expression fields to use NATURALSORT collation. @@ -67,13 +67,22 @@ drop index if exists media_file_sort_album_name; create index media_file_sort_album_name on media_file (coalesce(nullif(sort_album_name,''),order_album_name) collate NATURALSORT); +-- Playlist and radio indexes: recreate to match new NATURALSORT column collation +drop index if exists playlist_name; +create index playlist_name + on playlist (name collate NATURALSORT); + +drop index if exists radio_name; +create index radio_name + on radio (name collate NATURALSORT); + -- +goose Down -- Restore NOCASE column collation PRAGMA writable_schema = ON; UPDATE sqlite_master SET sql = replace(sql, 'collate NATURALSORT', 'collate NOCASE') -WHERE type = 'table' AND name IN ('artist', 'album', 'media_file'); +WHERE type = 'table' AND name IN ('artist', 'album', 'media_file', 'playlist', 'radio'); PRAGMA writable_schema = OFF; -- Restore NOCASE collation indexes @@ -132,3 +141,12 @@ create index media_file_sort_artist_name drop index if exists media_file_sort_album_name; create index media_file_sort_album_name on media_file (coalesce(nullif(sort_album_name,''),order_album_name) collate NOCASE); + +-- Restore playlist and radio indexes +drop index if exists playlist_name; +create index playlist_name + on playlist (name); + +drop index if exists radio_name; +create index radio_name + on radio (name); diff --git a/persistence/collation_test.go b/persistence/collation_test.go index ceaccfb26..61a28c106 100644 --- a/persistence/collation_test.go +++ b/persistence/collation_test.go @@ -32,8 +32,8 @@ var _ = Describe("Collation", func() { Entry("media_file.sort_title", "media_file", "sort_title", "NATURALSORT"), Entry("media_file.sort_album_name", "media_file", "sort_album_name", "NATURALSORT"), Entry("media_file.sort_artist_name", "media_file", "sort_artist_name", "NATURALSORT"), - Entry("playlist.name", "playlist", "name", "NOCASE"), - Entry("radio.name", "radio", "name", "NOCASE"), + Entry("playlist.name", "playlist", "name", "NATURALSORT"), + Entry("radio.name", "radio", "name", "NATURALSORT"), Entry("user.name", "user", "name", "NOCASE"), ) @@ -54,8 +54,8 @@ var _ = Describe("Collation", func() { Entry("media_file.sort_album_name", "media_file", "coalesce(nullif(sort_album_name,''),order_album_name) collate NATURALSORT"), Entry("media_file.sort_artist_name", "media_file", "coalesce(nullif(sort_artist_name,''),order_artist_name) collate NATURALSORT"), Entry("media_file.path", "media_file", "path collate nocase"), - Entry("playlist.name", "playlist", "name collate nocase"), - Entry("radio.name", "radio", "name collate nocase"), + Entry("playlist.name", "playlist", "name collate NATURALSORT"), + Entry("radio.name", "radio", "name collate NATURALSORT"), Entry("user.user_name", "user", "user_name collate nocase"), ) })