This repository has been archived by the owner on Mar 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathMigration003.go
97 lines (87 loc) · 1.75 KB
/
Migration003.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
package migrations
import (
"encoding/json"
"errors"
"io/ioutil"
"os"
"path"
)
type Migration003 struct{}
func (Migration003) Up(repoPath string, dbPassword string, testnet bool) error {
configFile, err := ioutil.ReadFile(path.Join(repoPath, "config"))
if err != nil {
return err
}
var cfgIface interface{}
err = json.Unmarshal(configFile, &cfgIface)
if err != nil {
return err
}
cfg, ok := cfgIface.(map[string]interface{})
if !ok {
return errors.New("invalid config file")
}
cfg["RepublishInterval"] = "24h"
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("4"))
if err != nil {
return err
}
f1.Close()
return nil
}
func (Migration003) Down(repoPath string, dbPassword string, testnet bool) error {
configFile, err := ioutil.ReadFile(path.Join(repoPath, "config"))
if err != nil {
return err
}
var cfgIface interface{}
err = json.Unmarshal(configFile, &cfgIface)
if err != nil {
return err
}
cfg, ok := cfgIface.(map[string]interface{})
if !ok {
return errors.New("invalid config file")
}
delete(cfg, "RepublishInterval")
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("3"))
if err != nil {
return err
}
f1.Close()
return nil
}