stats_mig.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package migrations
  2. import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
  3. func addStatsMigrations(mg *Migrator) {
  4. statTable := Table{
  5. Name: "stat",
  6. Columns: []*Column{
  7. {Name: "id", Type: DB_Int, IsPrimaryKey: true, IsAutoIncrement: true},
  8. {Name: "metric", Type: DB_Varchar, Length: 20, Nullable: false},
  9. {Name: "type", Type: DB_Int, Nullable: false},
  10. },
  11. Indices: []*Index{
  12. {Cols: []string{"metric"}, Type: UniqueIndex},
  13. },
  14. }
  15. // create table
  16. mg.AddMigration("create stat table", NewAddTableMigration(statTable))
  17. // create indices
  18. mg.AddMigration("add index stat.metric", NewAddIndexMigration(statTable, statTable.Indices[0]))
  19. statValue := Table{
  20. Name: "stat_value",
  21. Columns: []*Column{
  22. {Name: "id", Type: DB_Int, IsPrimaryKey: true, IsAutoIncrement: true},
  23. {Name: "value", Type: DB_Double, Nullable: false},
  24. {Name: "time", Type: DB_DateTime, Nullable: false},
  25. },
  26. }
  27. // create table
  28. mg.AddMigration("create stat_value table", NewAddTableMigration(statValue))
  29. }
  30. func addTestDataMigrations(mg *Migrator) {
  31. testData := Table{
  32. Name: "test_data",
  33. Columns: []*Column{
  34. {Name: "id", Type: DB_Int, IsPrimaryKey: true, IsAutoIncrement: true},
  35. {Name: "metric1", Type: DB_Varchar, Length: 20, Nullable: true},
  36. {Name: "metric2", Type: DB_NVarchar, Length: 150, Nullable: true},
  37. {Name: "value_big_int", Type: DB_BigInt, Nullable: true},
  38. {Name: "value_double", Type: DB_Double, Nullable: true},
  39. {Name: "value_float", Type: DB_Float, Nullable: true},
  40. {Name: "value_int", Type: DB_Int, Nullable: true},
  41. {Name: "time_epoch", Type: DB_BigInt, Nullable: false},
  42. {Name: "time_date_time", Type: DB_DateTime, Nullable: false},
  43. {Name: "time_time_stamp", Type: DB_TimeStamp, Nullable: false},
  44. },
  45. }
  46. // create table
  47. mg.AddMigration("create test_data table", NewAddTableMigration(testData))
  48. }