[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 13:48:07 -06:00
committed by Kevin Minehart
co-authored by George Robinson
parent fd67ab151d
commit fac483c393
@@ -286,6 +286,11 @@ func addAlertRuleMigrations(mg *migrator.Migrator, defaultIntervalSeconds int64)
Default: "false",
},
))
// 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: "false",
},
))
// 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) {