**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)
58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
package schemaversion
|
|
|
|
import "context"
|
|
|
|
// V29 migrates query variables to ensure their refresh property is set to 1 (on dashboard load)
|
|
// if it is not 1 or 2, and clears their options array if present.
|
|
//
|
|
// Example before migration:
|
|
//
|
|
// "templating": {
|
|
// "list": [
|
|
// { "type": "query", "refresh": 0, "options": [{ "text": "A", "value": "A" }] },
|
|
// { "type": "query", "refresh": 2, "options": [{ "text": "B", "value": "B" }] },
|
|
// { "type": "query", "options": [{ "text": "C", "value": "C" }] }
|
|
// ]
|
|
// }
|
|
//
|
|
// Example after migration:
|
|
//
|
|
// "templating": {
|
|
// "list": [
|
|
// { "type": "query", "refresh": 1, "options": [] },
|
|
// { "type": "query", "refresh": 2, "options": [] },
|
|
// { "type": "query", "refresh": 1, "options": [] }
|
|
// ]
|
|
// }
|
|
func V29(_ context.Context, dashboard map[string]interface{}) error {
|
|
dashboard["schemaVersion"] = 29
|
|
|
|
templating, ok := dashboard["templating"].(map[string]interface{})
|
|
if !ok {
|
|
return nil
|
|
}
|
|
list, ok := templating["list"].([]interface{})
|
|
if !ok {
|
|
return nil
|
|
}
|
|
for _, v := range list {
|
|
variable, ok := v.(map[string]interface{})
|
|
if !ok {
|
|
continue
|
|
}
|
|
if variable["type"] != "query" {
|
|
continue
|
|
}
|
|
// Set refresh to 1 if not 1 or 2
|
|
refreshInt := GetIntValue(variable, "refresh", 0)
|
|
if refreshInt != 1 && refreshInt != 2 {
|
|
variable["refresh"] = 1
|
|
}
|
|
// Clear options if they have content (matches frontend behavior)
|
|
if options, hasOptions := variable["options"].([]interface{}); hasOptions && len(options) > 0 {
|
|
variable["options"] = []interface{}{}
|
|
}
|
|
}
|
|
return nil
|
|
}
|