Fix dashboard migration discrepancies between backend and frontend implementations (use toEqual) (#110268)

**Highlights**

* **Single-version migrations**: add `targetVersion` to migrator & model, separate outputs, enforce exact version.
* **Datasource fixes**: include `apiVersion` in tests, empty-string → `{}`, preserve `{}` refs, drop unwanted defaults.
* **Panel defaults & nesting**: only top-level panels get defaults; preserve empty `transformations` context-aware; filter repeated panels.

* **Migration parity**

  * V16: collapsed rows, grid height parsing (`px`).
  * V17: omit `maxPerRow` when `minSpan=1`.
  * V19–V20: cleanup defaults (`targetBlank`, style).
  * V23–V24: template vars + table panel consistency.
  * V28: full singlestat/stat parity, mappings & color.
  * V30–V36: threshold logic, empty refs, nested targets.
* **Save-model cleanup**: replicate frontend defaults/filtering, drop null IDs, metadata, unused props.
* **Testing**: unified suites, dev dashboards (v42), full unit coverage for major migrations.

Co-authored-by: Ivan Ortega [ivanortegaalba@gmail.com](mailto:ivanortegaalba@gmail.com)
Co-authored-by: Dominik Prokop [dominik.prokop@grafana.com](mailto:dominik.prokop@grafana.com)
This commit is contained in:
Ivan Ortega Alba
2025-09-24 12:20:25 +02:00
committed by GitHub
co-authored by Ivan Ortega [ivanortegaalba@gmail.com](mailto:ivanortegaalba@gmail.com) Dominik Prokop [dominik.prokop@grafana.com](mailto:dominik.prokop@grafana.com)
parent 98fd3e8fe9
commit a72e02f88a
298 changed files with 158321 additions and 25235 deletions
@@ -1,5 +1,10 @@
package schemaversion
import (
"strconv"
"strings"
)
// migration_utils.go contains shared utility functions used across multiple schema version migrations.
// GetStringValue safely extracts a string value from a map, returning empty string if not found or not a string
@@ -55,6 +60,14 @@ func ConvertToFloat(value interface{}) (float64, bool) {
return float64(v), true
case int32:
return float64(v), true
case string:
// Handle string values like "700px" - strip px suffix and parse
// This matches frontend behavior: parseInt(height.replace('px', ''), 10)
cleanStr := strings.TrimSuffix(v, "px")
if parsed, err := strconv.ParseFloat(cleanStr, 64); err == nil {
return parsed, true
}
return 0, false
default:
return 0, false
}
@@ -77,3 +90,12 @@ func ConvertToInt(value interface{}) (int, bool) {
return 0, false
}
}
// IsArray checks if a value is an array (slice)
func IsArray(value interface{}) bool {
if value == nil {
return false
}
_, ok := value.([]interface{})
return ok
}