File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
cmd/metal-api/internal/datastore/migrations Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ package migrations
2
+
3
+ import (
4
+ r "gopkg.in/rethinkdb/rethinkdb-go.v6"
5
+
6
+ "github.com/metal-stack/metal-api/cmd/metal-api/internal/datastore"
7
+ )
8
+
9
+ func init () {
10
+ datastore .MustRegisterMigration (datastore.Migration {
11
+ Name : "set allocation succeeded to true for allocated machines (#210)" ,
12
+ Version : 3 ,
13
+ Up : func (db * r.Term , session r.QueryExecutor , rs * datastore.RethinkStore ) error {
14
+ ms , err := rs .ListMachines ()
15
+ if err != nil {
16
+ return err
17
+ }
18
+
19
+ for i := range ms {
20
+ old := ms [i ]
21
+ if old .Allocation == nil || old .Allocation .ConsolePassword == "" {
22
+ // these machines have never succeeded finalize-allocation
23
+ continue
24
+ }
25
+
26
+ if old .Allocation .Succeeded {
27
+ continue
28
+ }
29
+
30
+ n := old
31
+ n .Allocation .Succeeded = true
32
+ err = rs .UpdateMachine (& old , & n )
33
+ if err != nil {
34
+ return err
35
+ }
36
+ }
37
+ return nil
38
+ },
39
+ })
40
+ }
You can’t perform that action at this time.
0 commit comments