Alerting: Create basic storage layer for provisioning (#44679)
* Simplistic store API for provenance lookups on arbitrary types * Add a few notes in comments * Improved type safety for provisioned objects * Clean-up TODOs for future PRs * Clean up provisioning model * Clean up tests * Restrict allowable types in interface * Fix linter error * Move AlertRule domain methods to same file as AlertRule definition * Update pkg/services/ngalert/models/provisioning.go Co-authored-by: George Robinson <george.robinson@grafana.com> * Complete interface rename * Pass context through store API * More idiomatic method names * Better error description * Improve code-docs * Use ORM language instead of raw sql * Add support for records in different orgs * ResourceTypeID -> ResourceType since it's not an ID Co-authored-by: George Robinson <george.robinson@grafana.com>
This commit is contained in:
co-authored by
George Robinson
parent
7105bb3be7
commit
935059a376
@@ -22,6 +22,9 @@ func AddTablesMigrations(mg *migrator.Migrator) {
|
||||
|
||||
// Create Admin Configuration
|
||||
AddAlertAdminConfigMigrations(mg)
|
||||
|
||||
// Create provisioning data table
|
||||
AddProvisioningMigrations(mg)
|
||||
}
|
||||
|
||||
// AddAlertDefinitionMigrations should not be modified.
|
||||
@@ -327,3 +330,22 @@ func AddAlertAdminConfigMigrations(mg *migrator.Migrator) {
|
||||
Name: "send_alerts_to", Type: migrator.DB_SmallInt, Nullable: false,
|
||||
}))
|
||||
}
|
||||
|
||||
func AddProvisioningMigrations(mg *migrator.Migrator) {
|
||||
provisioningTable := migrator.Table{
|
||||
Name: "provenance_type",
|
||||
Columns: []*migrator.Column{
|
||||
{Name: "id", Type: migrator.DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
|
||||
{Name: "org_id", Type: migrator.DB_BigInt, Nullable: false},
|
||||
{Name: "record_key", Type: migrator.DB_NVarchar, Length: 190, Nullable: false},
|
||||
{Name: "record_type", Type: migrator.DB_NVarchar, Length: 190, Nullable: false},
|
||||
{Name: "provenance", Type: migrator.DB_NVarchar, Length: 190, Nullable: false},
|
||||
},
|
||||
Indices: []*migrator.Index{
|
||||
{Cols: []string{"record_type", "record_key", "org_id"}, Type: migrator.UniqueIndex},
|
||||
},
|
||||
}
|
||||
|
||||
mg.AddMigration("create provenance_type table", migrator.NewAddTableMigration(provisioningTable))
|
||||
mg.AddMigration("add index to uniquify (record_key, record_type, org_id) columns", migrator.NewAddIndexMigration(provisioningTable, provisioningTable.Indices[0]))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user