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