Files
grafana/apps/dashboard/pkg/migration/schemaversion/v28.go
T
Haris Rozajac 4d3c5d1550 Dashboard Migrations: V13 no-op, remove 28 and v24 as they are autoMigrations; and remove dead code from DashboardMigrator (#110008)
* 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

* extract defaults outside the func

* lint

* lint

* add missing showValues prop

* add context and fix latest version

* generate snapshots

* v13 should be no-op

* clean up

* 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

---------

Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
2025-10-09 11:14:02 -06:00

72 lines
1.9 KiB
Go

package schemaversion
import (
"context"
)
// V28 removes deprecated variable properties (tags, tagsQuery, tagValuesQuery, useTags)
//
// Example before migration:
//
// {
// "templating": {
// "list": [
// { "name": "var1", "tags": ["tag1"], "tagsQuery": "query", "tagValuesQuery": "values", "useTags": true }
// ]
// }
// }
//
// Example after migration:
//
// {
// "templating": {
// "list": [
// { "name": "var1" }
// ]
// }
// }
func V28(_ context.Context, dashboard map[string]interface{}) error {
dashboard["schemaVersion"] = 28
// Remove deprecated variable properties
if templating, ok := dashboard["templating"].(map[string]interface{}); ok {
if list, ok := templating["list"].([]interface{}); ok {
for _, v := range list {
if variable, ok := v.(map[string]interface{}); ok {
removeDeprecatedVariableProperties(variable)
}
}
}
}
return nil
}
// removeDeprecatedVariableProperties removes deprecated properties from variables
// Based on DashboardMigrator.ts v28 migration: variable property cleanup
func removeDeprecatedVariableProperties(variable map[string]interface{}) {
// Remove deprecated properties
delete(variable, "tags")
// Only remove tagsQuery if it's a non-empty string (matches frontend behavior)
if tagsQuery, exists := variable["tagsQuery"]; exists {
if str, ok := tagsQuery.(string); ok && str != "" {
delete(variable, "tagsQuery")
}
}
// Only remove tagValuesQuery if it's a non-empty string (matches frontend behavior)
if tagValuesQuery, exists := variable["tagValuesQuery"]; exists {
if str, ok := tagValuesQuery.(string); ok && str != "" {
delete(variable, "tagValuesQuery")
}
}
// Only remove useTags if it's a truthy boolean (matches frontend behavior)
if useTags, exists := variable["useTags"]; exists {
if val, ok := useTags.(bool); ok && val {
delete(variable, "useTags")
}
}
}