migrations.go 1.6 KB

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