mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
71 lines
3.8 KiB
Go
71 lines
3.8 KiB
Go
|
|
package ngalert
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||
|
|
)
|
||
|
|
|
||
|
|
func addAlertDefinitionMigrations(mg *migrator.Migrator) {
|
||
|
|
mg.AddMigration("delete alert_definition table", migrator.NewDropTableMigration("alert_definition"))
|
||
|
|
|
||
|
|
alertDefinition := migrator.Table{
|
||
|
|
Name: "alert_definition",
|
||
|
|
Columns: []*migrator.Column{
|
||
|
|
{Name: "id", Type: migrator.DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
|
||
|
|
{Name: "org_id", Type: migrator.DB_BigInt, Nullable: false},
|
||
|
|
{Name: "title", 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: "updated", Type: migrator.DB_DateTime, Nullable: false},
|
||
|
|
{Name: "interval_seconds", Type: migrator.DB_BigInt, Nullable: false, Default: fmt.Sprintf("%d", defaultIntervalSeconds)},
|
||
|
|
{Name: "version", Type: migrator.DB_Int, Nullable: false, Default: "0"},
|
||
|
|
{Name: "uid", Type: migrator.DB_NVarchar, Length: 40, Nullable: false, Default: "0"},
|
||
|
|
},
|
||
|
|
Indices: []*migrator.Index{
|
||
|
|
{Cols: []string{"org_id", "title"}, Type: migrator.IndexType},
|
||
|
|
{Cols: []string{"org_id", "uid"}, Type: migrator.IndexType},
|
||
|
|
},
|
||
|
|
}
|
||
|
|
// create table
|
||
|
|
mg.AddMigration("recreate alert_definition table", migrator.NewAddTableMigration(alertDefinition))
|
||
|
|
|
||
|
|
// create indices
|
||
|
|
mg.AddMigration("add index in alert_definition on org_id and title columns", migrator.NewAddIndexMigration(alertDefinition, alertDefinition.Indices[0]))
|
||
|
|
mg.AddMigration("add index in alert_definition on org_id and uid columns", migrator.NewAddIndexMigration(alertDefinition, alertDefinition.Indices[1]))
|
||
|
|
|
||
|
|
mg.AddMigration("alter alert_definition table data column to mediumtext in mysql", migrator.NewRawSQLMigration("").
|
||
|
|
Mysql("ALTER TABLE alert_definition MODIFY data MEDIUMTEXT;"))
|
||
|
|
}
|
||
|
|
|
||
|
|
func addAlertDefinitionVersionMigrations(mg *migrator.Migrator) {
|
||
|
|
mg.AddMigration("delete alert_definition_version table", migrator.NewDropTableMigration("alert_definition_version"))
|
||
|
|
|
||
|
|
alertDefinitionVersion := migrator.Table{
|
||
|
|
Name: "alert_definition_version",
|
||
|
|
Columns: []*migrator.Column{
|
||
|
|
{Name: "id", Type: migrator.DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
|
||
|
|
{Name: "alert_definition_id", Type: migrator.DB_BigInt},
|
||
|
|
{Name: "alert_definition_uid", Type: migrator.DB_NVarchar, Length: 40, Nullable: false, Default: "0"},
|
||
|
|
{Name: "parent_version", Type: migrator.DB_Int, Nullable: false},
|
||
|
|
{Name: "restored_from", Type: migrator.DB_Int, Nullable: false},
|
||
|
|
{Name: "version", Type: migrator.DB_Int, Nullable: false},
|
||
|
|
{Name: "created", Type: migrator.DB_DateTime, Nullable: false},
|
||
|
|
{Name: "title", 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: "interval_seconds", Type: migrator.DB_BigInt, Nullable: false},
|
||
|
|
},
|
||
|
|
Indices: []*migrator.Index{
|
||
|
|
{Cols: []string{"alert_definition_id", "version"}, Type: migrator.UniqueIndex},
|
||
|
|
{Cols: []string{"alert_definition_uid", "version"}, Type: migrator.UniqueIndex},
|
||
|
|
},
|
||
|
|
}
|
||
|
|
mg.AddMigration("recreate alert_definition_version table", migrator.NewAddTableMigration(alertDefinitionVersion))
|
||
|
|
mg.AddMigration("add index in alert_definition_version table on alert_definition_id and version columns", migrator.NewAddIndexMigration(alertDefinitionVersion, alertDefinitionVersion.Indices[0]))
|
||
|
|
mg.AddMigration("add index in alert_definition_version table on alert_definition_uid and version columns", migrator.NewAddIndexMigration(alertDefinitionVersion, alertDefinitionVersion.Indices[1]))
|
||
|
|
|
||
|
|
mg.AddMigration("alter alert_definition_version table data column to mediumtext in mysql", migrator.NewRawSQLMigration("").
|
||
|
|
Mysql("ALTER TABLE alert_definition_version MODIFY data MEDIUMTEXT;"))
|
||
|
|
}
|