The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/apps/dashboard/pkg/migration/migrate.go

26 lines
848 B

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
}