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
28 changes: 15 additions & 13 deletions internal/cmd/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,13 @@ func toAdminDetail(admin *ps.NekiAdmin, parameters []*ps.NekiParameter) *adminDe
}

type parameterDisplay struct {
Namespace string `header:"namespace" json:"namespace"`
Name string `header:"name" json:"name"`
Value string `header:"value" json:"value"`
Default string `header:"default" json:"default_value"`
Type string `header:"type" json:"parameter_type"`
Restart bool `header:"restart" json:"restart"`
Namespace string `header:"namespace" json:"namespace"`
Name string `header:"name" json:"name"`
Value string `header:"value" json:"value"`
Default string `header:"default" json:"default_value"`
Type string `header:"type" json:"parameter_type"`
Restart bool `header:"restart" json:"restart"`
RequiresUpdate bool `header:"requires update" json:"requires_update"`

orig *ps.NekiParameter
}
Expand All @@ -116,13 +117,14 @@ func toParameters(parameters []*ps.NekiParameter) []*parameterDisplay {
out := make([]*parameterDisplay, 0, len(parameters))
for _, parameter := range parameters {
out = append(out, &parameterDisplay{
Namespace: parameter.Namespace,
Name: parameter.Name,
Value: formatValue(parameter.Value),
Default: formatValue(parameter.DefaultValue),
Type: parameter.ParameterType,
Restart: parameter.Restart,
orig: parameter,
Namespace: parameter.Namespace,
Name: parameter.Name,
Value: formatValue(parameter.Value),
Default: formatValue(parameter.DefaultValue),
Type: parameter.ParameterType,
Restart: parameter.Restart,
RequiresUpdate: parameter.RequiresUpdate != nil,
Comment thread
ayrton marked this conversation as resolved.
orig: parameter,
})
}
return out
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/admin/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestAdminParametersCmd(t *testing.T) {
c.Assert(out.String(), qt.JSONEquals, []map[string]interface{}{{
"name": "recovery-poll-interval", "display_name": "", "namespace": "admin", "advanced": false,
"category": nil, "description": "", "parameter_type": "", "default_value": nil, "value": "20s",
"required": false, "created_at": "0001-01-01T00:00:00Z", "updated_at": nil, "restart": false, "url": "",
"required": false, "created_at": "0001-01-01T00:00:00Z", "updated_at": nil, "restart": false, "url": "", "requires_update": nil,
}})
}

Expand Down
28 changes: 15 additions & 13 deletions internal/cmd/branch/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ To change parameters, use 'pscale branch resize <database> <branch> --parameters
}

type postgresParameter struct {
Namespace string `header:"namespace" json:"namespace"`
Name string `header:"name" json:"name"`
Value string `header:"value" json:"value"`
Default string `header:"default" json:"default_value"`
Type string `header:"type" json:"parameter_type"`
Restart bool `header:"restart" json:"restart"`
Namespace string `header:"namespace" json:"namespace"`
Name string `header:"name" json:"name"`
Value string `header:"value" json:"value"`
Default string `header:"default" json:"default_value"`
Type string `header:"type" json:"parameter_type"`
Restart bool `header:"restart" json:"restart"`
RequiresUpdate bool `header:"requires update" json:"requires_update"`

orig *ps.PostgresParameter
}
Expand All @@ -119,13 +120,14 @@ func toPostgresParameters(parameters []*ps.PostgresParameter) []*postgresParamet
out := make([]*postgresParameter, 0, len(parameters))
for _, param := range parameters {
out = append(out, &postgresParameter{
Namespace: param.Namespace,
Name: param.Name,
Value: formatParameterValue(param.Value),
Default: formatParameterValue(param.DefaultValue),
Type: param.ParameterType,
Restart: param.Restart,
orig: param,
Namespace: param.Namespace,
Name: param.Name,
Value: formatParameterValue(param.Value),
Default: formatParameterValue(param.DefaultValue),
Type: param.ParameterType,
Restart: param.Restart,
RequiresUpdate: param.RequiresUpdate != nil,
orig: param,
})
}
return out
Expand Down
31 changes: 30 additions & 1 deletion internal/cmd/branch/parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package branch
import (
"bytes"
"context"
"encoding/json"
"strings"
"testing"

qt "github.com/frankban/quicktest"
Expand All @@ -15,6 +17,7 @@ import (

func TestBranch_ParametersCmd(t *testing.T) {
c := qt.New(t)
requiresUpdate := "cluster"

var buf bytes.Buffer
format := printer.JSON
Expand All @@ -34,7 +37,7 @@ func TestBranch_ParametersCmd(t *testing.T) {
c.Assert(req.Internal, qt.IsNil)

return []*ps.PostgresParameter{
{Namespace: "pgconf", Name: "max_connections", Value: "200", DefaultValue: "100", ParameterType: "integer", Restart: true},
{Namespace: "pgconf", Name: "max_connections", Value: "200", DefaultValue: "100", ParameterType: "integer", Restart: true, RequiresUpdate: &requiresUpdate},
{Namespace: "pgbouncer", Name: "default_pool_size", Value: "20", DefaultValue: "20", ParameterType: "integer"},
}, nil
},
Expand All @@ -58,6 +61,11 @@ func TestBranch_ParametersCmd(t *testing.T) {
c.Assert(pgSvc.ListParametersFnInvoked, qt.IsTrue)
c.Assert(buf.String(), qt.Contains, "max_connections")
c.Assert(buf.String(), qt.Contains, "default_pool_size")
var parameters []map[string]interface{}
c.Assert(json.Unmarshal(buf.Bytes(), &parameters), qt.IsNil)
c.Assert(parameters[0]["requires_update"], qt.Equals, "cluster")
c.Assert(parameters[1]["requires_update"], qt.IsNil)
c.Assert(buf.String(), qt.Contains, `"requires_update": null`)
}

func TestBranch_ParametersCmd_ListSubcommand(t *testing.T) {
Expand Down Expand Up @@ -130,3 +138,24 @@ func TestBranch_ParametersCmd_NamespaceFilter(t *testing.T) {
c.Assert(buf.String(), qt.Contains, "default_pool_size")
c.Assert(buf.String(), qt.Not(qt.Contains), "max_connections")
}

func TestBranch_ParametersRequiresUpdateTable(t *testing.T) {
c := qt.New(t)
var parameters []*ps.PostgresParameter
c.Assert(json.Unmarshal([]byte(`[
{"namespace":"pgconf","name":"locked","requires_update":"cluster"},
{"namespace":"pgconf","name":"editable","requires_update":null}
]`), &parameters), qt.IsNil)

var out bytes.Buffer
format := printer.Human
p := printer.NewPrinter(&format)
p.SetResourceOutput(&out)
c.Assert(p.PrintResource(toPostgresParameters(parameters)), qt.IsNil)

lines := strings.Split(strings.TrimSpace(out.String()), "\n")
c.Assert(len(lines), qt.Equals, 4)
c.Assert(lines[0], qt.Contains, "REQUIRES UPDATE")
c.Assert(strings.Fields(lines[2]), qt.DeepEquals, []string{"pgconf", "locked", "No", "Yes"})
c.Assert(strings.Fields(lines[3]), qt.DeepEquals, []string{"pgconf", "editable", "No", "No"})
}
34 changes: 18 additions & 16 deletions internal/cmd/configprofile/config_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ func toProfiles(profiles []*ps.NekiShardConfigurationProfile) []*profileDisplay
}

type parameterDisplay struct {
Namespace string `header:"namespace" json:"namespace"`
Name string `header:"name" json:"name"`
Value string `header:"value" json:"value"`
Default string `header:"default" json:"default_value"`
Type string `header:"type" json:"parameter_type"`
Restart bool `header:"restart" json:"restart"`
Required bool `header:"required" json:"required"`
orig *ps.NekiParameter
Namespace string `header:"namespace" json:"namespace"`
Name string `header:"name" json:"name"`
Value string `header:"value" json:"value"`
Default string `header:"default" json:"default_value"`
Type string `header:"type" json:"parameter_type"`
Restart bool `header:"restart" json:"restart"`
Required bool `header:"required" json:"required"`
RequiresUpdate bool `header:"requires update" json:"requires_update"`
orig *ps.NekiParameter
}

func (p *parameterDisplay) MarshalJSON() ([]byte, error) { return json.Marshal(p.orig) }
Expand All @@ -99,14 +100,15 @@ func toParameters(parameters []*ps.NekiParameter) []*parameterDisplay {
out := make([]*parameterDisplay, 0, len(parameters))
for _, p := range parameters {
out = append(out, &parameterDisplay{
Namespace: p.Namespace,
Name: p.Name,
Value: formatValue(p.Value),
Default: formatValue(p.DefaultValue),
Type: p.ParameterType,
Restart: p.Restart,
Required: p.Required,
orig: p,
Namespace: p.Namespace,
Name: p.Name,
Value: formatValue(p.Value),
Default: formatValue(p.DefaultValue),
Type: p.ParameterType,
Restart: p.Restart,
Required: p.Required,
RequiresUpdate: p.RequiresUpdate != nil,
orig: p,
})
}
return out
Expand Down
29 changes: 27 additions & 2 deletions internal/cmd/configprofile/config_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -309,13 +310,14 @@ func TestConfigProfileDefaultCommands(t *testing.T) {

func TestConfigProfileParametersCmd(t *testing.T) {
c := qt.New(t)
requiresUpdate := "configuration_profile"
var out bytes.Buffer
svc := &mock.NekiShardConfigurationProfilesService{ListParametersFn: func(_ context.Context, req *ps.ListNekiShardConfigurationProfileParametersRequest) ([]*ps.NekiParameter, error) {
c.Assert(req.Extension, qt.IsNotNil)
c.Assert(*req.Extension, qt.IsTrue)
c.Assert(req.Internal, qt.IsNil)
return []*ps.NekiParameter{
{Name: "work_mem", Namespace: "pgconf", Value: "64MB"},
{Name: "work_mem", Namespace: "pgconf", Value: "64MB", RequiresUpdate: &requiresUpdate},
{Name: "default_pool_size", Namespace: "pgbouncer", Value: "20"},
}, nil
}}
Expand All @@ -326,10 +328,33 @@ func TestConfigProfileParametersCmd(t *testing.T) {
c.Assert(out.String(), qt.JSONEquals, []map[string]interface{}{{
"name": "work_mem", "display_name": "", "namespace": "pgconf", "advanced": false,
"category": nil, "description": "", "parameter_type": "", "default_value": nil, "value": "64MB",
"required": false, "created_at": "0001-01-01T00:00:00Z", "updated_at": nil, "restart": false, "url": "",
"required": false, "created_at": "0001-01-01T00:00:00Z", "updated_at": nil, "restart": false, "url": "", "requires_update": "configuration_profile",
}})
}

func TestConfigProfileParametersRequiresUpdateTable(t *testing.T) {
c := qt.New(t)
var parameters []*ps.NekiParameter
c.Assert(json.Unmarshal([]byte(`[
{"namespace":"pgconf","name":"profile_locked","requires_update":"configuration_profile"},
{"namespace":"pgconf","name":"cluster_locked","requires_update":"cluster"},
{"namespace":"pgconf","name":"editable","requires_update":null}
]`), &parameters), qt.IsNil)

var out bytes.Buffer
format := printer.Human
p := printer.NewPrinter(&format)
p.SetResourceOutput(&out)
c.Assert(p.PrintResource(toParameters(parameters)), qt.IsNil)

lines := strings.Split(strings.TrimSpace(out.String()), "\n")
c.Assert(len(lines), qt.Equals, 5)
c.Assert(lines[0], qt.Contains, "REQUIRES UPDATE")
c.Assert(strings.Fields(lines[2]), qt.DeepEquals, []string{"pgconf", "profile_locked", "No", "No", "Yes"})
c.Assert(strings.Fields(lines[3]), qt.DeepEquals, []string{"pgconf", "cluster_locked", "No", "No", "Yes"})
c.Assert(strings.Fields(lines[4]), qt.DeepEquals, []string{"pgconf", "editable", "No", "No", "No"})
}

func TestConfigProfileChangesCancelCmd(t *testing.T) {
c := qt.New(t)
var out bytes.Buffer
Expand Down
28 changes: 15 additions & 13 deletions internal/cmd/sidecar/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,13 @@ func toSidecarDetail(sidecar *ps.NekiSidecar, parameters []*ps.NekiParameter) *s
}

type parameterDisplay struct {
Namespace string `header:"namespace" json:"namespace"`
Name string `header:"name" json:"name"`
Value string `header:"value" json:"value"`
Default string `header:"default" json:"default_value"`
Type string `header:"type" json:"parameter_type"`
Restart bool `header:"restart" json:"restart"`
Namespace string `header:"namespace" json:"namespace"`
Name string `header:"name" json:"name"`
Value string `header:"value" json:"value"`
Default string `header:"default" json:"default_value"`
Type string `header:"type" json:"parameter_type"`
Restart bool `header:"restart" json:"restart"`
RequiresUpdate bool `header:"requires update" json:"requires_update"`

orig *ps.NekiParameter
}
Expand All @@ -105,13 +106,14 @@ func toParameters(parameters []*ps.NekiParameter) []*parameterDisplay {
out := make([]*parameterDisplay, 0, len(parameters))
for _, parameter := range parameters {
out = append(out, &parameterDisplay{
Namespace: parameter.Namespace,
Name: parameter.Name,
Value: formatValue(parameter.Value),
Default: formatValue(parameter.DefaultValue),
Type: parameter.ParameterType,
Restart: parameter.Restart,
orig: parameter,
Namespace: parameter.Namespace,
Name: parameter.Name,
Value: formatValue(parameter.Value),
Default: formatValue(parameter.DefaultValue),
Type: parameter.ParameterType,
Restart: parameter.Restart,
RequiresUpdate: parameter.RequiresUpdate != nil,
orig: parameter,
})
}
return out
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/sidecar/sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func TestSidecarParametersCmd(t *testing.T) {
c.Assert(out.String(), qt.JSONEquals, []map[string]interface{}{{
"name": "default_pool_size", "display_name": "", "namespace": "pgbouncer", "advanced": false,
"category": nil, "description": "", "parameter_type": "", "default_value": nil, "value": "20",
"required": false, "created_at": "0001-01-01T00:00:00Z", "updated_at": nil, "restart": false, "url": "",
"required": false, "created_at": "0001-01-01T00:00:00Z", "updated_at": nil, "restart": false, "url": "", "requires_update": nil,
}})
}

Expand Down
29 changes: 15 additions & 14 deletions internal/planetscale/neki_shard_configuration_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,21 @@ type SetDefaultNekiShardConfigurationProfileRequest struct {
}

type NekiParameter struct {
Type string `json:"type,omitempty"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
Namespace string `json:"namespace"`
Advanced bool `json:"advanced"`
Category *string `json:"category"`
Description string `json:"description"`
ParameterType string `json:"parameter_type"`
DefaultValue interface{} `json:"default_value"`
Value interface{} `json:"value"`
Required bool `json:"required"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
Restart bool `json:"restart"`
Type string `json:"type,omitempty"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
Namespace string `json:"namespace"`
Advanced bool `json:"advanced"`
Category *string `json:"category"`
Description string `json:"description"`
ParameterType string `json:"parameter_type"`
DefaultValue interface{} `json:"default_value"`
Value interface{} `json:"value"`
Required bool `json:"required"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
Restart bool `json:"restart"`
RequiresUpdate *string `json:"requires_update"`
// Min, Max, and Step are numbers for plain numeric parameters but strings
// for byte- and time-typed ones (for example, "128kB" or "10min").
Max any `json:"max,omitempty"`
Expand Down
23 changes: 12 additions & 11 deletions internal/planetscale/postgres_branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,18 @@ type ListPostgresParametersRequest struct {

// PostgresParameter represents a configuration parameter of a Postgres branch.
type PostgresParameter struct {
ID string `json:"id"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
Namespace string `json:"namespace"`
Category string `json:"category"`
Description string `json:"description"`
ParameterType string `json:"parameter_type"`
DefaultValue any `json:"default_value"`
Value any `json:"value"`
Required bool `json:"required"`
Restart bool `json:"restart"`
ID string `json:"id"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
Namespace string `json:"namespace"`
Category string `json:"category"`
Description string `json:"description"`
ParameterType string `json:"parameter_type"`
DefaultValue any `json:"default_value"`
Value any `json:"value"`
Required bool `json:"required"`
Restart bool `json:"restart"`
RequiresUpdate *string `json:"requires_update"`

// Min, Max, and Step are numbers for plain numeric parameters but strings
// for byte- and time-typed ones (e.g. "8kB", "10s").
Expand Down
Loading