40 Star 146 Fork 3

Gitee 极速下载/grafana

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/grafana/grafana
克隆/下载
dashboard_mig.go 3.88 KB
一键复制 编辑 原始数据 按行查看 历史
utkarshcmu 提交于 2016-01-27 22:00 . Updated http_api docs
package migrations
import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
func addDashboardMigration(mg *Migrator) {
var dashboardV1 = Table{
Name: "dashboard",
Columns: []*Column{
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
{Name: "version", Type: DB_Int, Nullable: false},
{Name: "slug", Type: DB_NVarchar, Length: 255, Nullable: false},
{Name: "title", Type: DB_NVarchar, Length: 255, Nullable: false},
{Name: "data", Type: DB_Text, Nullable: false},
{Name: "account_id", Type: DB_BigInt, Nullable: false},
{Name: "created", Type: DB_DateTime, Nullable: false},
{Name: "updated", Type: DB_DateTime, Nullable: false},
},
Indices: []*Index{
{Cols: []string{"account_id"}},
{Cols: []string{"account_id", "slug"}, Type: UniqueIndex},
},
}
mg.AddMigration("create dashboard table", NewAddTableMigration(dashboardV1))
//------- indexes ------------------
mg.AddMigration("add index dashboard.account_id", NewAddIndexMigration(dashboardV1, dashboardV1.Indices[0]))
mg.AddMigration("add unique index dashboard_account_id_slug", NewAddIndexMigration(dashboardV1, dashboardV1.Indices[1]))
dashboardTagV1 := Table{
Name: "dashboard_tag",
Columns: []*Column{
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
{Name: "dashboard_id", Type: DB_BigInt, Nullable: false},
{Name: "term", Type: DB_NVarchar, Length: 50, Nullable: false},
},
Indices: []*Index{
{Cols: []string{"dashboard_id", "term"}, Type: UniqueIndex},
},
}
mg.AddMigration("create dashboard_tag table", NewAddTableMigration(dashboardTagV1))
mg.AddMigration("add unique index dashboard_tag.dasboard_id_term", NewAddIndexMigration(dashboardTagV1, dashboardTagV1.Indices[0]))
// ---------------------
// account -> org changes
//------- drop dashboard indexes ------------------
addDropAllIndicesMigrations(mg, "v1", dashboardTagV1)
//------- rename table ------------------
addTableRenameMigration(mg, "dashboard", "dashboard_v1", "v1")
// dashboard v2
var dashboardV2 = Table{
Name: "dashboard",
Columns: []*Column{
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
{Name: "version", Type: DB_Int, Nullable: false},
{Name: "slug", Type: DB_NVarchar, Length: 255, Nullable: false},
{Name: "title", Type: DB_NVarchar, Length: 255, Nullable: false},
{Name: "data", Type: DB_Text, Nullable: false},
{Name: "org_id", Type: DB_BigInt, Nullable: false},
{Name: "created", Type: DB_DateTime, Nullable: false},
{Name: "updated", Type: DB_DateTime, Nullable: false},
},
Indices: []*Index{
{Cols: []string{"org_id"}},
{Cols: []string{"org_id", "slug"}, Type: UniqueIndex},
},
}
// recreate table
mg.AddMigration("create dashboard v2", NewAddTableMigration(dashboardV2))
// recreate indices
addTableIndicesMigrations(mg, "v2", dashboardV2)
// copy data
mg.AddMigration("copy dashboard v1 to v2", NewCopyTableDataMigration("dashboard", "dashboard_v1", map[string]string{
"id": "id",
"version": "version",
"slug": "slug",
"title": "title",
"data": "data",
"org_id": "account_id",
"created": "created",
"updated": "updated",
}))
mg.AddMigration("drop table dashboard_v1", NewDropTableMigration("dashboard_v1"))
// change column type of dashboard.data
mg.AddMigration("alter dashboard.data to mediumtext v1", new(RawSqlMigration).
Sqlite("SELECT 0 WHERE 0;").
Postgres("SELECT 0;").
Mysql("ALTER TABLE dashboard MODIFY data MEDIUMTEXT;"))
// add column to store updater of a dashboard
mg.AddMigration("Add column updated_by in dashboard - v2", NewAddColumnMigration(dashboardV2, &Column{
Name: "updated_by", Type: DB_Int, Nullable: true,
}))
// add column to store creator of a dashboard
mg.AddMigration("Add column created_by in dashboard - v2", NewAddColumnMigration(dashboardV2, &Column{
Name: "created_by", Type: DB_Int, Nullable: true,
}))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mirrors/grafana.git
git@gitee.com:mirrors/grafana.git
mirrors
grafana
grafana
v3.0.0-beta7

搜索帮助

0d507c66 1850385 C8b1a773 1850385