Skip to content

Commit 3f8e7f5

Browse files
authored
Merge pull request #1215 from planetscale/add-vdiff-list-command
Add VDiff list command
2 parents 71a8c6e + b26f916 commit 3f8e7f5

5 files changed

Lines changed: 103 additions & 1 deletion

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ require (
2525
github.com/mattn/go-shellwords v1.0.12
2626
github.com/mitchellh/go-homedir v1.1.0
2727
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
28-
github.com/planetscale/planetscale-go v0.153.0
28+
github.com/planetscale/planetscale-go v0.154.0
2929
github.com/planetscale/psdb v0.0.0-20250717190954-65c6661ab6e4
3030
github.com/planetscale/psdbproxy v0.0.0-20250728082226-3f4ea3a74ec7
3131
github.com/spf13/cobra v1.10.2

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ github.com/planetscale/noglog v0.2.1-0.20210421230640-bea75fcd2e8e h1:MZ8D+Z3m2v
184184
github.com/planetscale/noglog v0.2.1-0.20210421230640-bea75fcd2e8e/go.mod h1:hwAsSPQdvPa3WcfKfzTXxtEq/HlqwLjQasfO6QbGo4Q=
185185
github.com/planetscale/planetscale-go v0.153.0 h1:b+X6JUvPkhjv083b+b8IHsv8INNMvvGwANjIGQOfMlM=
186186
github.com/planetscale/planetscale-go v0.153.0/go.mod h1:paQCI5SgquuoewvMQM7R+r1XJO868bdP6/ihGidYRM0=
187+
github.com/planetscale/planetscale-go v0.154.0 h1:bHBiOlGy7Cs7FDFmQgjjJnGUr2xPlqlB3uVPbh/Kl2Q=
188+
github.com/planetscale/planetscale-go v0.154.0/go.mod h1:paQCI5SgquuoewvMQM7R+r1XJO868bdP6/ihGidYRM0=
187189
github.com/planetscale/psdb v0.0.0-20250717190954-65c6661ab6e4 h1:Xv5pj20Rhfty1Tv0OVcidg4ez4PvGrpKvb6rvUwQgDs=
188190
github.com/planetscale/psdb v0.0.0-20250717190954-65c6661ab6e4/go.mod h1:M52h5IWxAcbdQ1hSZrLAGQC4ZXslxEsK/Wh9nu3wdWs=
189191
github.com/planetscale/psdbproxy v0.0.0-20250728082226-3f4ea3a74ec7 h1:aRd6vdE1fyuSI4RVj7oCr8lFmgqXvpnPUmN85VbZCp8=

internal/cmd/branch/vtctld/vdiff.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func VDiffCmd(ch *cmdutil.Helper) *cobra.Command {
1515
Short: "Manage VDiff operations",
1616
}
1717

18+
cmd.AddCommand(VDiffListCmd(ch))
1819
cmd.AddCommand(VDiffCreateCmd(ch))
1920
cmd.AddCommand(VDiffShowCmd(ch))
2021
cmd.AddCommand(VDiffStopCmd(ch))
@@ -24,6 +25,54 @@ func VDiffCmd(ch *cmdutil.Helper) *cobra.Command {
2425
return cmd
2526
}
2627

28+
func VDiffListCmd(ch *cmdutil.Helper) *cobra.Command {
29+
var flags struct {
30+
workflow string
31+
targetKeyspace string
32+
}
33+
34+
cmd := &cobra.Command{
35+
Use: "list <database> <branch>",
36+
Short: "List VDiffs",
37+
Args: cmdutil.RequiredArgs("database", "branch"),
38+
RunE: func(cmd *cobra.Command, args []string) error {
39+
ctx := cmd.Context()
40+
database, branch := args[0], args[1]
41+
42+
client, err := ch.Client()
43+
if err != nil {
44+
return err
45+
}
46+
47+
end := ch.Printer.PrintProgress(
48+
fmt.Sprintf("Fetching VDiffs for workflow %s on %s/%s\u2026",
49+
printer.BoldBlue(flags.workflow), printer.BoldBlue(database), printer.BoldBlue(branch)))
50+
defer end()
51+
52+
data, err := client.VDiff.List(ctx, &ps.VDiffListRequest{
53+
Organization: ch.Config.Organization,
54+
Database: database,
55+
Branch: branch,
56+
Workflow: flags.workflow,
57+
TargetKeyspace: flags.targetKeyspace,
58+
})
59+
if err != nil {
60+
return cmdutil.HandleError(err)
61+
}
62+
63+
end()
64+
return ch.Printer.PrettyPrintJSON(data)
65+
},
66+
}
67+
68+
cmd.Flags().StringVar(&flags.workflow, "workflow", "", "Name of the workflow")
69+
cmd.Flags().StringVar(&flags.targetKeyspace, "target-keyspace", "", "Target keyspace")
70+
cmd.MarkFlagRequired("workflow") // nolint:errcheck
71+
cmd.MarkFlagRequired("target-keyspace") // nolint:errcheck
72+
73+
return cmd
74+
}
75+
2776
func VDiffCreateCmd(ch *cmdutil.Helper) *cobra.Command {
2877
var flags struct {
2978
workflow string

internal/cmd/branch/vtctld/vdiff_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,49 @@ func TestVDiffCreate(t *testing.T) {
5858
c.Assert(svc.CreateFnInvoked, qt.IsTrue)
5959
}
6060

61+
func TestVDiffList(t *testing.T) {
62+
c := qt.New(t)
63+
64+
org := "my-org"
65+
db := "my-db"
66+
branch := "my-branch"
67+
68+
svc := &mock.VDiffService{
69+
ListFn: func(ctx context.Context, req *ps.VDiffListRequest) (json.RawMessage, error) {
70+
c.Assert(req.Organization, qt.Equals, org)
71+
c.Assert(req.Database, qt.Equals, db)
72+
c.Assert(req.Branch, qt.Equals, branch)
73+
c.Assert(req.Workflow, qt.Equals, "my-workflow")
74+
c.Assert(req.TargetKeyspace, qt.Equals, "target-ks")
75+
return json.RawMessage(`{"vdiffs":[]}`), nil
76+
},
77+
}
78+
79+
var buf bytes.Buffer
80+
format := printer.JSON
81+
p := printer.NewPrinter(&format)
82+
p.SetResourceOutput(&buf)
83+
84+
ch := &cmdutil.Helper{
85+
Printer: p,
86+
Config: &config.Config{Organization: org},
87+
Client: func() (*ps.Client, error) {
88+
return &ps.Client{
89+
VDiff: svc,
90+
}, nil
91+
},
92+
}
93+
94+
cmd := VDiffCmd(ch)
95+
cmd.SetArgs([]string{"list", db, branch,
96+
"--workflow", "my-workflow",
97+
"--target-keyspace", "target-ks",
98+
})
99+
err := cmd.Execute()
100+
c.Assert(err, qt.IsNil)
101+
c.Assert(svc.ListFnInvoked, qt.IsTrue)
102+
}
103+
61104
func TestVDiffShow(t *testing.T) {
62105
c := qt.New(t)
63106

internal/mock/vtctld_vdiff.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ type VDiffService struct {
1111
CreateFn func(context.Context, *ps.VDiffCreateRequest) (json.RawMessage, error)
1212
CreateFnInvoked bool
1313

14+
ListFn func(context.Context, *ps.VDiffListRequest) (json.RawMessage, error)
15+
ListFnInvoked bool
16+
1417
ShowFn func(context.Context, *ps.VDiffShowRequest) (json.RawMessage, error)
1518
ShowFnInvoked bool
1619

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

35+
func (s *VDiffService) List(ctx context.Context, req *ps.VDiffListRequest) (json.RawMessage, error) {
36+
s.ListFnInvoked = true
37+
return s.ListFn(ctx, req)
38+
}
39+
3240
func (s *VDiffService) Show(ctx context.Context, req *ps.VDiffShowRequest) (json.RawMessage, error) {
3341
s.ShowFnInvoked = true
3442
return s.ShowFn(ctx, req)

0 commit comments

Comments
 (0)