Files
grafana/apps/dashboard/pkg/migration/schemaversion/migrations.go
T
Ivan Ortega Alba 09bbdfe8ab Dashboard Migrations: V35 ensures X-axis visibility in timeseries (#106633)
* Add datasource info provider

* Dashboards: Support schemaVersion v35 migration in backend

* update go mods

---------

Co-authored-by: Todd Treece <360020+toddtreece@users.noreply.github.com>
Co-authored-by: Haris Rozajac <haris.rozajac12@gmail.com>
Co-authored-by: Stephanie Hingtgen <stephanie.hingtgen@grafana.com>
2025-06-17 10:38:48 +02:00

55 lines
931 B
Go

package schemaversion
import (
"strconv"
)
const (
MIN_VERSION = 34
LATEST_VERSION = 41
)
type SchemaVersionMigrationFunc func(map[string]interface{}) error
type DataSourceInfo struct {
Default bool
UID string
Name string
Type string
ID int64
APIVersion string
}
type DataSourceInfoProvider interface {
GetDataSourceInfo() []DataSourceInfo
}
func GetMigrations(dsInfoProvider DataSourceInfoProvider) map[int]SchemaVersionMigrationFunc {
return map[int]SchemaVersionMigrationFunc{
35: V35,
36: V36(dsInfoProvider),
37: V37,
38: V38,
39: V39,
40: V40,
41: V41,
}
}
func GetSchemaVersion(dash map[string]interface{}) int {
if v, ok := dash["schemaVersion"]; ok {
switch v := v.(type) {
case int:
return v
case float64:
return int(v)
case string:
if version, err := strconv.Atoi(v); err == nil {
return version
}
return 0
}
}
return 0
}