[release-12.3.1] refactor(annotations): Allow skipping always on dashboard UID migrations (#114096)

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

(cherry picked from commit b70c6a726f)

Co-authored-by: Andres Torres <janthoe@users.noreply.github.com>
This commit is contained in:
grafana-delivery-bot[bot]
2025-11-18 17:08:55 -05:00
committed by GitHub
co-authored by Andres Torres
parent 0fa02c1212
commit 95c7703d35
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"
}