migrations.go 1.8 KB

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