From 40976bb1e4a80bb452ada080f7c015d14d1cf7b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mustafa=20Sencer=20=C3=96zcan?= <32759850+mustafasencer@users.noreply.github.com> Date: Wed, 17 Dec 2025 13:48:19 +0100 Subject: [PATCH] fix: preserve the order when migrating the playlists (#115485) fix: preserve the order --- .../apis/dashboard/legacy/sql_dashboards.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/registry/apis/dashboard/legacy/sql_dashboards.go b/pkg/registry/apis/dashboard/legacy/sql_dashboards.go index 7df610f375e..0a496e4667b 100644 --- a/pkg/registry/apis/dashboard/legacy/sql_dashboards.go +++ b/pkg/registry/apis/dashboard/legacy/sql_dashboards.go @@ -501,7 +501,7 @@ func (a *dashboardSqlAccess) MigratePlaylists(ctx context.Context, orgId int64, return nil, err } - // Group playlist items by playlist ID + // Group playlist items by playlist ID while preserving order type playlistData struct { id int64 uid string @@ -512,7 +512,8 @@ func (a *dashboardSqlAccess) MigratePlaylists(ctx context.Context, orgId int64, updatedAt int64 } - playlists := make(map[int64]*playlistData) + playlistIndex := make(map[int64]int) // maps playlist ID to index in playlists slice + playlists := []*playlistData{} var currentID int64 var orgID int64 var uid, name, interval string @@ -527,7 +528,8 @@ func (a *dashboardSqlAccess) MigratePlaylists(ctx context.Context, orgId int64, } // Get or create playlist entry - pl, exists := playlists[currentID] + idx, exists := playlistIndex[currentID] + var pl *playlistData if !exists { pl = &playlistData{ id: currentID, @@ -538,7 +540,10 @@ func (a *dashboardSqlAccess) MigratePlaylists(ctx context.Context, orgId int64, createdAt: createdAt, updatedAt: updatedAt, } - playlists[currentID] = pl + playlistIndex[currentID] = len(playlists) + playlists = append(playlists, pl) + } else { + pl = playlists[idx] } // Add item if it exists (LEFT JOIN can return NULL for playlists without items) @@ -554,7 +559,7 @@ func (a *dashboardSqlAccess) MigratePlaylists(ctx context.Context, orgId int64, return nil, err } - // Convert to K8s objects and send to stream + // Convert to K8s objects and send to stream (order is preserved) for _, pl := range playlists { playlist := &playlistv0.Playlist{ TypeMeta: metav1.TypeMeta{