migrations.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. }
  26. func addMigrationLogMigrations(mg *Migrator) {
  27. migrationLogV1 := Table{
  28. Name: "migration_log",
  29. Columns: []*Column{
  30. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  31. {Name: "migration_id", Type: DB_NVarchar, Length: 255},
  32. {Name: "sql", Type: DB_Text},
  33. {Name: "success", Type: DB_Bool},
  34. {Name: "error", Type: DB_Text},
  35. {Name: "timestamp", Type: DB_DateTime},
  36. },
  37. }
  38. mg.AddMigration("create migration_log table", NewAddTableMigration(migrationLogV1))
  39. }
  40. func addStarMigrations(mg *Migrator) {
  41. starV1 := Table{
  42. Name: "star",
  43. Columns: []*Column{
  44. {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  45. {Name: "user_id", Type: DB_BigInt, Nullable: false},
  46. {Name: "dashboard_id", Type: DB_BigInt, Nullable: false},
  47. },
  48. Indices: []*Index{
  49. {Cols: []string{"user_id", "dashboard_id"}, Type: UniqueIndex},
  50. },
  51. }
  52. mg.AddMigration("create star table", NewAddTableMigration(starV1))
  53. mg.AddMigration("add unique index star.user_id_dashboard_id", NewAddIndexMigration(starV1, starV1.Indices[0]))
  54. }