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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/mattn/go-shellwords v1.0.12
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
github.com/planetscale/planetscale-go v0.153.0
github.com/planetscale/planetscale-go v0.154.0
github.com/planetscale/psdb v0.0.0-20250717190954-65c6661ab6e4
github.com/planetscale/psdbproxy v0.0.0-20250728082226-3f4ea3a74ec7
github.com/spf13/cobra v1.10.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ github.com/planetscale/noglog v0.2.1-0.20210421230640-bea75fcd2e8e h1:MZ8D+Z3m2v
github.com/planetscale/noglog v0.2.1-0.20210421230640-bea75fcd2e8e/go.mod h1:hwAsSPQdvPa3WcfKfzTXxtEq/HlqwLjQasfO6QbGo4Q=
github.com/planetscale/planetscale-go v0.153.0 h1:b+X6JUvPkhjv083b+b8IHsv8INNMvvGwANjIGQOfMlM=
github.com/planetscale/planetscale-go v0.153.0/go.mod h1:paQCI5SgquuoewvMQM7R+r1XJO868bdP6/ihGidYRM0=
github.com/planetscale/planetscale-go v0.154.0 h1:bHBiOlGy7Cs7FDFmQgjjJnGUr2xPlqlB3uVPbh/Kl2Q=
github.com/planetscale/planetscale-go v0.154.0/go.mod h1:paQCI5SgquuoewvMQM7R+r1XJO868bdP6/ihGidYRM0=
github.com/planetscale/psdb v0.0.0-20250717190954-65c6661ab6e4 h1:Xv5pj20Rhfty1Tv0OVcidg4ez4PvGrpKvb6rvUwQgDs=
github.com/planetscale/psdb v0.0.0-20250717190954-65c6661ab6e4/go.mod h1:M52h5IWxAcbdQ1hSZrLAGQC4ZXslxEsK/Wh9nu3wdWs=
github.com/planetscale/psdbproxy v0.0.0-20250728082226-3f4ea3a74ec7 h1:aRd6vdE1fyuSI4RVj7oCr8lFmgqXvpnPUmN85VbZCp8=
Expand Down
49 changes: 49 additions & 0 deletions internal/cmd/branch/vtctld/vdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func VDiffCmd(ch *cmdutil.Helper) *cobra.Command {
Short: "Manage VDiff operations",
}

cmd.AddCommand(VDiffListCmd(ch))
cmd.AddCommand(VDiffCreateCmd(ch))
cmd.AddCommand(VDiffShowCmd(ch))
cmd.AddCommand(VDiffStopCmd(ch))
Expand All @@ -24,6 +25,54 @@ func VDiffCmd(ch *cmdutil.Helper) *cobra.Command {
return cmd
}

func VDiffListCmd(ch *cmdutil.Helper) *cobra.Command {
var flags struct {
workflow string
targetKeyspace string
}

cmd := &cobra.Command{
Use: "list <database> <branch>",
Short: "List VDiffs",
Args: cmdutil.RequiredArgs("database", "branch"),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
database, branch := args[0], args[1]

client, err := ch.Client()
if err != nil {
return err
}

end := ch.Printer.PrintProgress(
fmt.Sprintf("Fetching VDiffs for workflow %s on %s/%s\u2026",
printer.BoldBlue(flags.workflow), printer.BoldBlue(database), printer.BoldBlue(branch)))
defer end()

data, err := client.VDiff.List(ctx, &ps.VDiffListRequest{
Organization: ch.Config.Organization,
Database: database,
Branch: branch,
Workflow: flags.workflow,
TargetKeyspace: flags.targetKeyspace,
})
if err != nil {
return cmdutil.HandleError(err)
}

end()
return ch.Printer.PrettyPrintJSON(data)
},
}

cmd.Flags().StringVar(&flags.workflow, "workflow", "", "Name of the workflow")
cmd.Flags().StringVar(&flags.targetKeyspace, "target-keyspace", "", "Target keyspace")
cmd.MarkFlagRequired("workflow") // nolint:errcheck
cmd.MarkFlagRequired("target-keyspace") // nolint:errcheck

return cmd
}

func VDiffCreateCmd(ch *cmdutil.Helper) *cobra.Command {
var flags struct {
workflow string
Expand Down
43 changes: 43 additions & 0 deletions internal/cmd/branch/vtctld/vdiff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,49 @@ func TestVDiffCreate(t *testing.T) {
c.Assert(svc.CreateFnInvoked, qt.IsTrue)
}

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

org := "my-org"
db := "my-db"
branch := "my-branch"

svc := &mock.VDiffService{
ListFn: func(ctx context.Context, req *ps.VDiffListRequest) (json.RawMessage, error) {
c.Assert(req.Organization, qt.Equals, org)
c.Assert(req.Database, qt.Equals, db)
c.Assert(req.Branch, qt.Equals, branch)
c.Assert(req.Workflow, qt.Equals, "my-workflow")
c.Assert(req.TargetKeyspace, qt.Equals, "target-ks")
return json.RawMessage(`{"vdiffs":[]}`), nil
},
}

var buf bytes.Buffer
format := printer.JSON
p := printer.NewPrinter(&format)
p.SetResourceOutput(&buf)

ch := &cmdutil.Helper{
Printer: p,
Config: &config.Config{Organization: org},
Client: func() (*ps.Client, error) {
return &ps.Client{
VDiff: svc,
}, nil
},
}

cmd := VDiffCmd(ch)
cmd.SetArgs([]string{"list", db, branch,
"--workflow", "my-workflow",
"--target-keyspace", "target-ks",
})
err := cmd.Execute()
c.Assert(err, qt.IsNil)
c.Assert(svc.ListFnInvoked, qt.IsTrue)
}

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

Expand Down
8 changes: 8 additions & 0 deletions internal/mock/vtctld_vdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ type VDiffService struct {
CreateFn func(context.Context, *ps.VDiffCreateRequest) (json.RawMessage, error)
CreateFnInvoked bool

ListFn func(context.Context, *ps.VDiffListRequest) (json.RawMessage, error)
ListFnInvoked bool

ShowFn func(context.Context, *ps.VDiffShowRequest) (json.RawMessage, error)
ShowFnInvoked bool

Expand All @@ -29,6 +32,11 @@ func (s *VDiffService) Create(ctx context.Context, req *ps.VDiffCreateRequest) (
return s.CreateFn(ctx, req)
}

func (s *VDiffService) List(ctx context.Context, req *ps.VDiffListRequest) (json.RawMessage, error) {
s.ListFnInvoked = true
return s.ListFn(ctx, req)
}

func (s *VDiffService) Show(ctx context.Context, req *ps.VDiffShowRequest) (json.RawMessage, error) {
s.ShowFnInvoked = true
return s.ShowFn(ctx, req)
Expand Down
Loading