|
|
|
@ -1,12 +1,24 @@ |
|
|
|
package store |
|
|
|
package ualert |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/models" |
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/sqlstore/migrator" |
|
|
|
"github.com/grafana/grafana/pkg/services/sqlstore/migrator" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// AddMigration defines database migrations.
|
|
|
|
|
|
|
|
// If Alerting NG is not enabled does nothing.
|
|
|
|
|
|
|
|
func AddTablesMigrations(mg *migrator.Migrator) { |
|
|
|
|
|
|
|
AddAlertDefinitionMigrations(mg, 60) |
|
|
|
|
|
|
|
AddAlertDefinitionVersionMigrations(mg) |
|
|
|
|
|
|
|
// Create alert_instance table
|
|
|
|
|
|
|
|
AlertInstanceMigration(mg) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create alert_rule
|
|
|
|
|
|
|
|
AddAlertRuleMigrations(mg, 60) |
|
|
|
|
|
|
|
AddAlertRuleVersionMigrations(mg) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// AddAlertDefinitionMigrations should not be modified.
|
|
|
|
// AddAlertDefinitionMigrations should not be modified.
|
|
|
|
func AddAlertDefinitionMigrations(mg *migrator.Migrator, defaultIntervalSeconds int64) { |
|
|
|
func AddAlertDefinitionMigrations(mg *migrator.Migrator, defaultIntervalSeconds int64) { |
|
|
|
mg.AddMigration("delete alert_definition table", migrator.NewDropTableMigration("alert_definition")) |
|
|
|
mg.AddMigration("delete alert_definition table", migrator.NewDropTableMigration("alert_definition")) |
|
|
|
@ -151,8 +163,8 @@ func AddAlertRuleMigrations(mg *migrator.Migrator, defaultIntervalSeconds int64) |
|
|
|
// the following fields will correspond to a dashboard (or folder) UIID
|
|
|
|
// the following fields will correspond to a dashboard (or folder) UIID
|
|
|
|
{Name: "namespace_uid", Type: migrator.DB_NVarchar, Length: 40, Nullable: false}, |
|
|
|
{Name: "namespace_uid", Type: migrator.DB_NVarchar, Length: 40, Nullable: false}, |
|
|
|
{Name: "rule_group", Type: migrator.DB_NVarchar, Length: 190, Nullable: false}, |
|
|
|
{Name: "rule_group", Type: migrator.DB_NVarchar, Length: 190, Nullable: false}, |
|
|
|
{Name: "no_data_state", Type: migrator.DB_NVarchar, Length: 15, Nullable: false, Default: fmt.Sprintf("'%s'", models.NoData.String())}, |
|
|
|
{Name: "no_data_state", Type: migrator.DB_NVarchar, Length: 15, Nullable: false, Default: "'NoData'"}, |
|
|
|
{Name: "exec_err_state", Type: migrator.DB_NVarchar, Length: 15, Nullable: false, Default: fmt.Sprintf("'%s'", models.AlertingErrState.String())}, |
|
|
|
{Name: "exec_err_state", Type: migrator.DB_NVarchar, Length: 15, Nullable: false, Default: "'Alerting'"}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
Indices: []*migrator.Index{ |
|
|
|
Indices: []*migrator.Index{ |
|
|
|
{Cols: []string{"org_id", "title"}, Type: migrator.UniqueIndex}, |
|
|
|
{Cols: []string{"org_id", "title"}, Type: migrator.UniqueIndex}, |
|
|
|
@ -199,8 +211,8 @@ func AddAlertRuleVersionMigrations(mg *migrator.Migrator) { |
|
|
|
{Name: "condition", Type: migrator.DB_NVarchar, Length: 190, Nullable: false}, |
|
|
|
{Name: "condition", Type: migrator.DB_NVarchar, Length: 190, Nullable: false}, |
|
|
|
{Name: "data", Type: migrator.DB_Text, Nullable: false}, |
|
|
|
{Name: "data", Type: migrator.DB_Text, Nullable: false}, |
|
|
|
{Name: "interval_seconds", Type: migrator.DB_BigInt, Nullable: false}, |
|
|
|
{Name: "interval_seconds", Type: migrator.DB_BigInt, Nullable: false}, |
|
|
|
{Name: "no_data_state", Type: migrator.DB_NVarchar, Length: 15, Nullable: false, Default: fmt.Sprintf("'%s'", models.NoData.String())}, |
|
|
|
{Name: "no_data_state", Type: migrator.DB_NVarchar, Length: 15, Nullable: false, Default: "'NoData'"}, |
|
|
|
{Name: "exec_err_state", Type: migrator.DB_NVarchar, Length: 15, Nullable: false, Default: fmt.Sprintf("'%s'", models.AlertingErrState.String())}, |
|
|
|
{Name: "exec_err_state", Type: migrator.DB_NVarchar, Length: 15, Nullable: false, Default: "'Alerting'"}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
Indices: []*migrator.Index{ |
|
|
|
Indices: []*migrator.Index{ |
|
|
|
{Cols: []string{"rule_org_id", "rule_uid", "version"}, Type: migrator.UniqueIndex}, |
|
|
|
{Cols: []string{"rule_org_id", "rule_uid", "version"}, Type: migrator.UniqueIndex}, |