Skip to content

Commit

Permalink
Add UpgradeMajorVersion to godo (#595)
Browse files Browse the repository at this point in the history
* DBAAS-3899: Add UpgradeMajorVersion to godo

* utilize struct instead of version string

Co-authored-by: Daniel Weinshenker <[email protected]>
Co-authored-by: Cesar Garza <[email protected]>
  • Loading branch information
3 people authored Jan 23, 2023
1 parent 3613833 commit 1bfe127
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 21 deletions.
64 changes: 43 additions & 21 deletions databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,28 @@ import (
)

const (
databaseBasePath = "/v2/databases"
databaseSinglePath = databaseBasePath + "/%s"
databaseCAPath = databaseBasePath + "/%s/ca"
databaseConfigPath = databaseBasePath + "/%s/config"
databaseResizePath = databaseBasePath + "/%s/resize"
databaseMigratePath = databaseBasePath + "/%s/migrate"
databaseMaintenancePath = databaseBasePath + "/%s/maintenance"
databaseBackupsPath = databaseBasePath + "/%s/backups"
databaseUsersPath = databaseBasePath + "/%s/users"
databaseUserPath = databaseBasePath + "/%s/users/%s"
databaseResetUserAuthPath = databaseUserPath + "/reset_auth"
databaseDBPath = databaseBasePath + "/%s/dbs/%s"
databaseDBsPath = databaseBasePath + "/%s/dbs"
databasePoolPath = databaseBasePath + "/%s/pools/%s"
databasePoolsPath = databaseBasePath + "/%s/pools"
databaseReplicaPath = databaseBasePath + "/%s/replicas/%s"
databaseReplicasPath = databaseBasePath + "/%s/replicas"
databaseEvictionPolicyPath = databaseBasePath + "/%s/eviction_policy"
databaseSQLModePath = databaseBasePath + "/%s/sql_mode"
databaseFirewallRulesPath = databaseBasePath + "/%s/firewall"
databaseOptionsPath = databaseBasePath + "/options"
databaseBasePath = "/v2/databases"
databaseSinglePath = databaseBasePath + "/%s"
databaseCAPath = databaseBasePath + "/%s/ca"
databaseConfigPath = databaseBasePath + "/%s/config"
databaseResizePath = databaseBasePath + "/%s/resize"
databaseMigratePath = databaseBasePath + "/%s/migrate"
databaseMaintenancePath = databaseBasePath + "/%s/maintenance"
databaseBackupsPath = databaseBasePath + "/%s/backups"
databaseUsersPath = databaseBasePath + "/%s/users"
databaseUserPath = databaseBasePath + "/%s/users/%s"
databaseResetUserAuthPath = databaseUserPath + "/reset_auth"
databaseDBPath = databaseBasePath + "/%s/dbs/%s"
databaseDBsPath = databaseBasePath + "/%s/dbs"
databasePoolPath = databaseBasePath + "/%s/pools/%s"
databasePoolsPath = databaseBasePath + "/%s/pools"
databaseReplicaPath = databaseBasePath + "/%s/replicas/%s"
databaseReplicasPath = databaseBasePath + "/%s/replicas"
databaseEvictionPolicyPath = databaseBasePath + "/%s/eviction_policy"
databaseSQLModePath = databaseBasePath + "/%s/sql_mode"
databaseFirewallRulesPath = databaseBasePath + "/%s/firewall"
databaseOptionsPath = databaseBasePath + "/options"
databaseUpgradeMajorVersionPath = databaseBasePath + "/%s/upgrade"
)

// SQL Mode constants allow for MySQL-specific SQL flavor configuration.
Expand Down Expand Up @@ -142,6 +143,7 @@ type DatabasesService interface {
UpdateRedisConfig(context.Context, string, *RedisConfig) (*Response, error)
UpdateMySQLConfig(context.Context, string, *MySQLConfig) (*Response, error)
ListOptions(todo context.Context) (*DatabaseOptions, *Response, error)
UpgradeMajorVersion(context.Context, string, *UpgradeVersionRequest) (*Response, error)
}

// DatabasesServiceOp handles communication with the Databases related methods
Expand Down Expand Up @@ -530,6 +532,10 @@ type evictionPolicyRoot struct {
EvictionPolicy string `json:"eviction_policy"`
}

type UpgradeVersionRequest struct {
Version string `json:"version"`
}

type sqlModeRoot struct {
SQLMode string `json:"sql_mode"`
}
Expand Down Expand Up @@ -1219,3 +1225,19 @@ func (svc *DatabasesServiceOp) ListOptions(ctx context.Context) (*DatabaseOption

return root.Options, resp, nil
}

// UpgradeMajorVersion upgrades the major version of a cluster.
func (svc *DatabasesServiceOp) UpgradeMajorVersion(ctx context.Context, databaseID string, upgradeReq *UpgradeVersionRequest) (*Response, error) {
path := fmt.Sprintf(databaseUpgradeMajorVersionPath, databaseID)
req, err := svc.client.NewRequest(ctx, http.MethodPut, path, upgradeReq)
if err != nil {
return nil, err
}

resp, err := svc.client.Do(ctx, req, nil)
if err != nil {
return resp, err
}

return resp, nil
}
24 changes: 24 additions & 0 deletions databases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2063,3 +2063,27 @@ func TestDatabases_UpdateConfigMySQL(t *testing.T) {
_, err := client.Databases.UpdateMySQLConfig(ctx, dbID, mySQLConfig)
require.NoError(t, err)
}

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

var (
dbID = "deadbeef-dead-4aa5-beef-deadbeef347d"
path = fmt.Sprintf("/v2/databases/%s/upgrade", dbID)
upgradeVersionReq = &UpgradeVersionRequest{
Version: "14",
}
)
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
var b UpgradeVersionRequest
decoder := json.NewDecoder(r.Body)
err := decoder.Decode(&b)
require.NoError(t, err)
assert.Equal(t, b.Version, upgradeVersionReq.Version)
w.WriteHeader(http.StatusNoContent)
})
_, err := client.Databases.UpgradeMajorVersion(ctx, dbID, upgradeVersionReq)
require.NoError(t, err)
}

0 comments on commit 1bfe127

Please sign in to comment.