Dashboard Migrations: V3 - no-op; remove v3 from DashboardMigrator.ts (#112239)

This commit is contained in:
Haris Rozajac
2025-10-14 18:39:24 -06:00
committed by GitHub
parent 3895849c85
commit e5ef29c202
8 changed files with 260 additions and 20 deletions
@@ -7,7 +7,7 @@ import (
)
const (
MIN_VERSION = 3
MIN_VERSION = 2
LATEST_VERSION = 42
)
@@ -35,6 +35,7 @@ type PanelPluginInfo struct {
func GetMigrations(dsInfoProvider DataSourceInfoProvider) map[int]SchemaVersionMigrationFunc {
return map[int]SchemaVersionMigrationFunc{
3: V3,
4: V4,
5: V5,
6: V6,
@@ -271,19 +271,30 @@ func (r *rowArea) getPanelPosition(panelHeight int, panelWidth int) map[string]i
func getMaxPanelID(rows []interface{}) int {
maxID := 0
hasValidID := false
for _, rowInterface := range rows {
if row, ok := rowInterface.(map[string]interface{}); ok {
if panels, ok := row["panels"].([]interface{}); ok {
for _, panelInterface := range panels {
if panel, ok := panelInterface.(map[string]interface{}); ok {
if id := GetIntValue(panel, "id", 0); id > maxID {
maxID = id
if id := GetIntValue(panel, "id", 0); id > 0 {
hasValidID = true
if id > maxID {
maxID = id
}
}
}
}
}
}
}
// If no valid IDs found, return 0 (matches frontend behavior)
if !hasValidID {
return 0
}
return maxID
}
@@ -0,0 +1,9 @@
package schemaversion
import "context"
// V3 is a no-op migration
func V3(_ context.Context, dashboard map[string]interface{}) error {
dashboard["schemaVersion"] = 3
return nil
}
@@ -0,0 +1,38 @@
package schemaversion_test
import (
"testing"
"github.com/grafana/grafana/apps/dashboard/pkg/migration/schemaversion"
)
func TestV3(t *testing.T) {
tests := []migrationTestCase{
{
name: "v3 no-op migration, updates schema version only",
input: map[string]interface{}{
"title": "V3 No-Op Migration Test Dashboard",
"schemaVersion": 2,
"panels": []interface{}{
map[string]interface{}{
"type": "graph",
"title": "Panel remains unchanged",
"id": 1,
},
},
},
expected: map[string]interface{}{
"title": "V3 No-Op Migration Test Dashboard",
"schemaVersion": 3,
"panels": []interface{}{
map[string]interface{}{
"type": "graph",
"title": "Panel remains unchanged",
"id": 1,
},
},
},
},
}
runMigrationTests(t, tests, schemaversion.V3)
}