Skip to content
Closed
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 Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.23.1 as build
FROM golang:1.23.2 as build
WORKDIR /app
COPY . .

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ endif
REPO=planetscale
NAME=pscale
BUILD_PKG=github.com/planetscale/cli/cmd/pscale
GORELEASE_CROSS_VERSION ?= v1.23.1
GORELEASE_CROSS_VERSION ?= v1.23.2
SYFT_VERSION ?= 1.9.0

.PHONY: all
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '2'

services:
app:
image: golang:1.23.1
image: golang:1.23.2
volumes:
- .:/work
working_dir: /work
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.goreleaser
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG GORELEASE_CROSS_VERSION=v1.23.1
ARG GORELEASE_CROSS_VERSION=v1.23.2
FROM ghcr.io/goreleaser/goreleaser-cross:${GORELEASE_CROSS_VERSION}

RUN apt-get update && apt-get install -y openssh-client
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/planetscale/cli

go 1.23.1
go 1.23.2

require (
github.com/99designs/keyring v1.2.2
Expand All @@ -23,7 +23,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
github.com/pkg/errors v0.9.1
github.com/planetscale/planetscale-go v0.108.0
github.com/planetscale/planetscale-go v0.110.0
github.com/planetscale/psdb v0.0.0-20240109164348-6848e728f6e7
github.com/planetscale/psdbproxy v0.0.0-20240927190836-61feaf3c8bdb
github.com/spf13/cobra v1.8.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
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.108.0 h1:KwLhKsntOO2yokjYxfBtUwHN9/n+c6PnYPbsibZ8jmE=
github.com/planetscale/planetscale-go v0.108.0/go.mod h1:2s0/iqbBEBEL5k+3t0+eNztAU3bYxUynLQs4yLrKNDI=
github.com/planetscale/planetscale-go v0.110.0 h1:iaS/4pbP/efBmLtzr+cH8gjhLy1OjAovOgSqL+Gbobk=
github.com/planetscale/planetscale-go v0.110.0/go.mod h1:ldGffCLckkR8fjGDjDFs4WcjlDr8uqg2qRUZhRYBEMI=
github.com/planetscale/psdb v0.0.0-20240109164348-6848e728f6e7 h1:dxdoFKWVDlV1gq8UQC8NWCofLjCEjEHw47gfeojgs28=
github.com/planetscale/psdb v0.0.0-20240109164348-6848e728f6e7/go.mod h1:WZmi4gw3rOK+ryd1inGxgfKwoFV04O7xBCqzWzv0/0U=
github.com/planetscale/psdbproxy v0.0.0-20240927190836-61feaf3c8bdb h1:eJqW2GfcbKOkUCNHBmHOIWrX4sIaYUJ9xljnlNYtVPQ=
Expand Down
40 changes: 35 additions & 5 deletions internal/cmdutil/cmdutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"fmt"
"os"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -166,6 +168,8 @@ func HasHomebrew() bool {
return err == nil
}

var versionRegex = regexp.MustCompile(`Ver ([0-9]+)\.([0-9]+)\.([0-9]+)`)

// MySQLClientPath checks whether the 'mysql' client exists and returns the
// path to the binary. The returned error contains instructions to install the
// client.
Expand All @@ -184,7 +188,11 @@ func MySQLClientPath() (string, error) {
}

oldpath := os.Getenv("PATH")
newpath := homebrewPrefix + "/opt/mysql-client/bin/" + string(os.PathListSeparator) + oldpath
newpath := homebrewPrefix + "/opt/mysql-client@8.4/bin/" +
homebrewPrefix + "/opt/mysql@8.4/bin/" +
homebrewPrefix + "/opt/mysql-client/bin/" +
homebrewPrefix + "/opt/mysql/bin/" +
string(os.PathListSeparator) + oldpath
defer func() {
if err := os.Setenv("PATH", oldpath); err != nil {
fmt.Println("failed to restore PATH", err)
Expand All @@ -196,17 +204,39 @@ func MySQLClientPath() (string, error) {
}

path, err := exec.LookPath("mysql")
if err == nil {
return path, nil
if err != nil {
return installInstructions("couldn't find the 'mysql' command-line tool required to run this command.")
}

cmd := exec.Command("mysql", "--version")
out, err := cmd.Output()
if err != nil {
return "", fmt.Errorf("failed to run 'mysql --version': %w", err)
}

v := versionRegex.FindStringSubmatch(string(out))
if len(v) != 4 {
return "", fmt.Errorf("could not parse server version from: %s", string(out))
}
major, err := strconv.Atoi(v[1])
if err != nil {
return "", fmt.Errorf("could not parse server version from: %s", string(out))
}

if major > 8 {
return installInstructions(fmt.Sprintf("unsupported mysql version: %s. Please install MySQL 8.x.", string(out)))
}

return path, nil
}

msg := "couldn't find the 'mysql' command-line tool required to run this command."
func installInstructions(msg string) (string, error) {
installURL := "https://planetscale.com/docs/reference/planetscale-environment-setup"

switch runtime.GOOS {
case "darwin":
if HasHomebrew() {
return "", fmt.Errorf("%s\nTo install, run: brew install mysql-client", msg)
return "", fmt.Errorf("%s\nTo install, run: brew install mysql-client@8.4", msg)
}

installURL = "https://planetscale.com/docs/reference/planetscale-environment-setup#macos-instructions"
Expand Down
24 changes: 24 additions & 0 deletions internal/mock/keyspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ type BranchKeyspacesService struct {

CreateFn func(context.Context, *ps.CreateBranchKeyspaceRequest) (*ps.Keyspace, error)
CreateFnInvoked bool

ResizeFn func(context.Context, *ps.ResizeKeyspaceRequest) (*ps.KeyspaceResizeRequest, error)
ResizeInvoked bool

CancelResizeFn func(context.Context, *ps.CancelKeyspaceResizeRequest) error
CancelResizeInvoked bool

ResizeStatusFn func(context.Context, *ps.KeyspaceResizeStatusRequest) (*ps.KeyspaceResizeRequest, error)
ResizeStatusInvoked bool
}

func (s *BranchKeyspacesService) List(ctx context.Context, req *ps.ListBranchKeyspacesRequest) ([]*ps.Keyspace, error) {
Expand Down Expand Up @@ -48,3 +57,18 @@ func (s *BranchKeyspacesService) Create(ctx context.Context, req *ps.CreateBranc
s.CreateFnInvoked = true
return s.CreateFn(ctx, req)
}

func (s *BranchKeyspacesService) Resize(ctx context.Context, req *ps.ResizeKeyspaceRequest) (*ps.KeyspaceResizeRequest, error) {
s.ResizeInvoked = true
return s.ResizeFn(ctx, req)
}

func (s *BranchKeyspacesService) CancelResize(ctx context.Context, req *ps.CancelKeyspaceResizeRequest) error {
s.CancelResizeInvoked = true
return s.CancelResizeFn(ctx, req)
}

func (s *BranchKeyspacesService) ResizeStatus(ctx context.Context, req *ps.KeyspaceResizeStatusRequest) (*ps.KeyspaceResizeRequest, error) {
s.ResizeStatusInvoked = true
return s.ResizeStatusFn(ctx, req)
}