2016-08-01 16:07:00 +08:00
|
|
|
package migrations
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
. "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func addAnnotationMig(mg *Migrator) {
|
2016-09-08 17:25:45 +08:00
|
|
|
|
2016-08-01 16:07:00 +08:00
|
|
|
table := Table{
|
|
|
|
|
Name: "annotation",
|
|
|
|
|
Columns: []*Column{
|
|
|
|
|
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
|
|
|
|
|
{Name: "org_id", Type: DB_BigInt, Nullable: false},
|
|
|
|
|
{Name: "alert_id", Type: DB_BigInt, Nullable: true},
|
|
|
|
|
{Name: "user_id", Type: DB_BigInt, Nullable: true},
|
2016-09-09 17:30:55 +08:00
|
|
|
{Name: "dashboard_id", Type: DB_BigInt, Nullable: true},
|
|
|
|
|
{Name: "panel_id", Type: DB_BigInt, Nullable: true},
|
2016-08-01 16:07:00 +08:00
|
|
|
{Name: "type", Type: DB_NVarchar, Length: 25, Nullable: false},
|
|
|
|
|
{Name: "title", Type: DB_Text, Nullable: false},
|
|
|
|
|
{Name: "text", Type: DB_Text, Nullable: false},
|
|
|
|
|
{Name: "metric", Type: DB_NVarchar, Length: 255, Nullable: true},
|
|
|
|
|
{Name: "prev_state", Type: DB_NVarchar, Length: 25, Nullable: false},
|
|
|
|
|
{Name: "new_state", Type: DB_NVarchar, Length: 25, Nullable: false},
|
|
|
|
|
{Name: "data", Type: DB_Text, Nullable: false},
|
2016-09-08 17:25:45 +08:00
|
|
|
{Name: "epoch", Type: DB_BigInt, Nullable: false},
|
2016-08-01 16:07:00 +08:00
|
|
|
},
|
|
|
|
|
Indices: []*Index{
|
|
|
|
|
{Cols: []string{"org_id", "alert_id"}, Type: IndexType},
|
|
|
|
|
{Cols: []string{"org_id", "type"}, Type: IndexType},
|
2016-09-09 17:30:55 +08:00
|
|
|
{Cols: []string{"dashboard_id", "panel_id"}, Type: IndexType},
|
2016-09-08 17:25:45 +08:00
|
|
|
{Cols: []string{"epoch"}, Type: IndexType},
|
2016-08-01 16:07:00 +08:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-09 17:30:55 +08:00
|
|
|
mg.AddMigration("Drop old annotation table v3", NewDropTableMigration("annotation"))
|
2016-09-08 17:25:45 +08:00
|
|
|
|
2016-09-09 17:30:55 +08:00
|
|
|
mg.AddMigration("create annotation table v4", NewAddTableMigration(table))
|
2016-08-01 16:07:00 +08:00
|
|
|
|
|
|
|
|
// create indices
|
2016-09-09 17:30:55 +08:00
|
|
|
mg.AddMigration("add index annotation org_id & alert_id v3", NewAddIndexMigration(table, table.Indices[0]))
|
|
|
|
|
mg.AddMigration("add index annotation org_id & type v3", NewAddIndexMigration(table, table.Indices[1]))
|
|
|
|
|
mg.AddMigration("add index annotation dashboard_id panel_id", NewAddIndexMigration(table, table.Indices[2]))
|
|
|
|
|
mg.AddMigration("add index annotation epoch v3", NewAddIndexMigration(table, table.Indices[3]))
|
2016-08-01 16:07:00 +08:00
|
|
|
}
|