Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DBAAS-3906: Include updatePool for DB Clusters #596

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 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"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are any of the struct vales within the update request required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, size, database, and mode.

DMW2151 marked this conversation as resolved.
Show resolved Hide resolved
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,20 @@ 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) {
ChiefMateStarbuck marked this conversation as resolved.
Show resolved Hide resolved
path := fmt.Sprintf(databasePoolPath, databaseID, name)
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