Skip to content

Commit d180de6

Browse files
add support for advanced mysql config get and patch operations (#1885)
Co-authored-by: Ganga Singh <gangasingh1807@gmail.com>
1 parent 3991b4b commit d180de6

5 files changed

Lines changed: 175 additions & 18 deletions

File tree

commands/databases.go

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,6 +2659,7 @@ For a full list of available fields, see the API documentation: https://docs.dig
26592659
displayerType(&displayers.MySQLConfiguration{}),
26602660
displayerType(&displayers.PostgreSQLConfiguration{}),
26612661
displayerType(&displayers.AdvancedPostgresConfiguration{}),
2662+
displayerType(&displayers.AdvancedMySQLConfiguration{}),
26622663
displayerType(&displayers.RedisConfiguration{}),
26632664
displayerType(&displayers.ValkeyConfiguration{}),
26642665
displayerType(&displayers.MongoDBConfiguration{}),
@@ -2719,17 +2720,18 @@ func RunDatabaseConfigurationGet(c *CmdConfig) error {
27192720
}
27202721

27212722
allowedEngines := map[string]any{
2722-
"mysql": nil,
2723-
"pg": nil,
2724-
"advanced_pg": nil,
2725-
"redis": nil,
2726-
"valkey": nil,
2727-
"mongodb": nil,
2728-
"kafka": nil,
2729-
"opensearch": nil,
2723+
"mysql": nil,
2724+
"pg": nil,
2725+
"advanced_pg": nil,
2726+
"advanced_mysql": nil,
2727+
"redis": nil,
2728+
"valkey": nil,
2729+
"mongodb": nil,
2730+
"kafka": nil,
2731+
"opensearch": nil,
27302732
}
27312733
if _, ok := allowedEngines[engine]; !ok {
2732-
return fmt.Errorf("(%s) command: engine must be one of: 'pg', 'advanced_pg', 'mysql', 'redis', 'valkey', 'mongodb', 'kafka', opensearch", c.NS)
2734+
return fmt.Errorf("(%s) command: engine must be one of: 'pg', 'advanced_pg', 'mysql', 'advanced_mysql', 'redis', 'valkey', 'mongodb', 'kafka', opensearch", c.NS)
27332735
}
27342736

27352737
dbId := args[0]
@@ -2763,6 +2765,16 @@ func RunDatabaseConfigurationGet(c *CmdConfig) error {
27632765
AdvancedPostgresConfig: *config,
27642766
}
27652767
return c.Display(&displayer)
2768+
} else if engine == "advanced_mysql" {
2769+
config, err := c.Databases().GetAdvancedMySQLConfiguration(dbId)
2770+
if err != nil {
2771+
return err
2772+
}
2773+
2774+
displayer := displayers.AdvancedMySQLConfiguration{
2775+
AdvancedMySQLConfig: *config,
2776+
}
2777+
return c.Display(&displayer)
27662778
} else if engine == "redis" {
27672779
config, err := c.Databases().GetRedisConfiguration(dbId)
27682780
if err != nil {
@@ -2833,17 +2845,18 @@ func RunDatabaseConfigurationUpdate(c *CmdConfig) error {
28332845
}
28342846

28352847
allowedEngines := map[string]any{
2836-
"mysql": nil,
2837-
"pg": nil,
2838-
"advanced_pg": nil,
2839-
"redis": nil,
2840-
"valkey": nil,
2841-
"mongodb": nil,
2842-
"kafka": nil,
2843-
"opensearch": nil,
2848+
"mysql": nil,
2849+
"pg": nil,
2850+
"advanced_pg": nil,
2851+
"advanced_mysql": nil,
2852+
"redis": nil,
2853+
"valkey": nil,
2854+
"mongodb": nil,
2855+
"kafka": nil,
2856+
"opensearch": nil,
28442857
}
28452858
if _, ok := allowedEngines[engine]; !ok {
2846-
return fmt.Errorf("(%s) command: engine must be one of: 'pg', 'advanced_pg', 'mysql', 'redis', 'valkey', 'mongodb', 'kafka', 'opensearch'", c.NS)
2859+
return fmt.Errorf("(%s) command: engine must be one of: 'pg', 'advanced_pg', 'mysql', 'advanced_mysql', 'redis', 'valkey', 'mongodb', 'kafka', 'opensearch'", c.NS)
28472860
}
28482861

28492862
configJson, err := c.Doit.GetString(c.NS, doctl.ArgDatabaseConfigJson)
@@ -2867,6 +2880,11 @@ func RunDatabaseConfigurationUpdate(c *CmdConfig) error {
28672880
if err != nil {
28682881
return err
28692882
}
2883+
} else if engine == "advanced_mysql" {
2884+
err := c.Databases().UpdateAdvancedMySQLConfiguration(dbId, configJson)
2885+
if err != nil {
2886+
return err
2887+
}
28702888
} else if engine == "redis" {
28712889
err := c.Databases().UpdateRedisConfiguration(dbId, configJson)
28722890
if err != nil {

commands/databases_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,19 @@ var (
232232
},
233233
}
234234

235+
testAdvancedMySQLConfiguration = do.AdvancedMySQLConfig{
236+
AdvancedMySQLConfig: &godo.AdvancedMySQLConfig{
237+
MySQLParameters: []godo.AdvancedMySQLParameter{
238+
{
239+
Name: "max_connections",
240+
Value: "151",
241+
DefaultValue: "151",
242+
RequiresRestart: false,
243+
},
244+
},
245+
},
246+
}
247+
235248
testRedisConfiguration = do.RedisConfig{
236249
RedisConfig: &godo.RedisConfig{},
237250
}
@@ -1796,6 +1809,16 @@ func TestDatabaseConfigurationGet(t *testing.T) {
17961809
assert.NoError(t, err)
17971810
})
17981811

1812+
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
1813+
tm.databases.EXPECT().GetAdvancedMySQLConfiguration(testDBCluster.ID).Return(&testAdvancedMySQLConfiguration, nil)
1814+
config.Args = append(config.Args, testDBCluster.ID)
1815+
config.Doit.Set(config.NS, doctl.ArgDatabaseEngine, "advanced_mysql")
1816+
1817+
err := RunDatabaseConfigurationGet(config)
1818+
1819+
assert.NoError(t, err)
1820+
})
1821+
17991822
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
18001823
tm.databases.EXPECT().GetRedisConfiguration(testDBCluster.ID).Return(&testRedisConfiguration, nil)
18011824
config.Args = append(config.Args, testDBCluster.ID)
@@ -1890,6 +1913,16 @@ func TestDatabaseConfigurationUpdate(t *testing.T) {
18901913
assert.NoError(t, err)
18911914
})
18921915

1916+
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
1917+
tm.databases.EXPECT().UpdateAdvancedMySQLConfiguration(testDBCluster.ID, "").Return(nil)
1918+
config.Args = append(config.Args, testDBCluster.ID)
1919+
config.Doit.Set(config.NS, doctl.ArgDatabaseEngine, "advanced_mysql")
1920+
1921+
err := RunDatabaseConfigurationUpdate(config)
1922+
1923+
assert.NoError(t, err)
1924+
})
1925+
18931926
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
18941927
tm.databases.EXPECT().UpdateRedisConfiguration(testDBCluster.ID, "").Return(nil)
18951928
config.Args = append(config.Args, testDBCluster.ID)

commands/displayers/database.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,6 +2382,50 @@ func (dc *AdvancedPostgresConfiguration) KV() []map[string]any {
23822382
return o
23832383
}
23842384

2385+
type AdvancedMySQLConfiguration struct {
2386+
AdvancedMySQLConfig do.AdvancedMySQLConfig
2387+
}
2388+
2389+
var _ Displayable = &AdvancedMySQLConfiguration{}
2390+
2391+
func (dc *AdvancedMySQLConfiguration) JSON(out io.Writer) error {
2392+
return writeJSON(dc.AdvancedMySQLConfig, out)
2393+
}
2394+
2395+
func (dc *AdvancedMySQLConfiguration) Cols() []string {
2396+
return []string{
2397+
"Name",
2398+
"Value",
2399+
"Default Value",
2400+
"Requires Restart",
2401+
"Description",
2402+
}
2403+
}
2404+
2405+
func (dc *AdvancedMySQLConfiguration) ColMap() map[string]string {
2406+
return map[string]string{
2407+
"Name": "Name",
2408+
"Value": "Value",
2409+
"Default Value": "Default Value",
2410+
"Requires Restart": "Requires Restart",
2411+
"Description": "Description",
2412+
}
2413+
}
2414+
2415+
func (dc *AdvancedMySQLConfiguration) KV() []map[string]any {
2416+
o := []map[string]any{}
2417+
for _, p := range dc.AdvancedMySQLConfig.MySQLParameters {
2418+
o = append(o, map[string]any{
2419+
"Name": p.Name,
2420+
"Value": p.Value,
2421+
"Default Value": p.DefaultValue,
2422+
"Requires Restart": p.RequiresRestart,
2423+
"Description": p.Description,
2424+
})
2425+
}
2426+
return o
2427+
}
2428+
23852429
type DatabaseEvents struct {
23862430
DatabaseEvents do.DatabaseEvents
23872431
}

do/databases.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ type AdvancedPostgresConfig struct {
125125
*godo.AdvancedPostgresConfig
126126
}
127127

128+
// AdvancedMySQLConfig is a wrapper for godo.AdvancedMySQLConfig
129+
type AdvancedMySQLConfig struct {
130+
*godo.AdvancedMySQLConfig
131+
}
132+
128133
// RedisConfig is a wrapper for godo.RedisConfig
129134
type RedisConfig struct {
130135
*godo.RedisConfig
@@ -233,6 +238,7 @@ type DatabasesService interface {
233238
GetMySQLConfiguration(databaseID string) (*MySQLConfig, error)
234239
GetPostgreSQLConfiguration(databaseID string) (*PostgreSQLConfig, error)
235240
GetAdvancedPostgresConfiguration(databaseID string) (*AdvancedPostgresConfig, error)
241+
GetAdvancedMySQLConfiguration(databaseID string) (*AdvancedMySQLConfig, error)
236242
GetRedisConfiguration(databaseID string) (*RedisConfig, error)
237243
GetValkeyConfiguration(databaseID string) (*ValkeyConfig, error)
238244
GetMongoDBConfiguration(databaseID string) (*MongoDBConfig, error)
@@ -242,6 +248,7 @@ type DatabasesService interface {
242248
UpdateMySQLConfiguration(databaseID string, confString string) error
243249
UpdatePostgreSQLConfiguration(databaseID string, confString string) error
244250
UpdateAdvancedPostgresConfiguration(databaseID string, confString string) error
251+
UpdateAdvancedMySQLConfiguration(databaseID string, confString string) error
245252
UpdateRedisConfiguration(databaseID string, confString string) error
246253
UpdateValkeyConfiguration(databaseID string, confString string) error
247254
UpdateMongoDBConfiguration(databaseID string, confString string) error
@@ -753,6 +760,17 @@ func (ds *databasesService) GetAdvancedPostgresConfiguration(databaseID string)
753760
}, nil
754761
}
755762

763+
func (ds *databasesService) GetAdvancedMySQLConfiguration(databaseID string) (*AdvancedMySQLConfig, error) {
764+
cfg, _, err := ds.client.Databases.GetAdvancedMySQLConfig(context.TODO(), databaseID)
765+
if err != nil {
766+
return nil, err
767+
}
768+
769+
return &AdvancedMySQLConfig{
770+
AdvancedMySQLConfig: cfg,
771+
}, nil
772+
}
773+
756774
func (ds *databasesService) GetRedisConfiguration(databaseID string) (*RedisConfig, error) {
757775
cfg, _, err := ds.client.Databases.GetRedisConfig(context.TODO(), databaseID)
758776
if err != nil {
@@ -853,6 +871,21 @@ func (ds *databasesService) UpdateAdvancedPostgresConfiguration(databaseID strin
853871
return nil
854872
}
855873

874+
func (ds *databasesService) UpdateAdvancedMySQLConfiguration(databaseID string, confString string) error {
875+
var conf godo.AdvancedMySQLConfigUpdate
876+
err := json.Unmarshal([]byte(confString), &conf)
877+
if err != nil {
878+
return err
879+
}
880+
881+
_, err = ds.client.Databases.UpdateAdvancedMySQLConfig(context.TODO(), databaseID, &conf)
882+
if err != nil {
883+
return err
884+
}
885+
886+
return nil
887+
}
888+
856889
func (ds *databasesService) UpdateRedisConfiguration(databaseID string, confString string) error {
857890
var conf godo.RedisConfig
858891
err := json.Unmarshal([]byte(confString), &conf)

do/mocks/DatabasesService.go

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)