From 0bd12ab53109a536fb66f9f708f8ed582817d02d Mon Sep 17 00:00:00 2001 From: George Robinson Date: Thu, 9 Jun 2022 09:10:11 +0100 Subject: [PATCH] Alerting: Fix force_migration when alerting is disabled (#50431) * Alerting: Fix force_migration when alerting is disabled This commit fixes a bug where force_migration must be set to true when both unified and legacy alerting is disabled. * Update comment * Fix typo in comment Co-authored-by: Armand Grillet --- pkg/services/sqlstore/migrations/ualert/ualert.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/services/sqlstore/migrations/ualert/ualert.go b/pkg/services/sqlstore/migrations/ualert/ualert.go index c237dab5143..d6dd13c71f4 100644 --- a/pkg/services/sqlstore/migrations/ualert/ualert.go +++ b/pkg/services/sqlstore/migrations/ualert/ualert.go @@ -59,6 +59,7 @@ func AddDashAlertMigration(mg *migrator.Migrator) { _, migrationRun := logs[migTitle] switch { + // If unified alerting is enabled and the upgrade migration has not been run case mg.Cfg.UnifiedAlerting.IsEnabled() && !migrationRun: // Remove the migration entry that removes all unified alerting data. This is so when the feature // flag is removed in future the "remove unified alerting data" migration will be run again. @@ -72,7 +73,13 @@ func AddDashAlertMigration(mg *migrator.Migrator) { seenChannelUIDs: make(map[string]struct{}), silences: make(map[int64][]*pb.MeshSilence), }) + // If unified alerting is disabled and upgrade migration has been run case !mg.Cfg.UnifiedAlerting.IsEnabled() && migrationRun: + // If legacy alerting is also disabled, there is nothing to do + if setting.AlertingEnabled != nil && !*setting.AlertingEnabled { + return + } + // Safeguard to prevent data loss when migrating from UA to LA if !mg.Cfg.ForceMigration { panic("Grafana has already been migrated to Unified Alerting.\nAny alert rules created while using Unified Alerting will be deleted by rolling back.\n\nSet force_migration=true in your grafana.ini and restart Grafana to roll back and delete Unified Alerting configuration data.")