migrations.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. mg.AddMigration("create migration_log table", new(AddTableMigration).
  18. Name("migration_log").WithColumns(
  19. &Column{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  20. &Column{Name: "migration_id", Type: DB_NVarchar, Length: 255},
  21. &Column{Name: "sql", Type: DB_Text},
  22. &Column{Name: "success", Type: DB_Bool},
  23. &Column{Name: "error", Type: DB_Text},
  24. &Column{Name: "timestamp", Type: DB_DateTime},
  25. ))
  26. }
  27. func addStarMigrations(mg *Migrator) {
  28. mg.AddMigration("create star table", new(AddTableMigration).
  29. Name("star").WithColumns(
  30. &Column{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
  31. &Column{Name: "user_id", Type: DB_BigInt, Nullable: false},
  32. &Column{Name: "dashboard_id", Type: DB_BigInt, Nullable: false},
  33. ))
  34. mg.AddMigration("add unique index star.user_id_dashboard_id", new(AddIndexMigration).
  35. Table("star").Columns("user_id", "dashboard_id").Unique())
  36. }