Skip to content

Commit

Permalink
Add validations
Browse files Browse the repository at this point in the history
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
  • Loading branch information
rohit-nayak-ps committed Sep 15, 2024
1 parent b5dad41 commit cdfa6b3
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions go/cmd/vtctldclient/command/vreplication/materialize/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"fmt"
"strings"

vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/vterrors"

"github.com/spf13/cobra"

"vitess.io/vitess/go/cmd/vtctldclient/cli"
Expand All @@ -31,6 +34,8 @@ import (
vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
)

const missingCreateParams = "either --table-settings, for a regular Materialize workflow, or, --reference and --tables must be provided, if materializing reference tables"

var (
createOptions = struct {
SourceKeyspace string
Expand Down Expand Up @@ -77,6 +82,20 @@ should be copied as-is from the source keyspace. Here's an example value for tab
if err := common.ParseAndValidateCreateOptions(cmd); err != nil {
return err
}

var hasTableSettings, isReference bool
if createOptions.TableSettings.val != nil {
hasTableSettings = true
}
if common.CreateOptions.IsReference && len(common.CreateOptions.Tables) > 0 {
isReference = true
}
if !hasTableSettings && !isReference {
return vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, missingCreateParams)
}
if hasTableSettings && isReference {
return vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, "cannot specify both --table-settings and --reference/--tables")
}
return nil
},
RunE: commandCreate,
Expand Down

0 comments on commit cdfa6b3

Please sign in to comment.