Skip to content

Commit

Permalink
feat: db and replica scaling options
Browse files Browse the repository at this point in the history
  • Loading branch information
neurosnap committed Jun 18, 2024
1 parent 5042b55 commit 59c5b30
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 38 deletions.
37 changes: 8 additions & 29 deletions aptible/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ type Database struct {
}

// DBUpdates - struct to define what operations you contain your DB update to. Add values to this struct
// to eventually pass it around for consumption by the go sdk
//
// to eventually pass it around for consumption by the go sdk
type DBUpdates struct {
ContainerSize int64
DiskSize int64
Expand All @@ -44,6 +45,7 @@ type DBCreateAttrs struct {
DiskSize int64
ContainerProfile string
DatabaseImageID int64
Iops int64
}

func (c *Client) CreateDatabase(accountID int64, attrs DBCreateAttrs) (Database, error) {
Expand All @@ -66,9 +68,11 @@ func (c *Client) CreateDatabase(accountID int64, attrs DBCreateAttrs) (Database,
// provisions database
requestType := "provision"
provisionRequest := models.AppRequest24{
Type: &requestType,
ContainerSize: attrs.ContainerSize,
DiskSize: attrs.DiskSize,
Type: &requestType,
ContainerSize: attrs.ContainerSize,
DiskSize: attrs.DiskSize,
InstanceProfile: attrs.ContainerProfile,
ProvisionedIops: attrs.Iops,
}
databaseID := *resp.Payload.ID

Expand All @@ -85,31 +89,6 @@ func (c *Client) CreateDatabase(accountID int64, attrs DBCreateAttrs) (Database,
return Database{}, err
}

// Setting the container profile on provision is not currently supported so
// if a non-default container profile is requested, restart with the desired profile
if attrs.ContainerProfile != "" && attrs.ContainerProfile != "m5" {
requestType := "restart"
request := models.AppRequest24{
Type: &requestType,
InstanceProfile: attrs.ContainerProfile,
}

params := operations.NewPostDatabasesDatabaseIDOperationsParams().WithDatabaseID(databaseID).WithAppRequest(&request)
op, err := c.Client.Operations.PostDatabasesDatabaseIDOperations(params, c.Token)
if err != nil {
return Database{}, err
}
if op.Payload.ID != nil {
operationID := *op.Payload.ID
_, err = c.WaitForOperation(operationID)
if err != nil {
return Database{}, err
}
} else {
return Database{}, fmt.Errorf("restart operation id is a nil pointer")
}
}

// gets database
return c.GetDatabase(databaseID)
}
Expand Down
21 changes: 12 additions & 9 deletions aptible/database_replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
)

type ReplicateAttrs struct {
EnvID int64
DatabaseID int64
ReplicaHandle string
ContainerSize int64
DiskSize int64
EnvID int64
DatabaseID int64
ReplicaHandle string
ContainerSize int64
DiskSize int64
ContainerProfile string
}

type ReplicaIdentifiers struct {
Expand All @@ -24,10 +25,12 @@ func (c *Client) CreateReplica(attrs ReplicateAttrs) (Database, error) {
operationType := "replicate"

req := models.AppRequest24{
Type: &operationType,
Handle: attrs.ReplicaHandle,
ContainerSize: attrs.ContainerSize,
DiskSize: attrs.DiskSize,
Type: &operationType,
Handle: attrs.ReplicaHandle,
ContainerSize: attrs.ContainerSize,
DiskSize: attrs.DiskSize,
InstanceProfile: attrs.ContainerProfile,
ProvisionedIops: attrs.Iops,
}

// replicate operation
Expand Down

0 comments on commit 59c5b30

Please sign in to comment.