From 1bfe127d65e820fcb051f3fac469cf6ee12e744a Mon Sep 17 00:00:00 2001 From: Daniel-Weinshenker <9273337+dweinshenker@users.noreply.github.com> Date: Mon, 23 Jan 2023 11:10:47 -0800 Subject: [PATCH] Add UpgradeMajorVersion to godo (#595) * DBAAS-3899: Add UpgradeMajorVersion to godo * utilize struct instead of version string Co-authored-by: Daniel Weinshenker Co-authored-by: Cesar Garza --- databases.go | 64 +++++++++++++++++++++++++++++++---------------- databases_test.go | 24 ++++++++++++++++++ 2 files changed, 67 insertions(+), 21 deletions(-) diff --git a/databases.go b/databases.go index 4df10af9..c70e9656 100644 --- a/databases.go +++ b/databases.go @@ -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. @@ -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 @@ -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"` } @@ -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 +} diff --git a/databases_test.go b/databases_test.go index a34a4333..2c46dd61 100644 --- a/databases_test.go +++ b/databases_test.go @@ -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) +}