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
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ require (
github.com/benbjohnson/clock v1.3.5
github.com/briandowns/spinner v1.23.2
github.com/charmbracelet/huh v0.8.0
github.com/dustin/go-humanize v1.0.1
github.com/fatih/color v1.18.0
github.com/frankban/quicktest v1.14.6
github.com/go-sql-driver/mysql v1.9.3
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1
github.com/google/go-cmp v0.7.0
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/go-version v1.8.0
github.com/kataras/tablewriter v0.0.0-20180708051242-e063d29b7c23
github.com/lensesio/tableprinter v0.0.0-20201125135848-89e81fc956e7
github.com/lib/pq v1.11.2
github.com/mark3labs/mcp-go v0.44.0
Expand All @@ -25,7 +27,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.148.0
github.com/planetscale/planetscale-go v0.151.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 Expand Up @@ -68,7 +70,6 @@ require (
github.com/clipperhouse/uax29/v2 v2.3.0 // indirect
github.com/danieljoos/wincred v1.2.3 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dvsekhvalnov/jose2go v1.8.0 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
Expand All @@ -79,7 +80,6 @@ require (
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/jsonschema v0.13.0 // indirect
github.com/kataras/tablewriter v0.0.0-20180708051242-e063d29b7c23 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.18.2 // indirect
github.com/klauspost/connect-compress/v2 v2.1.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjL
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/planetscale/noglog v0.2.1-0.20210421230640-bea75fcd2e8e h1:MZ8D+Z3m2vvqGZLvoQfpaGg/j1fNDr4j03s3PRz4rVY=
github.com/planetscale/noglog v0.2.1-0.20210421230640-bea75fcd2e8e/go.mod h1:hwAsSPQdvPa3WcfKfzTXxtEq/HlqwLjQasfO6QbGo4Q=
github.com/planetscale/planetscale-go v0.148.0 h1:9tMRq4btsuOe5s/QCx6DNKDwKnGVEZYu++RX0rOaC6g=
github.com/planetscale/planetscale-go v0.148.0/go.mod h1:PheYDHAwF14wfCBak1M0J64AdPW8NUeyvgPgWqe7zpI=
github.com/planetscale/planetscale-go v0.151.0 h1:Vx1khlA76AnioSZzoY6gbJvXfMOKVWjjf4980bYgAA8=
github.com/planetscale/planetscale-go v0.151.0/go.mod h1:mnADwPuBOmZaRCBbCzQna8N69vhlpEDCWGMF501qnEA=
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
2 changes: 2 additions & 0 deletions internal/cmd/branch/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"time"

"github.com/planetscale/cli/internal/cmd/branch/vtctld"
"github.com/planetscale/cli/internal/cmdutil"
ps "github.com/planetscale/planetscale-go/planetscale"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -34,6 +35,7 @@ func BranchCmd(ch *cmdutil.Helper) *cobra.Command {
cmd.AddCommand(RoutingRulesCmd(ch))
cmd.AddCommand(SafeMigrationsCmd(ch))
cmd.AddCommand(LintCmd(ch))
cmd.AddCommand(vtctld.VtctldCmd(ch))

return cmd
}
Expand Down
53 changes: 53 additions & 0 deletions internal/cmd/branch/vtctld/keyspaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package vtctld

import (
"fmt"

"github.com/planetscale/cli/internal/cmdutil"
"github.com/planetscale/cli/internal/printer"
ps "github.com/planetscale/planetscale-go/planetscale"
"github.com/spf13/cobra"
)

func ListKeyspacesCmd(ch *cmdutil.Helper) *cobra.Command {
var flags struct {
name string
}

cmd := &cobra.Command{
Use: "list-keyspaces <database> <branch>",
Short: "List vtctld keyspaces for a branch",
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 keyspaces for %s/%s\u2026",
printer.BoldBlue(database), printer.BoldBlue(branch)))
defer end()

data, err := client.Vtctld.ListKeyspaces(ctx, &ps.VtctldListKeyspacesRequest{
Organization: ch.Config.Organization,
Database: database,
Branch: branch,
Name: flags.name,
})
if err != nil {
return cmdutil.HandleError(err)
}

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

cmd.Flags().StringVar(&flags.name, "name", "", "Filter by keyspace name")

return cmd
}
54 changes: 54 additions & 0 deletions internal/cmd/branch/vtctld/keyspaces_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package vtctld

import (
"bytes"
"context"
"encoding/json"
"testing"

qt "github.com/frankban/quicktest"

"github.com/planetscale/cli/internal/cmdutil"
"github.com/planetscale/cli/internal/config"
"github.com/planetscale/cli/internal/mock"
"github.com/planetscale/cli/internal/printer"
ps "github.com/planetscale/planetscale-go/planetscale"
)

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

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

svc := &mock.VtctldService{
ListKeyspacesFn: func(ctx context.Context, req *ps.VtctldListKeyspacesRequest) (json.RawMessage, error) {
c.Assert(req.Organization, qt.Equals, org)
c.Assert(req.Database, qt.Equals, db)
c.Assert(req.Branch, qt.Equals, branch)
return json.RawMessage(`{"keyspaces":[]}`), 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{
Vtctld: svc,
}, nil
},
}

cmd := ListKeyspacesCmd(ch)
cmd.SetArgs([]string{db, branch})
err := cmd.Execute()
c.Assert(err, qt.IsNil)
c.Assert(svc.ListKeyspacesFnInvoked, qt.IsTrue)
}
55 changes: 55 additions & 0 deletions internal/cmd/branch/vtctld/start_workflow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package vtctld

import (
"fmt"

"github.com/planetscale/cli/internal/cmdutil"
"github.com/planetscale/cli/internal/printer"
ps "github.com/planetscale/planetscale-go/planetscale"
"github.com/spf13/cobra"
)

func StartWorkflowCmd(ch *cmdutil.Helper) *cobra.Command {
var flags struct {
keyspace string
}

cmd := &cobra.Command{
Use: "start-workflow <database> <branch> <workflow>",
Short: "Start a workflow on a branch",
Args: cmdutil.RequiredArgs("database", "branch", "workflow"),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
database, branch, workflow := args[0], args[1], args[2]

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

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

data, err := client.Vtctld.StartWorkflow(ctx, &ps.VtctldStartWorkflowRequest{
Organization: ch.Config.Organization,
Database: database,
Branch: branch,
Workflow: workflow,
Keyspace: flags.keyspace,
})
if err != nil {
return cmdutil.HandleError(err)
}

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

cmd.Flags().StringVar(&flags.keyspace, "keyspace", "", "Keyspace the workflow belongs to")
cmd.MarkFlagRequired("keyspace") // nolint:errcheck

return cmd
}
58 changes: 58 additions & 0 deletions internal/cmd/branch/vtctld/start_workflow_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package vtctld

import (
"bytes"
"context"
"encoding/json"
"testing"

qt "github.com/frankban/quicktest"

"github.com/planetscale/cli/internal/cmdutil"
"github.com/planetscale/cli/internal/config"
"github.com/planetscale/cli/internal/mock"
"github.com/planetscale/cli/internal/printer"
ps "github.com/planetscale/planetscale-go/planetscale"
)

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

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

svc := &mock.VtctldService{
StartWorkflowFn: func(ctx context.Context, req *ps.VtctldStartWorkflowRequest) (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.Keyspace, qt.Equals, "my-keyspace")
return json.RawMessage(`{"summary":"started"}`), 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{
Vtctld: svc,
}, nil
},
}

cmd := StartWorkflowCmd(ch)
cmd.SetArgs([]string{db, branch, "my-workflow",
"--keyspace", "my-keyspace",
})
err := cmd.Execute()
c.Assert(err, qt.IsNil)
c.Assert(svc.StartWorkflowFnInvoked, qt.IsTrue)
}
55 changes: 55 additions & 0 deletions internal/cmd/branch/vtctld/stop_workflow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package vtctld

import (
"fmt"

"github.com/planetscale/cli/internal/cmdutil"
"github.com/planetscale/cli/internal/printer"
ps "github.com/planetscale/planetscale-go/planetscale"
"github.com/spf13/cobra"
)

func StopWorkflowCmd(ch *cmdutil.Helper) *cobra.Command {
var flags struct {
keyspace string
}

cmd := &cobra.Command{
Use: "stop-workflow <database> <branch> <workflow>",
Short: "Stop a workflow on a branch",
Args: cmdutil.RequiredArgs("database", "branch", "workflow"),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
database, branch, workflow := args[0], args[1], args[2]

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

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

data, err := client.Vtctld.StopWorkflow(ctx, &ps.VtctldStopWorkflowRequest{
Organization: ch.Config.Organization,
Database: database,
Branch: branch,
Workflow: workflow,
Keyspace: flags.keyspace,
})
if err != nil {
return cmdutil.HandleError(err)
}

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

cmd.Flags().StringVar(&flags.keyspace, "keyspace", "", "Keyspace the workflow belongs to")
cmd.MarkFlagRequired("keyspace") // nolint:errcheck

return cmd
}
Loading