migrations.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package migrations
  2. import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
  3. // --- Migration Guide line ---
  4. // 1. Never change a migration that is committed and pushed to master
  5. // 2. Always add new migrations (to change or undo previous migrations)
  6. // 3. Some migrations are not yet written (rename column, table, drop table, index etc)
  7. func AddMigrations(mg *Migrator) {
  8. addMigrationLogMigrations(mg)
  9. addUserMigrations(mg)
  10. addTempUserMigrations(mg)
  11. addStarMigrations(mg)
  12. addOrgMigrations(mg)
  13. addDashboardMigration(mg)
  14. addDataSourceMigration(mg)
  15. addApiKeyMigrations(mg)
  16. addDashboardSnapshotMigrations(mg)
  17. addQuotaMigration(mg)
  18. addAppSettingsMigration(mg)
  19. addSessionMigration(mg)
  20. addPlaylistMigrations(mg)
  21. addPreferencesMigrations(mg)
  22. addAlertMigrations(mg)
  23. addAnnotationMig(mg)
  24. addTestDataMigrations(mg)
  25. addDashboardVersionMigration(mg)
  26. addTeamMigrations(mg)
  27. addDashboardAclMigrations(mg)
  28. addTagMigration(mg)
  29. addLoginAttemptMigrations(mg)
  30. addUserAuthMigrations(mg)
  31. addServerlockMigrations(mg)
  32. }
  33. func addMigrationLogMigrations(mg *Migrator) {
  34. migrationLogV1 := Table{
  35. Name: "migration_log",
  36. Columns: []*Column{
  37. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  38. {Name: "migration_id", Type: DB_NVarchar, Length: 255},
  39. {Name: "sql", Type: DB_Text},
  40. {Name: "success", Type: DB_Bool},
  41. {Name: "error", Type: DB_Text},
  42. {Name: "timestamp", Type: DB_DateTime},
  43. },
  44. }
  45. mg.AddMigration("create migration_log table", NewAddTableMigration(migrationLogV1))
  46. }
  47. func addStarMigrations(mg *Migrator) {
  48. starV1 := Table{
  49. Name: "star",
  50. Columns: []*Column{
  51. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  52. {Name: "user_id", Type: DB_BigInt, Nullable: false},
  53. {Name: "dashboard_id", Type: DB_BigInt, Nullable: false},
  54. },
  55. Indices: []*Index{
  56. {Cols: []string{"user_id", "dashboard_id"}, Type: UniqueIndex},
  57. },
  58. }
  59. mg.AddMigration("create star table", NewAddTableMigration(starV1))
  60. mg.AddMigration("add unique index star.user_id_dashboard_id", NewAddIndexMigration(starV1, starV1.Indices[0]))
  61. }