5d2ba10113
* Move dashboard k8s APIs to a separate app Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com> * Copy dashboard code in Dockerfile Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com> * Fix conversion generation Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com> * Update OpenAPI snapshot for dashboard/v0alpha1 Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com> --------- Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com>
27 lines
848 B
Go
27 lines
848 B
Go
package migration
|
|
|
|
import "github.com/grafana/grafana/apps/dashboard/pkg/migration/schemaversion"
|
|
|
|
func Migrate(dash map[string]interface{}, targetVersion int) error {
|
|
if dash == nil {
|
|
dash = map[string]interface{}{}
|
|
}
|
|
inputVersion := schemaversion.GetSchemaVersion(dash)
|
|
dash["schemaVersion"] = inputVersion
|
|
|
|
for nextVersion := inputVersion + 1; nextVersion <= targetVersion; nextVersion++ {
|
|
if migration, ok := schemaversion.Migrations[nextVersion]; ok {
|
|
if err := migration(dash); err != nil {
|
|
return schemaversion.NewMigrationError("migration failed", inputVersion, nextVersion)
|
|
}
|
|
dash["schemaVersion"] = nextVersion
|
|
}
|
|
}
|
|
|
|
if schemaversion.GetSchemaVersion(dash) != targetVersion {
|
|
return schemaversion.NewMigrationError("schema version not migrated to target version", inputVersion, targetVersion)
|
|
}
|
|
|
|
return nil
|
|
}
|