Dashboard Migrations: V4 - no-op and clean up dead code from DashboardMigrator.ts (#112225)

This commit is contained in:
Haris Rozajac
2025-10-14 14:38:31 -06:00
committed by GitHub
parent 3d112755de
commit 01c4cb1fac
8 changed files with 220 additions and 16 deletions
@@ -7,7 +7,7 @@ import (
)
const (
MIN_VERSION = 4
MIN_VERSION = 3
LATEST_VERSION = 42
)
@@ -35,6 +35,7 @@ type PanelPluginInfo struct {
func GetMigrations(dsInfoProvider DataSourceInfoProvider) map[int]SchemaVersionMigrationFunc {
return map[int]SchemaVersionMigrationFunc{
4: V4,
5: V5,
6: V6,
7: V7,
@@ -0,0 +1,9 @@
package schemaversion
import "context"
// V4 is a no-op migration
func V4(_ context.Context, dashboard map[string]interface{}) error {
dashboard["schemaVersion"] = 4
return nil
}
@@ -0,0 +1,38 @@
package schemaversion_test
import (
"testing"
"github.com/grafana/grafana/apps/dashboard/pkg/migration/schemaversion"
)
func TestV4(t *testing.T) {
tests := []migrationTestCase{
{
name: "v4 no-op migration, updates schema version only",
input: map[string]interface{}{
"title": "V4 No-Op Migration Test Dashboard",
"schemaVersion": 3,
"panels": []interface{}{
map[string]interface{}{
"type": "graph",
"title": "Panel remains unchanged",
"id": 1,
},
},
},
expected: map[string]interface{}{
"title": "V4 No-Op Migration Test Dashboard",
"schemaVersion": 4,
"panels": []interface{}{
map[string]interface{}{
"type": "graph",
"title": "Panel remains unchanged",
"id": 1,
},
},
},
},
}
runMigrationTests(t, tests, schemaversion.V4)
}
@@ -0,0 +1,18 @@
{
"title": "V4 No-Op Migration Test",
"schemaVersion": 3,
"panels": [
{
"id": 1,
"type": "singlestat"
},
{
"id": 2,
"type": "singlestat"
},
{
"id": 3,
"type": "graph"
}
]
}
@@ -0,0 +1,98 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations \u0026 Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"links": [],
"panels": [
{
"autoMigrateFrom": "singlestat",
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"id": 1,
"targets": [
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"refId": "A"
}
],
"type": "stat"
},
{
"autoMigrateFrom": "singlestat",
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"id": 2,
"targets": [
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"refId": "A"
}
],
"type": "stat"
},
{
"autoMigrateFrom": "graph",
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"id": 3,
"targets": [
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"refId": "A"
}
],
"type": "timeseries"
}
],
"refresh": "",
"schemaVersion": 42,
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-6h",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "V4 No-Op Migration Test",
"weekStart": ""
}
@@ -0,0 +1,52 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations \u0026 Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"links": [],
"panels": [
{
"autoMigrateFrom": "singlestat",
"id": 1,
"type": "stat"
},
{
"autoMigrateFrom": "singlestat",
"id": 2,
"type": "stat"
},
{
"autoMigrateFrom": "graph",
"id": 3,
"type": "timeseries"
}
],
"schemaVersion": 4,
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-6h",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "V4 No-Op Migration Test",
"weekStart": ""
}
+1 -1
View File
@@ -2531,7 +2531,7 @@
"count": 2
},
"@typescript-eslint/no-explicit-any": {
"count": 18
"count": 17
}
},
"public/app/features/dashboard/state/DashboardModel.repeat.test.ts": {
@@ -181,20 +181,8 @@ export class DashboardMigrator {
// schema version 4 changes
if (oldVersion < 4 && finalTargetVersion >= 4) {
// move aliasYAxis changes
panelUpgrades.push((panel: any) => {
if (panel.type !== 'graph') {
return panel;
}
each(panel.aliasYAxis, (value, key) => {
panel.seriesOverrides = [{ alias: key, yaxis: value }];
});
delete panel.aliasYAxis;
return panel;
});
// graph migration is handled through the auto migration
// see autoMigrateAngular map in public/app/features/dashboard/state/PanelModel.ts
}
if (oldVersion < 6 && finalTargetVersion >= 6) {