Skip to content

Commit

Permalink
DBAAS-3906: Include updatePool for DB Clusters (#596)
Browse files Browse the repository at this point in the history
* include update pgpool call

* Update databases.go

add `omitempty` on `DatabaseUpdatePoolRequest` User field

Co-authored-by: Samuel Guyah <[email protected]>

* add validation on DatabasesUpdatePool

* add validation on DatabasesUpdatePool

* add validation on DatabasesUpdatePool

* add validation on DatabasesUpdatePool, check for nil updatePool

Co-authored-by: Samuel Guyah <[email protected]>
  • Loading branch information
DMW2151 and ChiefMateStarbuck authored Jan 18, 2023
1 parent 0d12938 commit 4018345
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
40 changes: 40 additions & 0 deletions databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ type DatabasesService interface {
CreatePool(context.Context, string, *DatabaseCreatePoolRequest) (*DatabasePool, *Response, error)
GetPool(context.Context, string, string) (*DatabasePool, *Response, error)
DeletePool(context.Context, string, string) (*Response, error)
UpdatePool(context.Context, string, string, *DatabaseUpdatePoolRequest) (*Response, error)
GetReplica(context.Context, string, string) (*DatabaseReplica, *Response, error)
ListReplicas(context.Context, string, *ListOptions) ([]DatabaseReplica, *Response, error)
CreateReplica(context.Context, string, *DatabaseCreateReplicaRequest) (*DatabaseReplica, *Response, error)
Expand Down Expand Up @@ -299,6 +300,14 @@ type DatabaseCreatePoolRequest struct {
Mode string `json:"mode"`
}

// DatabaseUpdatePoolRequest is used to update a database connection pool
type DatabaseUpdatePoolRequest struct {
User string `json:"user,omitempty"`
Size int `json:"size"`
Database string `json:"db"`
Mode string `json:"mode"`
}

// DatabaseCreateUserRequest is used to create a new database user
type DatabaseCreateUserRequest struct {
Name string `json:"name"`
Expand Down Expand Up @@ -904,6 +913,37 @@ func (svc *DatabasesServiceOp) DeletePool(ctx context.Context, databaseID, name
return resp, nil
}

// UpdatePool will update an existing database connection pool
func (svc *DatabasesServiceOp) UpdatePool(ctx context.Context, databaseID, name string, updatePool *DatabaseUpdatePoolRequest) (*Response, error) {
path := fmt.Sprintf(databasePoolPath, databaseID, name)

if updatePool == nil {
return nil, NewArgError("updatePool", "cannot be nil")
}

if updatePool.Mode == "" {
return nil, NewArgError("mode", "cannot be empty")
}

if updatePool.Database == "" {
return nil, NewArgError("database", "cannot be empty")
}

if updatePool.Size < 1 {
return nil, NewArgError("size", "cannot be less than 1")
}

req, err := svc.client.NewRequest(ctx, http.MethodPut, path, updatePool)
if err != nil {
return nil, err
}
resp, err := svc.client.Do(ctx, req, nil)
if err != nil {
return resp, err
}
return resp, nil
}

// GetReplica returns a single database replica
func (svc *DatabasesServiceOp) GetReplica(ctx context.Context, databaseID, name string) (*DatabaseReplica, *Response, error) {
path := fmt.Sprintf(databaseReplicaPath, databaseID, name)
Expand Down
21 changes: 21 additions & 0 deletions databases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,27 @@ func TestDatabases_DeletePool(t *testing.T) {
require.NoError(t, err)
}

func TestDatabases_UpdatePool(t *testing.T) {
setup()
defer teardown()

dbID := "deadbeef-dead-4aa5-beef-deadbeef347d"

path := fmt.Sprintf("/v2/databases/%s/pools/pool", dbID)

mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
})

_, err := client.Databases.UpdatePool(ctx, dbID, "pool", &DatabaseUpdatePoolRequest{
User: "user",
Size: 12,
Database: "db",
Mode: "transaction",
})
require.NoError(t, err)
}

func TestDatabases_GetReplica(t *testing.T) {
setup()
defer teardown()
Expand Down

0 comments on commit 4018345

Please sign in to comment.