Skip to content

Commit fd344e2

Browse files
committed
Migrate allocation succeeded flag for existing machines.
1 parent ef5e0fd commit fd344e2

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
}

0 commit comments

Comments
 (0)