dashboard_acl.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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: "user_group_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", "user_group_id"}, Type: UniqueIndex},
  21. },
  22. }
  23. mg.AddMigration("create dashboard acl table", NewAddTableMigration(dashboardAclV1))
  24. //------- indexes ------------------
  25. mg.AddMigration("add unique 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_group_id", NewAddIndexMigration(dashboardAclV1, dashboardAclV1.Indices[2]))
  28. const rawSQL = `
  29. INSERT INTO dashboard_acl
  30. (
  31. org_id,
  32. dashboard_id,
  33. role,
  34. created,
  35. updated
  36. )
  37. VALUES
  38. (-1,-1,'Viewer','2017-06-20','2017-06-20'),
  39. (-1,-1,'Editor','2017-06-20','2017-06-20')
  40. `
  41. mg.AddMigration("save default acl rules in dashboard_acl table", new(RawSqlMigration).
  42. Sqlite(rawSQL).
  43. Postgres(rawSQL).
  44. Mysql(rawSQL))
  45. }