01ec8e3a4a
* 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>
90 lines
1.4 KiB
Go
90 lines
1.4 KiB
Go
package schemaversion
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
const (
|
|
MIN_VERSION = 9
|
|
LATEST_VERSION = 42
|
|
)
|
|
|
|
type SchemaVersionMigrationFunc func(context.Context, map[string]interface{}) error
|
|
|
|
type DataSourceInfo struct {
|
|
Default bool
|
|
UID string
|
|
Name string
|
|
Type string
|
|
ID int64
|
|
APIVersion string
|
|
}
|
|
|
|
type DataSourceInfoProvider interface {
|
|
// GetDataSourceInfo returns a list of all data sources with their info
|
|
// The context must have the namespace in it
|
|
GetDataSourceInfo(ctx context.Context) []DataSourceInfo
|
|
}
|
|
|
|
type PanelPluginInfo struct {
|
|
ID string
|
|
Version string
|
|
}
|
|
|
|
func GetMigrations(dsInfoProvider DataSourceInfoProvider) map[int]SchemaVersionMigrationFunc {
|
|
return map[int]SchemaVersionMigrationFunc{
|
|
10: V10,
|
|
11: V11,
|
|
12: V12,
|
|
13: V13,
|
|
14: V14,
|
|
15: V15,
|
|
16: V16,
|
|
17: V17,
|
|
18: V18,
|
|
19: V19,
|
|
20: V20,
|
|
21: V21,
|
|
22: V22,
|
|
23: V23,
|
|
24: V24,
|
|
25: V25,
|
|
26: V26,
|
|
27: V27,
|
|
28: V28,
|
|
29: V29,
|
|
30: V30,
|
|
31: V31,
|
|
32: V32,
|
|
33: V33(dsInfoProvider),
|
|
34: V34,
|
|
35: V35,
|
|
36: V36(dsInfoProvider),
|
|
37: V37,
|
|
38: V38,
|
|
39: V39,
|
|
40: V40,
|
|
41: V41,
|
|
42: V42,
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|