Skip to content

Implement in backend app platform v22 schemaVersion migration #107840

@ivanortegaalba

Description

@ivanortegaalba

Problem

In the frontend, DashboardMigrator handles the migration of a dashboard across different schema versions. From schemaVersion 1, the changes we have made in the dashboard schema have been migrated using this method. When a new version is added, a new if (schemaVersion < X) do something is added.

So, to have a valid v1 dashboard, we need to ensure every stored dashboard is in the latest schemaVersion, to always return a valid schema. Additionally, to fetch from V2, we will need a valid V1 to transform from V1 to V2.

This is why DashboardMigrator must be moved into the backend to make those changes in the backend now.

How to implement a new migration:

Here is an example of a migration: #106656

  1. Add the migration file into the schemaversion folder. Make sure you create the corresponding testing file too.
  2. Go to migrations.go and update the MIN_VERSION to register the migration in the registry.
  3. Implement the migration in the x.go file. Make sure you add good documentation, with examples, so anybody can understand what the migration is about. To understand what the migration is about, go to DashboardMigrator.ts and check if(version < X) corresponding code to understand what the change is about. We recommend checking DashboardMigrator.test.ts to see if there is any test that tests the change
  4. Once you have the runtime code and the test, create an example file ONLY with the needed scenarios to ensure the migration happens. This is used to do snapshot testing every time you run go tests. The frontend tests also run the migrations for that file and if there are discrepancies, the frontend tests fail by comparing the backend and frontend outputs.

Helpful resources

  • Run backend test for each version
go test ./apps/dashboard/pkg/migration/schemaversion
  • Run backend snapshot testing. If the output file doesn't exist yet, it will create it
go test ./apps/dashboard/pkg/migration
  • Run and watch backend/frontend comparison test, to compare the output generated with the previous command with the frontend migration for the same input:
yarn test app/features/dashboard/state/DashboardMigratorToBackend.test.ts

Metadata

Metadata

Assignees

Labels

area/schemaVersion/migrationtemporary label to track schemaVersion migrations mergedinternalfor issues made by grafanistas

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions