Skip to content

Commit bbe6124

Browse files
SkySingh04loosla
andauthored
[feat:] Add --wait Flag to doctl databases migrate Command (#1591)
* closes #1584 added --wait flag to migrate command Signed-off-by: Akash <[email protected]> * Update commands/databases_test.go Co-authored-by: Anna Lushnikova <[email protected]> --------- Signed-off-by: Akash <[email protected]> Co-authored-by: Anna Lushnikova <[email protected]>
1 parent 0558237 commit bbe6124

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

commands/databases.go

+27-1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ For PostgreSQL and MySQL clusters, you can also provide a disk size in MiB to sc
143143
aliasOpt("m"))
144144
AddStringFlag(cmdDatabaseMigrate, doctl.ArgRegionSlug, "", "", "The region to which the database cluster should be migrated, such as `sfo2` or `nyc3`.", requiredOpt())
145145
AddStringFlag(cmdDatabaseMigrate, doctl.ArgPrivateNetworkUUID, "", "", "The UUID of a VPC network to create the database cluster in. The command uses the region's default VPC network if not specified.")
146+
AddBoolFlag(cmdDatabaseMigrate, doctl.ArgCommandWait, "", false, "A boolean value that specifies whether to wait for the database migration to complete before returning control to the terminal.")
146147

147148
cmdDatabaseFork := CmdBuilder(cmd, RunDatabaseFork, "fork <name>", "Create a new database cluster by forking an existing database cluster.", `Creates a new database cluster from an existing cluster. The forked database contains all of the data from the original database at the time the fork is created.`, Writer, aliasOpt("f"))
148149
AddStringFlag(cmdDatabaseFork, doctl.ArgDatabaseRestoreFromClusterID, "", "", "The ID of an existing database cluster from which the new database will be forked from", requiredOpt())
@@ -586,7 +587,32 @@ func RunDatabaseMigrate(c *CmdConfig) error {
586587
return err
587588
}
588589

589-
return c.Databases().Migrate(id, r)
590+
dbs := c.Databases()
591+
err = dbs.Migrate(id, r)
592+
if err != nil {
593+
return err
594+
}
595+
596+
wait, err := c.Doit.GetBool(c.NS, doctl.ArgCommandWait)
597+
if err != nil {
598+
return err
599+
}
600+
601+
if wait {
602+
notice("Database migration is in progress, waiting for database to be online")
603+
604+
err := waitForDatabaseReady(dbs, id)
605+
if err != nil {
606+
return fmt.Errorf(
607+
"database couldn't enter the `online` state after migration: %v",
608+
err,
609+
)
610+
}
611+
612+
notice("Database migrated successfully")
613+
}
614+
615+
return nil
590616
}
591617

592618
func buildDatabaseMigrateRequestFromArgs(c *CmdConfig) (*godo.DatabaseMigrateRequest, error) {

commands/databases_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,19 @@ func TestDatabaseMigrate(t *testing.T) {
603603
assert.NoError(t, err)
604604
})
605605

606+
// Success with wait flag
607+
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
608+
tm.databases.EXPECT().Migrate(testDBCluster.ID, r).Return(nil)
609+
tm.databases.EXPECT().Get(testDBCluster.ID).Return(&testDBCluster, nil).AnyTimes() // Polling for status
610+
config.Args = append(config.Args, testDBCluster.ID)
611+
config.Doit.Set(config.NS, doctl.ArgRegionSlug, testDBCluster.RegionSlug)
612+
config.Doit.Set(config.NS, doctl.ArgPrivateNetworkUUID, testDBCluster.PrivateNetworkUUID)
613+
config.Doit.Set(config.NS, doctl.ArgCommandWait, true)
614+
615+
err := RunDatabaseMigrate(config)
616+
assert.NoError(t, err)
617+
})
618+
606619
// Error
607620
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
608621
tm.databases.EXPECT().Migrate(testDBCluster.ID, r).Return(errTest)

0 commit comments

Comments
 (0)