Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 2 additions & 5 deletions internal/cmd/branch/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ func CreateCmd(ch *cmdutil.Helper) *cobra.Command {
if flags.backupID != "" && flags.parentBranch != "" && flags.restorePoint == "" {
return fmt.Errorf("--from and --restore cannot be used together")
}
if cmd.Flags().Changed("replicas") && flags.backupID == "" && flags.restorePoint == "" {
return fmt.Errorf("--replicas can only be used with a PostgreSQL backup restore or point-in-time recovery")
}
if (cmd.Flags().Changed("storage-iops") || cmd.Flags().Changed("storage-throughput")) && flags.backupID == "" && flags.restorePoint == "" {
return fmt.Errorf("--storage-iops and --storage-throughput can only be used with a PostgreSQL backup restore or point-in-time recovery")
}
Expand Down Expand Up @@ -140,7 +137,7 @@ func CreateCmd(ch *cmdutil.Helper) *cobra.Command {

if db.Kind == "mysql" {
if cmd.Flags().Changed("replicas") {
return fmt.Errorf("--replicas is only supported for PostgreSQL backup restores and point-in-time recovery")
return fmt.Errorf("--replicas is only supported for PostgreSQL databases")
}
if cmd.Flags().Changed("min-storage") || cmd.Flags().Changed("max-storage") {
return fmt.Errorf("--min-storage and --max-storage are only supported for PostgreSQL databases")
Expand Down Expand Up @@ -313,7 +310,7 @@ func CreateCmd(ch *cmdutil.Helper) *cobra.Command {
cmd.Flags().BoolVar(&flags.dataBranching, "seed-data", false, "Add seed data using the Data Branching™ feature. This branch will be created with the same resources as the base branch.")
cmd.Flags().BoolVar(&flags.wait, "wait", false, "Wait until the branch is ready")
cmd.Flags().StringVar(&flags.majorVersion, "major-version", "", "For PostgreSQL databases, the PostgreSQL major version to use for the branch. Defaults to the major version of the parent branch if it exists or the database's default branch major version. Ignored for branches restored from backups.")
cmd.Flags().IntVar(&flags.replicas, "replicas", 0, "Number of additional replicas for a PostgreSQL restore. 0 creates a single-node branch; omit to use the target cluster size default.")
cmd.Flags().IntVar(&flags.replicas, "replicas", 0, "Number of replicas for a PostgreSQL branch. 0 is a single-node branch with no replicas; 2-8 is HA. Omit to use the cluster size default.")
cmd.Flags().Int64Var(&flags.minStorage, "min-storage", 0, "Minimum storage size in bytes")
cmd.Flags().Int64Var(&flags.maxStorage, "max-storage", 0, "Maximum storage size in bytes for autoscaling")
cmd.Flags().Int64Var(&flags.storageIOPS, "storage-iops", 0, "Storage IOPS for a PostgreSQL restore. Requires --restore or --restore-point.")
Expand Down
34 changes: 9 additions & 25 deletions internal/cmd/branch/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1275,15 +1275,19 @@ func TestBranch_CreateCmdWithRestorePointMySQLError(t *testing.T) {
c.Assert(svc.CreateFnInvoked, qt.IsFalse)
}

func TestBranch_CreateCmdWithPostgresRestoreReplicas(t *testing.T) {
func TestBranch_CreateCmdWithPostgresReplicas(t *testing.T) {
zero := 0
two := 2
tests := []struct {
name string
args []string
wantReplicas *int
wantBackupID string
}{
{name: "omitted", args: []string{"planetscale", "restored", "--restore", "backup-id"}},
{name: "explicit zero", args: []string{"planetscale", "restored", "--restore", "backup-id", "--replicas", "0"}, wantReplicas: &zero},
{name: "restore omitted", args: []string{"planetscale", "restored", "--restore", "backup-id"}, wantBackupID: "backup-id"},
{name: "restore explicit zero", args: []string{"planetscale", "restored", "--restore", "backup-id", "--replicas", "0"}, wantReplicas: &zero, wantBackupID: "backup-id"},
{name: "ordinary branch", args: []string{"planetscale", "development", "--replicas", "2"}, wantReplicas: &two},
{name: "ordinary explicit zero", args: []string{"planetscale", "development", "--replicas", "0"}, wantReplicas: &zero},
}

for _, tt := range tests {
Expand All @@ -1295,10 +1299,10 @@ func TestBranch_CreateCmdWithPostgresRestoreReplicas(t *testing.T) {
p := printer.NewPrinter(&format)
p.SetResourceOutput(&buf)

res := &ps.PostgresBranch{Name: "restored"}
res := &ps.PostgresBranch{Name: tt.args[1]}
svc := &mock.PostgresBranchesService{
CreateFn: func(ctx context.Context, req *ps.CreatePostgresBranchRequest) (*ps.PostgresBranch, error) {
c.Assert(req.BackupID, qt.Equals, "backup-id")
c.Assert(req.BackupID, qt.Equals, tt.wantBackupID)
if tt.wantReplicas == nil {
c.Assert(req.Replicas, qt.IsNil)
} else {
Expand Down Expand Up @@ -1331,26 +1335,6 @@ func TestBranch_CreateCmdWithPostgresRestoreReplicas(t *testing.T) {
}
}

func TestBranch_CreateCmdRejectsReplicasWithoutRestore(t *testing.T) {
tests := []struct {
name string
args []string
}{
{name: "ordinary branch", args: []string{"planetscale", "development", "--replicas", "2"}},
{name: "data branching", args: []string{"planetscale", "development", "--seed-data", "--replicas", "2"}},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := qt.New(t)
cmd := CreateCmd(&cmdutil.Helper{})
cmd.SetArgs(tt.args)

c.Assert(cmd.Execute(), qt.ErrorMatches, ".*--replicas can only be used with a PostgreSQL backup restore or point-in-time recovery.*")
})
}
}

func TestBranch_CreateCmdRejectsRestoreReplicasForMySQL(t *testing.T) {
c := qt.New(t)

Expand Down