Alerting: Collate rule_group column as binary (#114365)

* fix: collate rule_group column as utf8mb4_bin

This ensures this column is sorted identically by the database and
golang, which should eliminate issues related to a mismatch in sort
order.

* chore: make test stricter

* fix: also add binary collation for postgres
This commit is contained in:
William Wernert
2025-11-24 14:58:43 -05:00
committed by GitHub
parent 0c2707bbc4
commit 2c18526a78
3 changed files with 15 additions and 5 deletions
@@ -162,4 +162,6 @@ func (oss *OSSMigrations) AddMigration(mg *Migrator) {
ualert.ExpandAlertRuleUpdatedByMigration(mg)
ualert.AddAlertRuleGroupIndexMigration(mg)
ualert.CollateBinAlertRuleGroup(mg)
}
@@ -0,0 +1,10 @@
package ualert
import "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
// CollateBinAlertRuleGroup ensures that rule_group column collates in the same way go sorts strings.
func CollateBinAlertRuleGroup(mg *migrator.Migrator) {
mg.AddMigration("ensure rule_group column sorts the same way as golang", migrator.NewRawSQLMigration("").
Mysql("ALTER TABLE alert_rule MODIFY rule_group VARCHAR(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL;").
Postgres(`ALTER TABLE alert_rule ALTER COLUMN rule_group SET DATA TYPE varchar(190) COLLATE "C";`))
}