stats_mig.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  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. }