Skip to content

Commit 6966aee

Browse files
authored
feat(rdb): promote read replica (#1785)
1 parent 785dc16 commit 6966aee

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

api/rdb/v1/rdb_sdk.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ const (
651651
ReadReplicaStatusError = ReadReplicaStatus("error")
652652
ReadReplicaStatusLocked = ReadReplicaStatus("locked")
653653
ReadReplicaStatusConfiguring = ReadReplicaStatus("configuring")
654+
ReadReplicaStatusPromoting = ReadReplicaStatus("promoting")
654655
)
655656

656657
func (enum ReadReplicaStatus) String() string {
@@ -2545,6 +2546,51 @@ func (s *API) ResetReadReplica(req *ResetReadReplicaRequest, opts ...scw.Request
25452546
return &resp, nil
25462547
}
25472548

2549+
type PromoteReadReplicaRequest struct {
2550+
// Region: region to target. If none is passed will use default region from the config.
2551+
Region scw.Region `json:"-"`
2552+
// ReadReplicaID: UUID of the Read Replica.
2553+
ReadReplicaID string `json:"-"`
2554+
}
2555+
2556+
// PromoteReadReplica: promote a Read Replica.
2557+
// Promote a Read Replica to Database Instance automatically.
2558+
func (s *API) PromoteReadReplica(req *PromoteReadReplicaRequest, opts ...scw.RequestOption) (*Instance, error) {
2559+
var err error
2560+
2561+
if req.Region == "" {
2562+
defaultRegion, _ := s.client.GetDefaultRegion()
2563+
req.Region = defaultRegion
2564+
}
2565+
2566+
if fmt.Sprint(req.Region) == "" {
2567+
return nil, errors.New("field Region cannot be empty in request")
2568+
}
2569+
2570+
if fmt.Sprint(req.ReadReplicaID) == "" {
2571+
return nil, errors.New("field ReadReplicaID cannot be empty in request")
2572+
}
2573+
2574+
scwReq := &scw.ScalewayRequest{
2575+
Method: "POST",
2576+
Path: "/rdb/v1/regions/" + fmt.Sprint(req.Region) + "/read-replicas/" + fmt.Sprint(req.ReadReplicaID) + "/promote",
2577+
Headers: http.Header{},
2578+
}
2579+
2580+
err = scwReq.SetBody(req)
2581+
if err != nil {
2582+
return nil, err
2583+
}
2584+
2585+
var resp Instance
2586+
2587+
err = s.client.Do(scwReq, &resp, opts...)
2588+
if err != nil {
2589+
return nil, err
2590+
}
2591+
return &resp, nil
2592+
}
2593+
25482594
type CreateReadReplicaEndpointRequest struct {
25492595
// Region: region to target. If none is passed will use default region from the config.
25502596
Region scw.Region `json:"-"`

0 commit comments

Comments
 (0)