代码拉取完成,页面将自动刷新
package migrations
import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
func addOrgMigrations(mg *Migrator) {
orgV1 := Table{
Name: "org",
Columns: []*Column{
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
{Name: "version", Type: DB_Int, Nullable: false},
{Name: "name", Type: DB_NVarchar, Length: 190, Nullable: false},
{Name: "address1", Type: DB_NVarchar, Length: 255, Nullable: true},
{Name: "address2", Type: DB_NVarchar, Length: 255, Nullable: true},
{Name: "city", Type: DB_NVarchar, Length: 255, Nullable: true},
{Name: "state", Type: DB_NVarchar, Length: 255, Nullable: true},
{Name: "zip_code", Type: DB_NVarchar, Length: 50, Nullable: true},
{Name: "country", Type: DB_NVarchar, Length: 255, Nullable: true},
{Name: "billing_email", Type: DB_NVarchar, Length: 255, Nullable: true},
{Name: "created", Type: DB_DateTime, Nullable: false},
{Name: "updated", Type: DB_DateTime, Nullable: false},
},
Indices: []*Index{
{Cols: []string{"name"}, Type: UniqueIndex},
},
}
// add org v1
mg.AddMigration("create org table v1", NewAddTableMigration(orgV1))
addTableIndicesMigrations(mg, "v1", orgV1)
orgUserV1 := Table{
Name: "org_user",
Columns: []*Column{
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
{Name: "org_id", Type: DB_BigInt},
{Name: "user_id", Type: DB_BigInt},
{Name: "role", Type: DB_NVarchar, Length: 20},
{Name: "created", Type: DB_DateTime},
{Name: "updated", Type: DB_DateTime},
},
Indices: []*Index{
{Cols: []string{"org_id"}},
{Cols: []string{"org_id", "user_id"}, Type: UniqueIndex},
},
}
//------- org_user table -------------------
mg.AddMigration("create org_user table v1", NewAddTableMigration(orgUserV1))
addTableIndicesMigrations(mg, "v1", orgUserV1)
//------- copy data from old table-------------------
mg.AddMigration("copy data account to org", NewCopyTableDataMigration("org", "account", map[string]string{
"id": "id",
"version": "version",
"name": "name",
"created": "created",
"updated": "updated",
}).IfTableExists("account"))
mg.AddMigration("copy data account_user to org_user", NewCopyTableDataMigration("org_user", "account_user", map[string]string{
"id": "id",
"org_id": "account_id",
"user_id": "user_id",
"role": "role",
"created": "created",
"updated": "updated",
}).IfTableExists("account_user"))
mg.AddMigration("Drop old table account", NewDropTableMigration("account"))
mg.AddMigration("Drop old table account_user", NewDropTableMigration("account_user"))
mg.AddMigration("Update org table charset", NewTableCharsetMigration("org", []*Column{
{Name: "name", Type: DB_NVarchar, Length: 190, Nullable: false},
{Name: "address1", Type: DB_NVarchar, Length: 255, Nullable: true},
{Name: "address2", Type: DB_NVarchar, Length: 255, Nullable: true},
{Name: "city", Type: DB_NVarchar, Length: 255, Nullable: true},
{Name: "state", Type: DB_NVarchar, Length: 255, Nullable: true},
{Name: "zip_code", Type: DB_NVarchar, Length: 50, Nullable: true},
{Name: "country", Type: DB_NVarchar, Length: 255, Nullable: true},
{Name: "billing_email", Type: DB_NVarchar, Length: 255, Nullable: true},
}))
mg.AddMigration("Update org_user table charset", NewTableCharsetMigration("org_user", []*Column{
{Name: "role", Type: DB_NVarchar, Length: 20},
}))
const migrateReadOnlyViewersToViewers = `UPDATE org_user SET role = 'Viewer' WHERE role = 'Read Only Editor'`
mg.AddMigration("Migrate all Read Only Viewers to Viewers", new(RawSqlMigration).
Sqlite(migrateReadOnlyViewersToViewers).
Postgres(migrateReadOnlyViewersToViewers).
Mysql(migrateReadOnlyViewersToViewers))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。