forked from OpenBazaar/openbazaar-go
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Migration005.go
109 lines (99 loc) · 2.1 KB
/
Migration005.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package migrations
import (
"encoding/json"
"errors"
"io/ioutil"
"os"
"path"
)
type Migration005 struct{}
func (Migration005) Up(repoPath string, dbPassword string, testnet bool) error {
configFile, err := ioutil.ReadFile(path.Join(repoPath, "config"))
if err != nil {
return err
}
var cfgIface interface{}
json.Unmarshal(configFile, &cfgIface)
cfg, ok := cfgIface.(map[string]interface{})
if !ok {
return errors.New("invalid config file")
}
ipns, ok := cfg["Ipns"]
if !ok {
return errors.New("ipns config not found")
}
ipnsCfg, ok := ipns.(map[string]interface{})
if !ok {
return errors.New("ipns config not found")
}
ipnsCfg["QuerySize"] = 1
ipnsCfg["BackUpAPI"] = "https://gateway.ob1.io/ob/ipns/"
out, err := json.MarshalIndent(cfg, "", " ")
if err != nil {
return err
}
f, err := os.Create(path.Join(repoPath, "config"))
if err != nil {
return err
}
_, err = f.Write(out)
if err != nil {
return err
}
f.Close()
f1, err := os.Create(path.Join(repoPath, "repover"))
if err != nil {
return err
}
_, err = f1.Write([]byte("6"))
if err != nil {
return err
}
f1.Close()
return nil
}
func (Migration005) Down(repoPath string, dbPassword string, testnet bool) error {
configFile, err := ioutil.ReadFile(path.Join(repoPath, "config"))
if err != nil {
return err
}
var cfgIface interface{}
json.Unmarshal(configFile, &cfgIface)
cfg, ok := cfgIface.(map[string]interface{})
if !ok {
return errors.New("invalid config file")
}
ipns, ok := cfg["Ipns"]
if !ok {
return errors.New("ipns config not found")
}
ipnsCfg, ok := ipns.(map[string]interface{})
if !ok {
return errors.New("ipns config not found")
}
ipnsCfg["QuerySize"] = 5
ipnsCfg["BackUpAPI"] = ""
out, err := json.MarshalIndent(cfg, "", " ")
if err != nil {
return err
}
f, err := os.Create(path.Join(repoPath, "config"))
if err != nil {
return err
}
_, err = f.Write(out)
if err != nil {
return err
}
f.Close()
f1, err := os.Create(path.Join(repoPath, "repover"))
if err != nil {
return err
}
_, err = f1.Write([]byte("5"))
if err != nil {
return err
}
f1.Close()
return nil
}