2016-04-13 03:33:45 -05:00
|
|
|
package migrations
|
|
|
|
|
2016-05-23 00:47:38 -05:00
|
|
|
import (
|
|
|
|
. "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
|
|
|
)
|
2016-04-13 03:33:45 -05:00
|
|
|
|
|
|
|
func addAlertMigrations(mg *Migrator) {
|
2016-05-23 03:02:17 -05:00
|
|
|
|
2016-04-13 03:33:45 -05:00
|
|
|
alertV1 := Table{
|
2016-06-11 03:54:24 -05:00
|
|
|
Name: "alert",
|
2016-04-13 03:33:45 -05:00
|
|
|
Columns: []*Column{
|
|
|
|
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
|
|
|
|
{Name: "dashboard_id", Type: DB_BigInt, Nullable: false},
|
|
|
|
{Name: "panel_id", Type: DB_BigInt, Nullable: false},
|
2016-04-25 09:18:28 -05:00
|
|
|
{Name: "org_id", Type: DB_BigInt, Nullable: false},
|
2016-06-06 10:11:46 -05:00
|
|
|
{Name: "name", Type: DB_NVarchar, Length: 255, Nullable: false},
|
2016-08-12 03:12:04 -05:00
|
|
|
{Name: "message", Type: DB_Text, Nullable: false},
|
2016-04-28 01:23:50 -05:00
|
|
|
{Name: "state", Type: DB_NVarchar, Length: 255, Nullable: false},
|
2016-06-13 08:18:19 -05:00
|
|
|
{Name: "settings", Type: DB_Text, Nullable: false},
|
2016-06-17 01:27:38 -05:00
|
|
|
{Name: "frequency", Type: DB_BigInt, Nullable: false},
|
2016-06-13 08:58:22 -05:00
|
|
|
{Name: "handler", Type: DB_BigInt, Nullable: false},
|
2016-07-21 06:09:12 -05:00
|
|
|
{Name: "severity", Type: DB_Text, Nullable: false},
|
2016-08-15 10:20:45 -05:00
|
|
|
{Name: "paused", Type: DB_Bool, Nullable: false},
|
|
|
|
{Name: "silenced", Type: DB_Bool, Nullable: false},
|
|
|
|
{Name: "execution_error", Type: DB_Text, Nullable: false},
|
|
|
|
{Name: "last_eval_data", Type: DB_Text, Nullable: false},
|
|
|
|
{Name: "last_eval_time", Type: DB_DateTime, Nullable: false},
|
2016-05-20 07:23:24 -05:00
|
|
|
{Name: "created", Type: DB_DateTime, Nullable: false},
|
|
|
|
{Name: "updated", Type: DB_DateTime, Nullable: false},
|
2016-07-13 04:58:55 -05:00
|
|
|
{Name: "updated_by", Type: DB_BigInt, Nullable: false},
|
|
|
|
{Name: "created_by", Type: DB_BigInt, Nullable: false},
|
2016-04-13 03:33:45 -05:00
|
|
|
},
|
2016-08-15 10:20:45 -05:00
|
|
|
Indices: []*Index{
|
|
|
|
{Cols: []string{"org_id", "id"}, Type: IndexType},
|
|
|
|
{Cols: []string{"state"}, Type: IndexType},
|
|
|
|
{Cols: []string{"dashboard_id"}, Type: IndexType},
|
|
|
|
},
|
2016-04-13 03:33:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// create table
|
2016-06-11 03:54:24 -05:00
|
|
|
mg.AddMigration("create alert table v1", NewAddTableMigration(alertV1))
|
2016-04-25 07:28:18 -05:00
|
|
|
|
2016-08-15 10:20:45 -05:00
|
|
|
// create indices
|
|
|
|
mg.AddMigration("add index alert org_id & id ", NewAddIndexMigration(alertV1, alertV1.Indices[0]))
|
|
|
|
mg.AddMigration("add index alert state", NewAddIndexMigration(alertV1, alertV1.Indices[1]))
|
|
|
|
mg.AddMigration("add index alert dashboard_id", NewAddIndexMigration(alertV1, alertV1.Indices[2]))
|
2016-06-13 09:39:00 -05:00
|
|
|
|
|
|
|
alert_notification := Table{
|
|
|
|
Name: "alert_notification",
|
|
|
|
Columns: []*Column{
|
|
|
|
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
|
|
|
|
{Name: "org_id", Type: DB_BigInt, Nullable: false},
|
|
|
|
{Name: "name", Type: DB_NVarchar, Length: 255, Nullable: false},
|
|
|
|
{Name: "type", Type: DB_NVarchar, Length: 255, Nullable: false},
|
|
|
|
{Name: "settings", Type: DB_Text, Nullable: false},
|
|
|
|
{Name: "created", Type: DB_DateTime, Nullable: false},
|
|
|
|
{Name: "updated", Type: DB_DateTime, Nullable: false},
|
|
|
|
},
|
2016-08-15 10:20:45 -05:00
|
|
|
Indices: []*Index{
|
|
|
|
{Cols: []string{"org_id", "name"}, Type: UniqueIndex},
|
|
|
|
},
|
2016-06-13 09:39:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
mg.AddMigration("create alert_notification table v1", NewAddTableMigration(alert_notification))
|
2016-08-15 10:20:45 -05:00
|
|
|
mg.AddMigration("add index alert_notification org_id & name", NewAddIndexMigration(alert_notification, alert_notification.Indices[0]))
|
2016-04-13 03:33:45 -05:00
|
|
|
}
|