-
Notifications
You must be signed in to change notification settings - Fork 0
/
createTable.go
46 lines (39 loc) · 1.43 KB
/
createTable.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
package pgOpsSqlx
import (
"github.com/dkzhang/RmsGo/ResourceSM/model/metering"
"github.com/dkzhang/RmsGo/ResourceSM/model/projectRes"
"github.com/dkzhang/RmsGo/ResourceSM/model/resAlloc"
"github.com/dkzhang/RmsGo/ResourceSM/model/resNode"
"github.com/dkzhang/RmsGo/datebaseCommon/postgreOpsSqlx"
"github.com/jmoiron/sqlx"
"github.com/sirupsen/logrus"
)
var tableList = map[string]string{
"res_node_cpu": resNode.GetSchemaCPU(),
"res_node_gpu": resNode.GetSchemaGPU(),
"res_alloc_cpu": resAlloc.GetSchemaCPU(),
"res_alloc_gpu": resAlloc.GetSchemaGPU(),
"res_alloc_storage": resAlloc.GetSchemaStorage(),
"history_res_alloc_cpu": resAlloc.GetSchemaHistoryCPU(),
"history_res_alloc_gpu": resAlloc.GetSchemaHistoryGPU(),
"history_res_alloc_storage": resAlloc.GetSchemaHistoryStorage(),
"project_res_info": projectRes.GetSchema(),
"metering_statement": metering.GetSchema(),
"history_metering_statement": metering.GetSchemaHistory(),
}
func CreateAllTable(db *sqlx.DB) {
for name, scheme := range tableList {
_, err := postgreOpsSqlx.DropTable(db, name)
if err != nil {
logrus.Errorf("Drop table <%s> error: %v", name, err)
} else {
logrus.Infof("Drop table <%s> success", name)
}
_, err = postgreOpsSqlx.CreateTable(db, scheme)
if err != nil {
logrus.Errorf("Create table <%s> error: %v", name, err)
} else {
logrus.Infof("Create table <%s> success", name)
}
}
}