diff --git a/docs/sources/administration/provisioning.md b/docs/sources/administration/provisioning.md index 3c94cb79f21..cce25e4cf2b 100644 --- a/docs/sources/administration/provisioning.md +++ b/docs/sources/administration/provisioning.md @@ -234,15 +234,15 @@ By default Grafana will delete dashboards in the database if the file is removed ## Alert Notification Channels -Alert Notification Channels can be provisionned by adding one or more yaml config files in the [`provisioning/notifiers`](/installation/configuration/#provisioning) directory. +Alert Notification Channels can be provisioned by adding one or more yaml config files in the [`provisioning/notifiers`](/installation/configuration/#provisioning) directory. Each config file can contain the following top-level fields: - `notifiers`, a list of alert notifications that will be added or updated during start up. If the notification channel already exists, Grafana will update it to match the configuration file. - `delete_notifiers`, a list of alert notifications to be deleted before before inserting/updating those in the `notifiers` list. -Provisionning looks up alert notifications by name, and will update any existing notification with the provided name. +Provisioning looks up alert notifications by uid, and will update any existing notification with the provided uid. -By default, exporting a dashboard as JSON will use a sequential identifier to refer to alert notifications. The field `name` can be optionally specified to specify a string identifier for the alert name. +By default, exporting a dashboard as JSON will use a sequential identifier to refer to alert notifications. The field `uid` can be optionally specified to specify a string identifier for the alert name. ```json { diff --git a/pkg/services/sqlstore/alert_notification.go b/pkg/services/sqlstore/alert_notification.go index 9231c896cf1..efb5f621392 100644 --- a/pkg/services/sqlstore/alert_notification.go +++ b/pkg/services/sqlstore/alert_notification.go @@ -281,10 +281,12 @@ func generateNewAlertNotificationUid(sess *DBSession, orgId int64) (string, erro if err != nil { return "", err } + if !exists { return uid, nil } } + return "", m.ErrAlertNotificationFailedGenerateUniqueUid } diff --git a/pkg/services/sqlstore/migrations/alert_mig.go b/pkg/services/sqlstore/migrations/alert_mig.go index 2ed9732687a..84014bd386f 100644 --- a/pkg/services/sqlstore/migrations/alert_mig.go +++ b/pkg/services/sqlstore/migrations/alert_mig.go @@ -141,13 +141,16 @@ func addAlertMigrations(mg *Migrator) { mg.AddMigration("Add column uid in alert_notification", NewAddColumnMigration(alert_notification, &Column{ Name: "uid", Type: DB_NVarchar, Length: 40, Nullable: true, })) + mg.AddMigration("Update uid column values in alert_notification", new(RawSqlMigration). Sqlite("UPDATE alert_notification SET uid=printf('%09d',id) WHERE uid IS NULL;"). Postgres("UPDATE alert_notification SET uid=lpad('' || id,9,'0') WHERE uid IS NULL;"). Mysql("UPDATE alert_notification SET uid=lpad(id,9,'0') WHERE uid IS NULL;")) + mg.AddMigration("Add unique index alert_notification_org_id_uid", NewAddIndexMigration(alert_notification, &Index{ Cols: []string{"org_id", "uid"}, Type: UniqueIndex, })) + mg.AddMigration("Remove unique index org_id_name", NewDropIndexMigration(alert_notification, &Index{ Cols: []string{"org_id", "name"}, Type: UniqueIndex, }))