Skip to content

Commit

Permalink
Merge pull request #179 from civo/mysql-manual-backup-restore
Browse files Browse the repository at this point in the history
Update dbaas structs to support mysql backup and restore
  • Loading branch information
vishalanarase committed Jan 31, 2024
2 parents 21e802a + 1e90b92 commit 7a5da2a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
1 change: 1 addition & 0 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type SupportedSoftwareVersion struct {

// RestoreDatabaseRequest is the request body for restoring a database
type RestoreDatabaseRequest struct {
Name string `json:"name"`
Software string `json:"software"`
NetworkID string `json:"network_id"`
Backup string `json:"backup"`
Expand Down
39 changes: 19 additions & 20 deletions database_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,25 @@ import (
"fmt"
)

// Scheduled represents scheduled backups
type Scheduled struct {
Name string `json:"name,omitempty"`
Schedule string `json:"schedule,omitempty"`
Count int32 `json:"count,omitempty"`
Backups []string `json:"backups,omitempty"`
}

// Manual represents manual backups
type Manual struct {
Backup string `json:"backup,omitempty"`
}

// DatabaseBackup represents a backup
type DatabaseBackup struct {
DatabaseName string `json:"database_name"`
DatabaseID string `json:"database_id"`
Software string `json:"software"`
Scheduled *Scheduled `json:"scheduled,omitempty"`
Manual []Manual `json:"manual,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Software string `json:"software,omitempty"`
Status string `json:"status,omitempty"`
Schedule string `json:"schedule,omitempty"`
DatabaseName string `json:"database_name,omitempty"`
DatabaseID string `json:"database_id,omitempty"`
Backup string `json:"backup,omitempty"`
IsScheduled bool `json:"is_scheduled,omitempty"`
}

// PaginatedDatabaseBackup is the structure for list response from DB endpoint
type PaginatedDatabaseBackup struct {
Page int `json:"page"`
PerPage int `json:"per_page"`
Pages int `json:"pages"`
Items []DatabaseBackup `json:"items"`
}

// DatabaseBackupCreateRequest represents a backup create request
Expand All @@ -46,13 +45,13 @@ type DatabaseBackupUpdateRequest struct {
}

// ListDatabaseBackup lists backups for database
func (c *Client) ListDatabaseBackup(did string) (*DatabaseBackup, error) {
func (c *Client) ListDatabaseBackup(did string) (*PaginatedDatabaseBackup, error) {
resp, err := c.SendGetRequest(fmt.Sprintf("/v2/databases/%s/backups", did))
if err != nil {
return nil, decodeError(err)
}

back := &DatabaseBackup{}
back := &PaginatedDatabaseBackup{}
if err := json.NewDecoder(bytes.NewReader(resp)).Decode(&back); err != nil {
return nil, decodeError(err)
}
Expand Down

0 comments on commit 7a5da2a

Please sign in to comment.