Skip to content

Commit

Permalink
Remove all keyspace and VSchema-level methods from branches service (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
iheanyi authored Oct 14, 2024
1 parent 6b51d53 commit 429534f
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 169 deletions.
82 changes: 0 additions & 82 deletions planetscale/branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,6 @@ type BranchSchemaRequest struct {
Keyspace string `json:"-"`
}

// BranchVSchemaRequest encapsulates a request for getting a branch's VSchema.
type BranchVSchemaRequest struct {
Organization string `json:"-"`
Database string `json:"-"`
Branch string `json:"-"`
Keyspace string `json:"-"`
}

type UpdateBranchVschemaRequest struct {
Organization string `json:"-"`
Database string `json:"-"`
Branch string `json:"-"`
Keyspace string `json:"keyspace"`
VSchema string `json:"vschema"`
}

type BranchRoutingRulesRequest struct {
Organization string `json:"-"`
Database string `json:"-"`
Expand All @@ -114,12 +98,6 @@ type UpdateBranchRoutingRulesRequest struct {
RoutingRules string `json:"routing_rules"`
}

type BranchKeyspacesRequest struct {
Organization string `json:"-"`
Database string `json:"-"`
Branch string `json:"-"`
}

// RefreshSchemaRequest reflects the request needed to refresh a schema
// snapshot on a database branch.
type RefreshSchemaRequest struct {
Expand Down Expand Up @@ -191,11 +169,8 @@ type DatabaseBranchesService interface {
Delete(context.Context, *DeleteDatabaseBranchRequest) error
Diff(context.Context, *DiffBranchRequest) ([]*Diff, error)
Schema(context.Context, *BranchSchemaRequest) ([]*Diff, error)
VSchema(context.Context, *BranchVSchemaRequest) (*VSchema, error)
UpdateVSchema(context.Context, *UpdateBranchVschemaRequest) (*VSchema, error)
RoutingRules(context.Context, *BranchRoutingRulesRequest) (*RoutingRules, error)
UpdateRoutingRules(context.Context, *UpdateBranchRoutingRulesRequest) (*RoutingRules, error)
Keyspaces(context.Context, *BranchKeyspacesRequest) ([]*Keyspace, error)
RefreshSchema(context.Context, *RefreshSchemaRequest) error
Demote(context.Context, *DemoteRequest) (*DatabaseBranch, error)
Promote(context.Context, *PromoteRequest) (*DatabaseBranch, error)
Expand Down Expand Up @@ -260,42 +235,6 @@ func (d *databaseBranchesService) Schema(ctx context.Context, schemaReq *BranchS
return schemas.Schemas, nil
}

// VSchema returns the VSchema for a branch keyspace.
// Deprecated: Use the VSchema method within BranchKeyspacesService instead.
func (d *databaseBranchesService) VSchema(ctx context.Context, vSchemaReq *BranchVSchemaRequest) (*VSchema, error) {
path := fmt.Sprintf("%s/keyspaces/%s/vschema", databaseBranchAPIPath(vSchemaReq.Organization, vSchemaReq.Database, vSchemaReq.Branch), vSchemaReq.Keyspace)

req, err := d.client.newRequest(http.MethodGet, path, nil)
if err != nil {
return nil, errors.Wrap(err, "error creating http request")
}

vSchema := &VSchema{}
if err := d.client.do(ctx, req, &vSchema); err != nil {
return nil, err
}

return vSchema, nil
}

// UpdateVSchema updates the VSchema for a branch keyspace.
// Deprecated: Use the UpdateVSchema method within BranchKeyspacesService instead.
func (d *databaseBranchesService) UpdateVSchema(ctx context.Context, updateVSchemaReq *UpdateBranchVschemaRequest) (*VSchema, error) {
path := fmt.Sprintf("%s/keyspaces/%s/vschema", databaseBranchAPIPath(updateVSchemaReq.Organization, updateVSchemaReq.Database, updateVSchemaReq.Branch), updateVSchemaReq.Keyspace)

req, err := d.client.newRequest(http.MethodPatch, path, updateVSchemaReq)
if err != nil {
return nil, errors.Wrap(err, "error creating http request")
}

vSchema := &VSchema{}
if err := d.client.do(ctx, req, &vSchema); err != nil {
return nil, err
}

return vSchema, nil
}

func (d *databaseBranchesService) RoutingRules(ctx context.Context, routingRulesReq *BranchRoutingRulesRequest) (*RoutingRules, error) {
path := fmt.Sprintf("%s/routing-rules", databaseBranchAPIPath(routingRulesReq.Organization, routingRulesReq.Database, routingRulesReq.Branch))

Expand Down Expand Up @@ -328,27 +267,6 @@ func (d *databaseBranchesService) UpdateRoutingRules(ctx context.Context, update
return routingRules, nil
}

// Keyspaces returns the keyspaces for a branch.
// Deprecated: Use the List method within BranchKeyspacesService instead.
func (d *databaseBranchesService) Keyspaces(ctx context.Context, keyspaceReq *BranchKeyspacesRequest) ([]*Keyspace, error) {
path := fmt.Sprintf("%s/keyspaces", databaseBranchAPIPath(keyspaceReq.Organization, keyspaceReq.Database, keyspaceReq.Branch))

req, err := d.client.newRequest(http.MethodGet, path, nil)
if err != nil {
return nil, errors.Wrap(err, "error creating http request")
}

var out struct {
KS []*Keyspace `json:"data"`
}

if err := d.client.do(ctx, req, &out); err != nil {
return nil, err
}

return out.KS, nil
}

// Create creates a new branch for an organization's database.
func (d *databaseBranchesService) Create(ctx context.Context, createReq *CreateDatabaseBranchRequest) (*DatabaseBranch, error) {
path := databaseBranchesAPIPath(createReq.Organization, createReq.Database)
Expand Down
87 changes: 0 additions & 87 deletions planetscale/branches_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,93 +201,6 @@ func TestBranches_Schema(t *testing.T) {
c.Assert(schemas, qt.DeepEquals, want)
}

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

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
out := `{"raw": "{}"}`
_, err := w.Write([]byte(out))
c.Assert(err, qt.IsNil)
}))

client, err := NewClient(WithBaseURL(ts.URL))
c.Assert(err, qt.IsNil)

ctx := context.Background()

vSchema, err := client.DatabaseBranches.VSchema(ctx, &BranchVSchemaRequest{
Organization: "foo",
Database: "bar",
Branch: "baz",
Keyspace: "main",
})

want := `{}`

c.Assert(err, qt.IsNil)
c.Assert(vSchema.Raw, qt.DeepEquals, want)
}

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

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
out := `{"raw": "{}"}`
_, err := w.Write([]byte(out))
c.Assert(err, qt.IsNil)
}))

client, err := NewClient(WithBaseURL(ts.URL))
c.Assert(err, qt.IsNil)

ctx := context.Background()

vSchema, err := client.DatabaseBranches.UpdateVSchema(ctx, &UpdateBranchVschemaRequest{
Organization: "foo",
Database: "bar",
Branch: "baz",
Keyspace: "bar",
VSchema: "{}",
})

want := `{}`

c.Assert(err, qt.IsNil)
c.Assert(vSchema.Raw, qt.DeepEquals, want)
}

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

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
out := `{"type":"list","current_page":1,"next_page":null,"next_page_url":null,"prev_page":null,"prev_page_url":null,"data":[{"id":"thisisanid","type":"Keyspace","name":"planetscale","shards":2,"sharded":true,"created_at":"2022-01-14T15:39:28.394Z","updated_at":"2021-12-20T21:11:07.697Z"}]}`
_, err := w.Write([]byte(out))
c.Assert(err, qt.IsNil)
}))

client, err := NewClient(WithBaseURL(ts.URL))
c.Assert(err, qt.IsNil)

ctx := context.Background()

keyspaces, err := client.DatabaseBranches.Keyspaces(ctx, &BranchKeyspacesRequest{
Organization: "foo",
Database: "bar",
Branch: "baz",
})

wantID := "thisisanid"

c.Assert(err, qt.IsNil)
c.Assert(len(keyspaces), qt.Equals, 1)
c.Assert(keyspaces[0].ID, qt.Equals, wantID)
c.Assert(keyspaces[0].Sharded, qt.Equals, true)
c.Assert(keyspaces[0].Shards, qt.Equals, 2)
}

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

Expand Down

0 comments on commit 429534f

Please sign in to comment.