Skip to content

Commit

Permalink
feat(rdb): promote read replica (#1785)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaleway-bot committed Jul 21, 2023
1 parent 785dc16 commit 6966aee
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions api/rdb/v1/rdb_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ const (
ReadReplicaStatusError = ReadReplicaStatus("error")
ReadReplicaStatusLocked = ReadReplicaStatus("locked")
ReadReplicaStatusConfiguring = ReadReplicaStatus("configuring")
ReadReplicaStatusPromoting = ReadReplicaStatus("promoting")
)

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

type PromoteReadReplicaRequest struct {
// Region: region to target. If none is passed will use default region from the config.
Region scw.Region `json:"-"`
// ReadReplicaID: UUID of the Read Replica.
ReadReplicaID string `json:"-"`
}

// PromoteReadReplica: promote a Read Replica.
// Promote a Read Replica to Database Instance automatically.
func (s *API) PromoteReadReplica(req *PromoteReadReplicaRequest, opts ...scw.RequestOption) (*Instance, error) {
var err error

if req.Region == "" {
defaultRegion, _ := s.client.GetDefaultRegion()
req.Region = defaultRegion
}

if fmt.Sprint(req.Region) == "" {
return nil, errors.New("field Region cannot be empty in request")
}

if fmt.Sprint(req.ReadReplicaID) == "" {
return nil, errors.New("field ReadReplicaID cannot be empty in request")
}

scwReq := &scw.ScalewayRequest{
Method: "POST",
Path: "/rdb/v1/regions/" + fmt.Sprint(req.Region) + "/read-replicas/" + fmt.Sprint(req.ReadReplicaID) + "/promote",
Headers: http.Header{},
}

err = scwReq.SetBody(req)
if err != nil {
return nil, err
}

var resp Instance

err = s.client.Do(scwReq, &resp, opts...)
if err != nil {
return nil, err
}
return &resp, nil
}

type CreateReadReplicaEndpointRequest struct {
// Region: region to target. If none is passed will use default region from the config.
Region scw.Region `json:"-"`
Expand Down

0 comments on commit 6966aee

Please sign in to comment.