dashboard_acl.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package migrations
  2. import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
  3. func addDashboardAclMigrations(mg *Migrator) {
  4. dashboardAclV1 := Table{
  5. Name: "dashboard_acl",
  6. Columns: []*Column{
  7. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  8. {Name: "org_id", Type: DB_BigInt},
  9. {Name: "dashboard_id", Type: DB_BigInt},
  10. {Name: "user_id", Type: DB_BigInt, Nullable: true},
  11. {Name: "team_id", Type: DB_BigInt, Nullable: true},
  12. {Name: "permission", Type: DB_SmallInt, Default: "4"},
  13. {Name: "role", Type: DB_Varchar, Length: 20, Nullable: true},
  14. {Name: "created", Type: DB_DateTime, Nullable: false},
  15. {Name: "updated", Type: DB_DateTime, Nullable: false},
  16. },
  17. Indices: []*Index{
  18. {Cols: []string{"dashboard_id"}},
  19. {Cols: []string{"dashboard_id", "user_id"}, Type: UniqueIndex},
  20. {Cols: []string{"dashboard_id", "team_id"}, Type: UniqueIndex},
  21. },
  22. }
  23. mg.AddMigration("create dashboard acl table", NewAddTableMigration(dashboardAclV1))
  24. //------- indexes ------------------
  25. mg.AddMigration("add index dashboard_acl_dashboard_id", NewAddIndexMigration(dashboardAclV1, dashboardAclV1.Indices[0]))
  26. mg.AddMigration("add unique index dashboard_acl_dashboard_id_user_id", NewAddIndexMigration(dashboardAclV1, dashboardAclV1.Indices[1]))
  27. mg.AddMigration("add unique index dashboard_acl_dashboard_id_team_id", NewAddIndexMigration(dashboardAclV1, dashboardAclV1.Indices[2]))
  28. const rawSQL = `
  29. INSERT INTO dashboard_acl
  30. (
  31. org_id,
  32. dashboard_id,
  33. permission,
  34. role,
  35. created,
  36. updated
  37. )
  38. VALUES
  39. (-1,-1, 1,'Viewer','2017-06-20','2017-06-20'),
  40. (-1,-1, 2,'Editor','2017-06-20','2017-06-20')
  41. `
  42. mg.AddMigration("save default acl rules in dashboard_acl table", NewRawSqlMigration(rawSQL))
  43. }