From 3bdffc92cfe6215fb875153cfc8d0d956c5b915b Mon Sep 17 00:00:00 2001 From: Alexander Weaver Date: Fri, 9 Dec 2022 11:42:40 -0600 Subject: [PATCH] Alerting: Create alertmanager config history table (#60103) Create config history table --- .../sqlstore/migrations/ualert/tables.go | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pkg/services/sqlstore/migrations/ualert/tables.go b/pkg/services/sqlstore/migrations/ualert/tables.go index a5d51b0f50c..875f9f68894 100644 --- a/pkg/services/sqlstore/migrations/ualert/tables.go +++ b/pkg/services/sqlstore/migrations/ualert/tables.go @@ -33,6 +33,8 @@ func AddTablesMigrations(mg *migrator.Migrator) { AddProvisioningMigrations(mg) AddAlertImageMigrations(mg) + + AddAlertmanagerConfigHistoryMigrations(mg) } // AddAlertDefinitionMigrations should not be modified. @@ -345,6 +347,26 @@ func AddAlertmanagerConfigMigrations(mg *migrator.Migrator) { })) } +func AddAlertmanagerConfigHistoryMigrations(mg *migrator.Migrator) { + alertConfigHistory := migrator.Table{ + Name: "alert_configuration_history", + Columns: []*migrator.Column{ + {Name: "id", Type: migrator.DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true}, + {Name: "org_id", Type: migrator.DB_BigInt, Nullable: false, Default: "0"}, + {Name: "alertmanager_configuration", Type: migrator.DB_MediumText, Nullable: false}, + {Name: "configuration_hash", Type: migrator.DB_Varchar, Nullable: false, Default: "'not-yet-calculated'", Length: 32}, + {Name: "configuration_version", Type: migrator.DB_NVarchar, Length: 3}, // In a format of vXX e.g. v1, v2, v10, etc + {Name: "created_at", Type: migrator.DB_Int, Nullable: false}, + {Name: "default", Type: migrator.DB_Bool, Nullable: false, Default: "0"}, + }, + Indices: []*migrator.Index{ + {Cols: []string{"org_id"}}, + }, + } + + mg.AddMigration("create_alert_configuration_history_table", migrator.NewAddTableMigration(alertConfigHistory)) +} + func AddAlertAdminConfigMigrations(mg *migrator.Migrator) { adminConfiguration := migrator.Table{ Name: "ngalert_configuration",