2025-01-24 00:40:22 +08:00
|
|
|
package schemaversion
|
|
|
|
|
2025-06-16 21:53:41 +08:00
|
|
|
import (
|
|
|
|
"strconv"
|
2025-09-04 04:41:37 +08:00
|
|
|
|
|
|
|
"golang.org/x/net/context"
|
2025-06-16 21:53:41 +08:00
|
|
|
)
|
2025-01-24 00:40:22 +08:00
|
|
|
|
2025-03-14 16:55:40 +08:00
|
|
|
const (
|
2025-08-21 23:54:02 +08:00
|
|
|
MIN_VERSION = 12
|
2025-10-07 03:17:12 +08:00
|
|
|
LATEST_VERSION = 42
|
2025-09-04 19:17:22 +08:00
|
|
|
|
|
|
|
// The pluginVersion to set after simulating auto-migrate for angular panels
|
|
|
|
pluginVersionForAutoMigrate = "12.1.0"
|
2025-03-14 16:55:40 +08:00
|
|
|
)
|
2025-01-24 00:40:22 +08:00
|
|
|
|
2025-09-04 04:41:37 +08:00
|
|
|
type SchemaVersionMigrationFunc func(context.Context, map[string]interface{}) error
|
2025-06-16 21:53:41 +08:00
|
|
|
|
|
|
|
type DataSourceInfo struct {
|
|
|
|
Default bool
|
|
|
|
UID string
|
|
|
|
Name string
|
|
|
|
Type string
|
|
|
|
ID int64
|
|
|
|
APIVersion string
|
|
|
|
}
|
|
|
|
|
|
|
|
type DataSourceInfoProvider interface {
|
2025-09-04 04:41:37 +08:00
|
|
|
// GetDataSourceInfo returns a list of all data sources with their info
|
|
|
|
// The context must have the namespace in it
|
|
|
|
GetDataSourceInfo(ctx context.Context) []DataSourceInfo
|
2025-06-16 21:53:41 +08:00
|
|
|
}
|
|
|
|
|
2025-08-06 23:51:55 +08:00
|
|
|
type PanelPluginInfo struct {
|
|
|
|
ID string
|
|
|
|
Version string
|
|
|
|
}
|
|
|
|
|
2025-09-04 19:17:22 +08:00
|
|
|
func GetMigrations(dsInfoProvider DataSourceInfoProvider) map[int]SchemaVersionMigrationFunc {
|
2025-06-16 21:53:41 +08:00
|
|
|
return map[int]SchemaVersionMigrationFunc{
|
2025-08-21 23:54:02 +08:00
|
|
|
13: V13,
|
2025-08-13 21:35:21 +08:00
|
|
|
14: V14,
|
2025-08-13 21:28:27 +08:00
|
|
|
15: V15,
|
2025-08-13 20:35:58 +08:00
|
|
|
16: V16,
|
2025-08-13 18:58:54 +08:00
|
|
|
17: V17,
|
2025-08-12 06:04:49 +08:00
|
|
|
18: V18,
|
2025-08-12 05:44:00 +08:00
|
|
|
19: V19,
|
2025-08-08 17:46:34 +08:00
|
|
|
20: V20,
|
2025-08-08 16:55:32 +08:00
|
|
|
21: V21,
|
2025-08-08 16:03:02 +08:00
|
|
|
22: V22,
|
2025-08-08 06:41:42 +08:00
|
|
|
23: V23,
|
2025-09-04 19:17:22 +08:00
|
|
|
24: V24,
|
2025-08-08 04:14:39 +08:00
|
|
|
25: V25,
|
2025-08-07 01:00:48 +08:00
|
|
|
26: V26,
|
2025-08-07 00:22:11 +08:00
|
|
|
27: V27,
|
2025-09-04 19:17:22 +08:00
|
|
|
28: V28,
|
2025-07-16 01:27:04 +08:00
|
|
|
29: V29,
|
2025-07-16 00:44:11 +08:00
|
|
|
30: V30,
|
2025-07-15 23:28:48 +08:00
|
|
|
31: V31,
|
|
|
|
32: V32,
|
2025-06-27 01:04:43 +08:00
|
|
|
33: V33(dsInfoProvider),
|
2025-06-19 15:03:14 +08:00
|
|
|
34: V34,
|
2025-06-17 16:38:48 +08:00
|
|
|
35: V35,
|
2025-06-16 21:53:41 +08:00
|
|
|
36: V36(dsInfoProvider),
|
|
|
|
37: V37,
|
|
|
|
38: V38,
|
|
|
|
39: V39,
|
|
|
|
40: V40,
|
|
|
|
41: V41,
|
2025-09-05 21:07:30 +08:00
|
|
|
42: V42,
|
2025-06-16 21:53:41 +08:00
|
|
|
}
|
2025-01-24 00:40:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|