Skip to content

Commit 0558237

Browse files
Yordanisslooslaandrewsomething
authored
ISSUE: 1585 | Add --wait flag to databases resize command (#1590)
* ISSUE: 1585 * added bool flag into resize command * added wait functionality into resize * adjusted test * ISSUES:1585 + clean up with fmt * ISSUES:1585 + clean up make go fmt * ISSUES:1585 + removed test option to make it similar to create command * ISSUES:1585 + added new test case with wait flag + simplify logic in function * Small copy adjustment. --------- Co-authored-by: Anna Lushnikova <[email protected]> Co-authored-by: Andrew Starr-Bochicchio <[email protected]>
1 parent 6804c7d commit 0558237

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

commands/databases.go

+31-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ For PostgreSQL and MySQL clusters, you can also provide a disk size in MiB to sc
135135
AddIntFlag(cmdDatabaseResize, doctl.ArgDatabaseNumNodes, "", 0, nodeNumberDetails, requiredOpt())
136136
AddStringFlag(cmdDatabaseResize, doctl.ArgSizeSlug, "", "", nodeSizeDetails, requiredOpt())
137137
AddIntFlag(cmdDatabaseResize, doctl.ArgDatabaseStorageSizeMib, "", 0, storageSizeMiBDetails)
138-
cmdDatabaseResize.Example = `The following example resizes a PostgreSQL or MySQL database to have two nodes, 16 vCPUs, 64 GB of memory, and 2048 GiB of storage space: doctl databases resize ca9f591d-9999-5555-a0ef-1c02d1d1e352 --num-nodes 2 --size db-s-16vcpu-64gb --storage-size-mib 2048000`
138+
AddBoolFlag(cmdDatabaseResize, doctl.ArgCommandWait, "", false,
139+
"Boolean that specifies whether to wait for the resize to complete before returning control to the terminal")
140+
cmdDatabaseResize.Example = `The following example resizes a PostgreSQL or MySQL database to have two nodes, 16 vCPUs, 64 GB of memory, and 2048 GiB of storage space: doctl databases resize ca9f591d-9999-5555-a0ef-1c02d1d1e352 --num-nodes 2 --size db-s-16vcpu-64gb --storage-size-mib 2048000 --wait true`
139141

140142
cmdDatabaseMigrate := CmdBuilder(cmd, RunDatabaseMigrate, "migrate <database-cluster-id>", "Migrate a database cluster to a new region", `Migrates the specified database cluster to a new region.`, Writer,
141143
aliasOpt("m"))
@@ -511,13 +513,40 @@ func RunDatabaseResize(c *CmdConfig) error {
511513
}
512514

513515
id := c.Args[0]
516+
dbs := c.Databases()
514517

515518
r, err := buildDatabaseResizeRequestFromArgs(c)
516519
if err != nil {
517520
return err
518521
}
519522

520-
return c.Databases().Resize(id, r)
523+
// Resize the database
524+
err = dbs.Resize(id, r)
525+
if err != nil {
526+
return err
527+
}
528+
529+
// Check if the --wait flag was passed
530+
wait, err := c.Doit.GetBool(c.NS, doctl.ArgCommandWait)
531+
if err != nil {
532+
return err
533+
}
534+
535+
if wait {
536+
notice("Database resizing is in progress, waiting for database to be online")
537+
538+
err := waitForDatabaseReady(dbs, id)
539+
if err != nil {
540+
return fmt.Errorf(
541+
"database couldn't enter the `online` state after resizing: %v",
542+
err,
543+
)
544+
}
545+
546+
notice("Database resized successfully")
547+
}
548+
549+
return nil
521550
}
522551

523552
func buildDatabaseResizeRequestFromArgs(c *CmdConfig) (*godo.DatabaseResizeRequest, error) {

commands/databases_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,20 @@ func TestDatabaseResize(t *testing.T) {
634634
assert.NoError(t, err)
635635
})
636636

637+
// Success with wait flag
638+
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
639+
tm.databases.EXPECT().Resize(testDBCluster.ID, r).Return(nil)
640+
tm.databases.EXPECT().Get(testDBCluster.ID).Return(&testDBCluster, nil)
641+
config.Args = append(config.Args, testDBCluster.ID)
642+
config.Doit.Set(config.NS, doctl.ArgSizeSlug, testDBCluster.SizeSlug)
643+
config.Doit.Set(config.NS, doctl.ArgDatabaseNumNodes, testDBCluster.NumNodes)
644+
config.Doit.Set(config.NS, doctl.ArgDatabaseStorageSizeMib, testDBCluster.StorageSizeMib)
645+
config.Doit.Set(config.NS, doctl.ArgCommandWait, true)
646+
647+
err := RunDatabaseResize(config)
648+
assert.NoError(t, err)
649+
})
650+
637651
// Error
638652
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
639653
tm.databases.EXPECT().Resize(testDBCluster.ID, r).Return(errTest)

0 commit comments

Comments
 (0)