-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
532 additions
and
62 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
cmd/metal-api/internal/datastore/migrations/06_childprefixlength.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package migrations | ||
|
||
import ( | ||
r "gopkg.in/rethinkdb/rethinkdb-go.v6" | ||
|
||
"github.com/metal-stack/metal-api/cmd/metal-api/internal/datastore" | ||
) | ||
|
||
func init() { | ||
type tmpPartition struct { | ||
PrivateNetworkPrefixLength uint8 `rethinkdb:"privatenetworkprefixlength"` | ||
} | ||
datastore.MustRegisterMigration(datastore.Migration{ | ||
Name: "migrate partition.childprefixlength to tenant super network", | ||
Version: 6, | ||
Up: func(db *r.Term, session r.QueryExecutor, rs *datastore.RethinkStore) error { | ||
nws, err := rs.ListNetworks() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, old := range nws { | ||
if !old.PrivateSuper { | ||
continue | ||
} | ||
|
||
cursor, err := db.Table("partition").Get(old.PartitionID).Run(session) | ||
if err != nil { | ||
return err | ||
} | ||
var partition tmpPartition | ||
err = cursor.One(&partition) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
new := old | ||
new.ChildPrefixLength = &partition.PrivateNetworkPrefixLength | ||
err = rs.UpdateNetwork(&old, &new) | ||
if err != nil { | ||
return err | ||
} | ||
err = cursor.Close() | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
_, err = db.Table("partition").Replace(r.Row.Without("privatenetworkprefixlength")).RunWrite(session) | ||
return err | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.