migrations.go 1.7 KB

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