refactor(annotations): Allow skipping always on dashboard UID migrations (#113780)

This commit is contained in:
Andres Torres
2025-11-14 11:34:13 -05:00
committed by GitHub
parent e6eb40a679
commit b70c6a726f
5 changed files with 166 additions and 4 deletions
@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"strings"
"sync"
"time"
"github.com/prometheus/client_golang/prometheus"
@@ -40,6 +41,8 @@ func validateTimeRange(item *annotations.Item) error {
return nil
}
var xormMigrationTrigger sync.Once
type xormRepositoryImpl struct {
cfg *setting.Cfg
db db.DB
@@ -51,10 +54,9 @@ type xormRepositoryImpl struct {
}
func NewXormStore(cfg *setting.Cfg, l log.Logger, db db.DB, tagService tag.Service, reg prometheus.Registerer) *xormRepositoryImpl {
err := migrations.RunDashboardUIDMigrations(db.GetEngine().NewSession(), db.GetEngine().DriverName())
if err != nil {
l.Error("failed to populate dashboard_uid for annotations", "error", err)
}
xormMigrationTrigger.Do(func() {
triggerAlwaysOnMigrations(cfg, l, db)
})
repo := &xormRepositoryImpl{
cfg: cfg,
@@ -96,6 +98,19 @@ func NewXormStore(cfg *setting.Cfg, l log.Logger, db db.DB, tagService tag.Servi
return repo
}
func triggerAlwaysOnMigrations(cfg *setting.Cfg, l log.Logger, db db.DB) {
sec := cfg.Raw.Section("database")
skipDashboardUIDMigration := sec.Key("skip_dashboard_uid_migration_on_startup").MustBool(false)
if skipDashboardUIDMigration {
l.Debug("skipped dashboard UID startup migration")
return
}
err := migrations.RunDashboardUIDMigrations(db.GetEngine().NewSession(), db.GetEngine().DriverName())
if err != nil {
l.Error("failed to populate dashboard_uid for annotations", "error", err)
}
}
func (r *xormRepositoryImpl) Type() string {
return "sql"
}