Skip to content

Random db name #509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions cmd/database/database_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var dbCreateCmd = &cobra.Command{
Aliases: []string{"new", "add"},
Example: "civo db create <DATABASE-NAME> --size <SIZE> --software <SOFTWARE_NAME> --version <SOFTWARE_VERSION>",
Short: "Create a new database",
Args: cobra.MinimumNArgs(1),
Args: cobra.MinimumNArgs(0), // Change from 1 to 0 to make the name argument optional
Run: func(cmd *cobra.Command, args []string) {
utility.EnsureCurrentRegion()

Expand Down Expand Up @@ -133,15 +133,26 @@ var dbCreateCmd = &cobra.Command{

if !softwareVersionIsValid {
if softwareVersion == "" {
utility.Error(fmt.Sprintf("No version specified for %s. Please provide a version using --version flag. For example, civo database create db-psql --software psql --version 14", canonicalSoftwareName))
utility.Error("No version specified for %s. Please provide a version using --version flag. For example, civo database create db-psql --software psql --version 14", canonicalSoftwareName)
} else {
utility.Error("The provided software version is not valid. Please check the available versions for the specified software.")
utility.Error("The provided software version is not valid. Please check the available versions by typing civo db engine")
}
os.Exit(1)
}

var dbName string
if len(args) > 0 {
if utility.ValidNameLength(args[0]) {
utility.Warning("the database name cannot be longer than 63 characters")
os.Exit(1)
}
dbName = args[0]
} else {
dbName = utility.RandomName()
}

configDB := civogo.CreateDatabaseRequest{
Name: args[0],
Name: dbName,
Size: size,
NetworkID: network.ID,
Nodes: nodes,
Expand Down