-
Notifications
You must be signed in to change notification settings - Fork 835
/
20190312_154209_v1_6.go
69 lines (57 loc) · 1.52 KB
/
20190312_154209_v1_6.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
57
58
59
60
61
62
63
64
65
66
67
68
69
package migrations
import (
"encoding/json"
"github.com/astaxie/beego/migration"
"github.com/astaxie/beego/orm"
"github.com/Qihoo360/wayne/src/backend/models"
"github.com/Qihoo360/wayne/src/backend/util/logs"
)
type NamespaceMetaData struct {
// kubernetes' namespace
Namespace string `json:"namespace,omitempty"`
}
// DO NOT MODIFY
type V16_20190312_154209 struct {
migration.Migration
}
// DO NOT MODIFY
func init() {
m := &V16_20190312_154209{}
m.Created = "20190312_154209"
migration.Register("V16_20190312_154209", m)
}
// Run the migrations
func (m *V16_20190312_154209) Up() {
// For migration namespace metadata namespace to kubeNamespace
o := orm.NewOrm()
namespaces := []*models.Namespace{}
_, err := o.QueryTable(new(models.Namespace)).
All(&namespaces)
if err != nil {
logs.Error("Get all namespaces error.", err)
return
}
for _, namespace := range namespaces {
if namespace.MetaData != "" {
metadata := &NamespaceMetaData{}
err := json.Unmarshal([]byte(namespace.MetaData), metadata)
if err != nil {
logs.Error("json.Unmarshal namespaces error.", namespace, err)
continue
}
if metadata.Namespace != "" {
namespace.KubeNamespace = metadata.Namespace
_, err := o.Update(namespace)
if err != nil {
logs.Error("update namespaces error.", namespace, err)
continue
}
}
}
}
// use m.SQL("CREATE TABLE ...") to make schema update
}
// Reverse the migrations
func (m *V16_20190312_154209) Down() {
// use m.SQL("DROP TABLE ...") to reverse schema update
}