Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: db and replica scaling options #67

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
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