Skip to content

Commit

Permalink
wait for db to be ready before showing creds
Browse files Browse the repository at this point in the history
  • Loading branch information
uzaxirr committed Feb 5, 2025
1 parent 8d3583a commit 1c0e673
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cmd/database/database_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"fmt"
"os"
"strings"
"time"

"github.com/briandowns/spinner"

"github.com/civo/cli/common"
"github.com/civo/cli/config"
Expand Down Expand Up @@ -41,6 +44,26 @@ var dbCredentialCmd = &cobra.Command{
os.Exit(1)
}

// Add check for database status
if db.Status == "Pending" {
fmt.Printf("The DB %s is currently being provisioned, please wait...\n", utility.Green(db.Name))

s := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
s.Writer = os.Stderr
s.Prefix = fmt.Sprintf("Waiting for database (%s)... ", db.Name)
s.Start()

for db.Status == "Pending" {
db, err = client.FindDatabase(args[0])
if err != nil {
utility.Error("%s", err)
os.Exit(1)
}
time.Sleep(2 * time.Second)
}
s.Stop()
}

connStr := strings.ToLower(db.Software) + "://" + db.DatabaseUserInfo[0].Username + ":" + db.DatabaseUserInfo[0].Password + "@" + db.PublicIPv4 + ":" + fmt.Sprintf("%d", db.DatabaseUserInfo[0].Port)

if connectionString {
Expand Down

0 comments on commit 1c0e673

Please sign in to comment.