Files
grafana/apps/dashboard/pkg/migration/schemaversion/v10.go
T
Haris Rozajac 01ec8e3a4a Dashboard Migrations: V10 - table panel styles.thresholds (#111420)
* migrate to v19

* migrate to v18

* Migration to be verified: v17 Convert minSpan to maxPerRow in panels

* Migration to be verified: 16 Grid layout migration

* Refactor v17 and v19 migrations to use shared helper functions

* Migration to be verified: 15 No-op migration for schema consistency

* Migration to be verified: 14 Shared crosshair to graph tooltip migration

* cleanup

* wip

* complete migration

* fix lint issues

* refactor and test with minimal graph config

* update tests

* migrate to v12

* extract defaults outside the func

* lint

* lint

* add missing showValues prop

* migrate to v11

* migrate to v10

* add test files

* update

* add context and fix latest version

* add context

* add context

* generate snapshots

* v13 should be no-op

* clean up

* fix tests

* add context

* snapshots

* generate snapshots

* fix test

* remove v28

* remove singlestat migraiton from frontend migrator because this is an automigration

* remove unused function

* Remove v24 table plugin logic

* cleanup

* remove plugin version for automigrate as it was used only in v24 and v28 that have been removed

* cleanup

* update snapshot

* update snapshot

---------

Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
2025-10-09 16:36:24 -06:00

98 lines
2.1 KiB
Go

package schemaversion
import "context"
// V10 migration removes the first threshold value from table panel styles when they have 3 or more thresholds.
// This migration aligns with the frontend schema version 10 changes that addressed aliasYAxis changes
// specifically for table panels with threshold configurations.
//
// Background:
// In earlier versions, table panels stored threshold values as arrays with the first element representing
// a baseline value that was not actually used in threshold calculations. This migration removes that
// unused first element to clean up the data structure.
//
// Example before migration:
// {
// "schemaVersion": 9,
// "panels": [
// {
// "type": "table",
// "styles": [
// {
// "thresholds": ["10", "20", "30"]
// },
// {
// "thresholds": ["100", "200", "300"]
// }
// ]
// }
// ]
// }
//
// Example after migration:
// {
// "schemaVersion": 10,
// "panels": [
// {
// "type": "table",
// "styles": [
// {
// "thresholds": ["20", "30"]
// },
// {
// "thresholds": ["200", "300"]
// }
// ]
// }
// ]
// }
func V10(_ context.Context, dashboard map[string]interface{}) error {
dashboard["schemaVersion"] = 10
panels, ok := dashboard["panels"].([]interface{})
if !ok {
return nil
}
for _, p := range panels {
panel, ok := p.(map[string]interface{})
if !ok {
continue
}
// Only process table panels
panelType := GetStringValue(panel, "type")
if panelType != "table" {
continue
}
styles, ok := panel["styles"].([]interface{})
if !ok {
continue
}
// Process each style in the table panel
for _, s := range styles {
style, ok := s.(map[string]interface{})
if !ok {
continue
}
thresholds, ok := style["thresholds"].([]interface{})
if !ok {
continue
}
// Only modify thresholds if they have 3 or more values
if len(thresholds) >= 3 {
// Remove the first threshold value
newThresholds := thresholds[1:]
style["thresholds"] = newThresholds
}
}
}
return nil
}