2016-04-13 10:33:45 +02:00
|
|
|
package migrations
|
|
|
|
|
|
2016-05-23 07:47:38 +02:00
|
|
|
import (
|
|
|
|
|
. "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
|
|
|
|
)
|
2016-04-13 10:33:45 +02:00
|
|
|
|
|
|
|
|
func addAlertMigrations(mg *Migrator) {
|
2016-05-23 10:02:17 +02:00
|
|
|
|
2016-04-13 10:33:45 +02:00
|
|
|
alertV1 := Table{
|
2016-06-11 10:54:24 +02:00
|
|
|
Name: "alert",
|
2016-04-13 10:33:45 +02:00
|
|
|
Columns: []*Column{
|
|
|
|
|
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
|
2016-08-16 09:52:45 +02:00
|
|
|
{Name: "version", Type: DB_BigInt, Nullable: false},
|
2016-04-13 10:33:45 +02:00
|
|
|
{Name: "dashboard_id", Type: DB_BigInt, Nullable: false},
|
|
|
|
|
{Name: "panel_id", Type: DB_BigInt, Nullable: false},
|
2016-04-25 16:18:28 +02:00
|
|
|
{Name: "org_id", Type: DB_BigInt, Nullable: false},
|
2016-06-06 17:11:46 +02:00
|
|
|
{Name: "name", Type: DB_NVarchar, Length: 255, Nullable: false},
|
2016-08-12 10:12:04 +02:00
|
|
|
{Name: "message", Type: DB_Text, Nullable: false},
|
2017-05-29 02:31:36 -04:00
|
|
|
{Name: "state", Type: DB_NVarchar, Length: 190, Nullable: false},
|
2016-06-13 15:18:19 +02:00
|
|
|
{Name: "settings", Type: DB_Text, Nullable: false},
|
2016-06-17 08:27:38 +02:00
|
|
|
{Name: "frequency", Type: DB_BigInt, Nullable: false},
|
2016-06-13 15:58:22 +02:00
|
|
|
{Name: "handler", Type: DB_BigInt, Nullable: false},
|
2016-07-21 13:09:12 +02:00
|
|
|
{Name: "severity", Type: DB_Text, Nullable: false},
|
2016-08-15 17:20:45 +02:00
|
|
|
{Name: "silenced", Type: DB_Bool, Nullable: false},
|
|
|
|
|
{Name: "execution_error", Type: DB_Text, Nullable: false},
|
2016-08-16 09:52:45 +02:00
|
|
|
{Name: "eval_data", Type: DB_Text, Nullable: true},
|
|
|
|
|
{Name: "eval_date", Type: DB_DateTime, Nullable: true},
|
|
|
|
|
{Name: "new_state_date", Type: DB_DateTime, Nullable: false},
|
|
|
|
|
{Name: "state_changes", Type: DB_Int, Nullable: false},
|
2016-05-20 14:23:24 +02:00
|
|
|
{Name: "created", Type: DB_DateTime, Nullable: false},
|
|
|
|
|
{Name: "updated", Type: DB_DateTime, Nullable: false},
|
2016-04-13 10:33:45 +02:00
|
|
|
},
|
2016-08-15 17:20:45 +02:00
|
|
|
Indices: []*Index{
|
|
|
|
|
{Cols: []string{"org_id", "id"}, Type: IndexType},
|
|
|
|
|
{Cols: []string{"state"}, Type: IndexType},
|
|
|
|
|
{Cols: []string{"dashboard_id"}, Type: IndexType},
|
|
|
|
|
},
|
2016-04-13 10:33:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// create table
|
2016-06-11 10:54:24 +02:00
|
|
|
mg.AddMigration("create alert table v1", NewAddTableMigration(alertV1))
|
2016-04-25 14:28:18 +02:00
|
|
|
|
2016-08-15 17:20:45 +02: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 16:39:00 +02: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},
|
2017-03-28 08:34:53 -04:00
|
|
|
{Name: "name", Type: DB_NVarchar, Length: 190, Nullable: false},
|
2016-06-13 16:39:00 +02:00
|
|
|
{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 17:20:45 +02:00
|
|
|
Indices: []*Index{
|
|
|
|
|
{Cols: []string{"org_id", "name"}, Type: UniqueIndex},
|
|
|
|
|
},
|
2016-06-13 16:39:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mg.AddMigration("create alert_notification table v1", NewAddTableMigration(alert_notification))
|
2016-09-05 21:33:05 +02:00
|
|
|
mg.AddMigration("Add column is_default", NewAddColumnMigration(alert_notification, &Column{
|
|
|
|
|
Name: "is_default", Type: DB_Bool, Nullable: false, Default: "0",
|
|
|
|
|
}))
|
2016-08-15 17:20:45 +02:00
|
|
|
mg.AddMigration("add index alert_notification org_id & name", NewAddIndexMigration(alert_notification, alert_notification.Indices[0]))
|
2016-09-05 21:33:05 +02:00
|
|
|
|
2017-03-28 08:34:53 -04:00
|
|
|
mg.AddMigration("Update alert table charset", NewTableCharsetMigration("alert", []*Column{
|
|
|
|
|
{Name: "name", Type: DB_NVarchar, Length: 255, Nullable: false},
|
|
|
|
|
{Name: "message", Type: DB_Text, Nullable: false},
|
2017-05-29 02:31:36 -04:00
|
|
|
{Name: "state", Type: DB_NVarchar, Length: 190, Nullable: false},
|
2017-03-28 08:34:53 -04:00
|
|
|
{Name: "settings", Type: DB_Text, Nullable: false},
|
|
|
|
|
{Name: "severity", Type: DB_Text, Nullable: false},
|
|
|
|
|
{Name: "execution_error", Type: DB_Text, Nullable: false},
|
|
|
|
|
{Name: "eval_data", Type: DB_Text, Nullable: true},
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
mg.AddMigration("Update alert_notification table charset", NewTableCharsetMigration("alert_notification", []*Column{
|
|
|
|
|
{Name: "name", Type: DB_NVarchar, Length: 190, Nullable: false},
|
|
|
|
|
{Name: "type", Type: DB_NVarchar, Length: 255, Nullable: false},
|
|
|
|
|
{Name: "settings", Type: DB_Text, Nullable: false},
|
|
|
|
|
}))
|
2016-04-13 10:33:45 +02:00
|
|
|
}
|