Dashboards: Do not throw error if backend cannot migrate schemaVersion to latest (#102357)

* Refactor migration error handling to use MinimumVersionError for schema version checks

- Updated migration logic to return MinimumVersionError instead of MigrationError for outdated schema versions.
- Enhanced MinimumVersionError message for clarity on migration constraints.
- Added tests for version error handling in the dashboard API to ensure proper error throwing for specific conversion errors.

* Fix tests and remove folder dependencies
This commit is contained in:
Ivan Ortega Alba
2025-03-19 09:57:05 +02:00
committed by GitHub
parent 7f9fa8c662
commit 35e3d26987
7 changed files with 232 additions and 100 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ func Migrate(dash map[string]interface{}, targetVersion int) error {
// If the schema version is older than the minimum version, with migration support,
// we don't migrate the dashboard.
if inputVersion < schemaversion.MIN_VERSION {
return schemaversion.NewMigrationError("schema version is too old", inputVersion, schemaversion.MIN_VERSION)
return schemaversion.NewMinimumVersionError(inputVersion)
}
for nextVersion := inputVersion + 1; nextVersion <= targetVersion; nextVersion++ {
+1 -1
View File
@@ -27,7 +27,7 @@ func TestMigrate(t *testing.T) {
"schemaVersion": schemaversion.MIN_VERSION - 1,
}, schemaversion.MIN_VERSION)
var minVersionErr = schemaversion.NewMigrationError("schema version is too old", schemaversion.MIN_VERSION-1, schemaversion.MIN_VERSION)
var minVersionErr = schemaversion.NewMinimumVersionError(schemaversion.MIN_VERSION - 1)
require.ErrorAs(t, err, &minVersionErr)
})
@@ -35,5 +35,5 @@ type MinimumVersionError struct {
}
func (e *MinimumVersionError) Error() string {
return fmt.Errorf("input schema version is below minimum version. input: %d minimum: %d", e.inputVersion, MIN_VERSION).Error()
return fmt.Errorf("dashboard schema version %d cannot be migrated to latest version %d - migration path only exists for versions greater than %d", e.inputVersion, LATEST_VERSION, MIN_VERSION).Error()
}