[v9.4.x] Alerting: Fix migration pauses all alert rules on PostgreSQL (#63968)

Alerting: Fix migration pauses all alert rules on PostgreSQL (#63951)

This commit fixes a serious bug in Grafana 9.4.1 where on upgrade
a migration would pause all existing alert rules and change the
default value of the column to true.

(cherry picked from commit 030f6c948f)

Co-authored-by: George Robinson <george.robinson@grafana.com>
This commit is contained in:
Grot (@grafanabot)
2023-03-01 18:00:08 +00:00
committed by GitHub
co-authored by George Robinson
parent 4c22a2b8fb
commit 8c483cca31
@@ -286,6 +286,11 @@ func addAlertRuleMigrations(mg *migrator.Migrator, defaultIntervalSeconds int64)
Default: "0",
},
))
// This migration fixes a bug where "false" for the default value created a column with default "true" in PostgreSQL databases
mg.AddMigration("fix is_paused column for alert_rule table", migrator.NewRawSQLMigration("").
Postgres(`ALTER TABLE alert_rule ALTER COLUMN is_paused SET DEFAULT false;
UPDATE alert_rule SET is_paused = false;`))
}
func addAlertRuleVersionMigrations(mg *migrator.Migrator) {
@@ -350,6 +355,11 @@ func addAlertRuleVersionMigrations(mg *migrator.Migrator) {
Default: "0",
},
))
// This migration fixes a bug where "false" for the default value created a column with default "true" in PostgreSQL databases
mg.AddMigration("fix is_paused column for alert_rule_version table", migrator.NewRawSQLMigration("").
Postgres(`ALTER TABLE alert_rule_version ALTER COLUMN is_paused SET DEFAULT false;
UPDATE alert_rule_version SET is_paused = false;`))
}
func addAlertmanagerConfigMigrations(mg *migrator.Migrator) {