migrations.go 1.7 KB

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