MCPcopy Create free account
hub / github.com/MG-RAST/Shock / RunVersionUpdates

Function RunVersionUpdates

shock-server/versions/versions.go:68–278  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

66}
67
68func RunVersionUpdates() (err error) {
69 // get ACL versions
70 confVersionACL, ok1 := conf.VERSIONS["ACL"]
71 dbVersionACL, ok2 := VersionMap["ACL"]
72
73 // skip version updates if database is empty / new shock deploy
74 session := db.Connection.Session.Copy()
75 c := session.DB(conf.MONGODB_DATABASE).C("Nodes")
76 num, err := c.Count()
77 session.Close()
78 if err != nil {
79 return err
80 }
81 if num == 0 {
82 return nil
83 }
84
85 // Upgrading databases with ACL schema before version 2
86 if (ok1 && confVersionACL >= 2) && (!ok2 || (ok2 && dbVersionACL < 2)) {
87 consoleReader := bufio.NewReader(os.Stdin)
88 fmt.Print("The ACL schema version in your database needs updating to version 2. Would you like the update to run? (y/n): ")
89 text, _ := consoleReader.ReadString('\n')
90 if text[0] == 'y' {
91 // Checking database to see if "public" already exists in a Node's ACL's somewhere.
92 session := db.Connection.Session.Copy()
93 defer session.Close()
94 c := session.DB(conf.MONGODB_DATABASE).C("Nodes")
95 nCount, err := c.Find(bson.M{}).Count()
96 if err != nil {
97 return err
98 }
99 oCount, err := c.Find(bson.M{"acl.owner": "public"}).Count()
100 if err != nil {
101 return err
102 }
103 rCount, err := c.Find(bson.M{"acl.read": "public"}).Count()
104 if err != nil {
105 return err
106 }
107 wCount, err := c.Find(bson.M{"acl.write": "public"}).Count()
108 if err != nil {
109 return err
110 }
111 dCount, err := c.Find(bson.M{"acl.delete": "public"}).Count()
112 if err != nil {
113 return err
114 }
115 if oCount > 0 || rCount > 0 || wCount > 0 || dCount > 0 {
116 fmt.Println("There are \"public\" strings already present in some of your Node ACL's:")
117 fmt.Println("Total number of nodes: " + strconv.Itoa(nCount))
118 fmt.Println("Number of nodes with \"public\" in owner ACL: " + strconv.Itoa(oCount))
119 fmt.Println("Number of nodes with \"public\" in read ACL: " + strconv.Itoa(rCount))
120 fmt.Println("Number of nodes with \"public\" in write ACL: " + strconv.Itoa(wCount))
121 fmt.Println("Number of nodes with \"public\" in delete ACL: " + strconv.Itoa(dCount))
122 fmt.Print("Your database may be in a mixed state, would you like to run the update anyway? (y/n): ")
123 text, _ = consoleReader.ReadString('\n')
124 }
125 if text[0] == 'y' {

Callers

nothing calls this directly

Calls 6

FilePathMethod · 0.80
IndexPathMethod · 0.80
CloseMethod · 0.65
StatMethod · 0.65
PathMethod · 0.45
SaveMethod · 0.45

Tested by

no test coverage detected