Skip to content

Commit da2f6e1

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

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
n := old
27+
n.Allocation.Succeeded = true
28+
err = rs.UpdateMachine(&old, &n)
29+
if err != nil {
30+
return err
31+
}
32+
}
33+
return nil
34+
},
35+
})
36+
}

0 commit comments

Comments
 (0)