From 4ea1434d7eca36839b01dbf96e873b534de94ec2 Mon Sep 17 00:00:00 2001 From: Rohit Nayak Date: Fri, 13 Sep 2024 22:44:31 +0200 Subject: [PATCH] Add validations Signed-off-by: Rohit Nayak --- .../vreplication/materialize/create.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/go/cmd/vtctldclient/command/vreplication/materialize/create.go b/go/cmd/vtctldclient/command/vreplication/materialize/create.go index 8765b354345..8d401d41ef0 100644 --- a/go/cmd/vtctldclient/command/vreplication/materialize/create.go +++ b/go/cmd/vtctldclient/command/vreplication/materialize/create.go @@ -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" @@ -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 @@ -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,