Skip to content

Commit e94d2a4

Browse files
Implemented changes for DBaaS v2.0 and added deprecation notices
1 parent b6c358f commit e94d2a4

File tree

12 files changed

+3778
-52824
lines changed

12 files changed

+3778
-52824
lines changed

databases.go

Lines changed: 96 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ type (
1313
DatabaseDayOfWeek int
1414
DatabaseMaintenanceFrequency string
1515
DatabaseStatus string
16+
DatabasePlatform string
17+
DatabaseMemberType string
1618
)
1719

1820
const (
@@ -50,24 +52,43 @@ const (
5052
DatabaseStatusBackingUp DatabaseStatus = "backing_up"
5153
)
5254

55+
const (
56+
DatabasePlatformRDBMSLegacy DatabasePlatform = "rdbms-legacy"
57+
DatabasePlatformRDBMSDefault DatabasePlatform = "rdbms-default"
58+
)
59+
60+
const (
61+
DatabaseMemberTypePrimary DatabaseMemberType = "primary"
62+
DatabaseMemberTypeFailover DatabaseMemberType = "failover"
63+
)
64+
5365
// A Database is a instance of Linode Managed Databases
5466
type Database struct {
55-
ID int `json:"id"`
56-
Status DatabaseStatus `json:"status"`
57-
Label string `json:"label"`
58-
Hosts DatabaseHost `json:"hosts"`
59-
Region string `json:"region"`
60-
Type string `json:"type"`
61-
Engine string `json:"engine"`
62-
Version string `json:"version"`
63-
ClusterSize int `json:"cluster_size"`
64-
ReplicationType string `json:"replication_type"`
65-
SSLConnection bool `json:"ssl_connection"`
66-
Encrypted bool `json:"encrypted"`
67-
AllowList []string `json:"allow_list"`
68-
InstanceURI string `json:"instance_uri"`
69-
Created *time.Time `json:"-"`
70-
Updated *time.Time `json:"-"`
67+
ID int `json:"id"`
68+
Status DatabaseStatus `json:"status"`
69+
Label string `json:"label"`
70+
Hosts DatabaseHost `json:"hosts"`
71+
Region string `json:"region"`
72+
Type string `json:"type"`
73+
Engine string `json:"engine"`
74+
Version string `json:"version"`
75+
ClusterSize int `json:"cluster_size"`
76+
Platform DatabasePlatform `json:"platform"`
77+
78+
// Members has dynamic keys so it is a map
79+
Members map[string]DatabaseMemberType `json:"members"`
80+
81+
// Deprecated: ReplicationType is a deprecated property.
82+
ReplicationType string `json:"replication_type,omitempty"`
83+
// Deprecated: SSLConnection is a deprecated property.
84+
SSLConnection bool `json:"ssl_connection,omitempty"`
85+
// Deprecated: Encrypted is a deprecated property.
86+
Encrypted bool `json:"encrypted,omitempty"`
87+
88+
AllowList []string `json:"allow_list"`
89+
InstanceURI string `json:"instance_uri"`
90+
Created *time.Time `json:"-"`
91+
Updated *time.Time `json:"-"`
7192
}
7293

7394
// DatabaseHost for Primary/Secondary of Database
@@ -85,11 +106,21 @@ type DatabaseEngine struct {
85106

86107
// DatabaseMaintenanceWindow stores information about a MySQL cluster's maintenance window
87108
type DatabaseMaintenanceWindow struct {
88-
DayOfWeek DatabaseDayOfWeek `json:"day_of_week"`
89-
Duration int `json:"duration"`
90-
Frequency DatabaseMaintenanceFrequency `json:"frequency"`
91-
HourOfDay int `json:"hour_of_day"`
92-
WeekOfMonth *int `json:"week_of_month"`
109+
DayOfWeek DatabaseDayOfWeek `json:"day_of_week"`
110+
Duration int `json:"duration"`
111+
Frequency DatabaseMaintenanceFrequency `json:"frequency"`
112+
HourOfDay int `json:"hour_of_day"`
113+
114+
Pending []DatabaseMaintenanceWindowPending `json:"pending,omitempty"`
115+
116+
// Deprecated: WeekOfMonth is a deprecated property.
117+
WeekOfMonth *int `json:"week_of_month,omitempty"` // This field doesn't exist in v2
118+
}
119+
120+
type DatabaseMaintenanceWindowPending struct {
121+
Deadline *time.Time `json:"-"`
122+
Description string `json:"description"`
123+
PlannedFor *time.Time `json:"-"`
93124
}
94125

95126
// DatabaseType is information about the supported Database Types by Linode Managed Databases
@@ -120,6 +151,12 @@ type ClusterPrice struct {
120151
Monthly float32 `json:"monthly"`
121152
}
122153

154+
// DatabaseFork describes the source and restore time for the fork for forked DBs
155+
type DatabaseFork struct {
156+
Source int `json:"source"`
157+
RestoreTime *time.Time `json:"-,omitempty"`
158+
}
159+
123160
func (d *Database) UnmarshalJSON(b []byte) error {
124161
type Mask Database
125162

@@ -140,6 +177,44 @@ func (d *Database) UnmarshalJSON(b []byte) error {
140177
return nil
141178
}
142179

180+
func (d *DatabaseFork) UnmarshalJSON(b []byte) error {
181+
type Mask DatabaseFork
182+
183+
p := struct {
184+
*Mask
185+
RestoreTime *parseabletime.ParseableTime `json:"restore_time"`
186+
}{
187+
Mask: (*Mask)(d),
188+
}
189+
190+
if err := json.Unmarshal(b, &p); err != nil {
191+
return err
192+
}
193+
194+
d.RestoreTime = (*time.Time)(p.RestoreTime)
195+
return nil
196+
}
197+
198+
func (d *DatabaseMaintenanceWindowPending) UnmarshalJSON(b []byte) error {
199+
type Mask DatabaseMaintenanceWindowPending
200+
201+
p := struct {
202+
*Mask
203+
Deadline *parseabletime.ParseableTime `json:"deadline"`
204+
PlannedFor *parseabletime.ParseableTime `json:"planned_for"`
205+
}{
206+
Mask: (*Mask)(d),
207+
}
208+
209+
if err := json.Unmarshal(b, &p); err != nil {
210+
return err
211+
}
212+
213+
d.Deadline = (*time.Time)(p.Deadline)
214+
d.PlannedFor = (*time.Time)(p.PlannedFor)
215+
return nil
216+
}
217+
143218
// ListDatabases lists all Database instances in Linode Managed Databases for the account
144219
func (c *Client) ListDatabases(ctx context.Context, opts *ListOptions) ([]Database, error) {
145220
response, err := getPaginatedResults[Database](ctx, c, "databases/instances", opts)

mysql.go

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,44 @@ const (
1919

2020
// A MySQLDatabase is an instance of Linode MySQL Managed Databases
2121
type MySQLDatabase struct {
22-
ID int `json:"id"`
23-
Status DatabaseStatus `json:"status"`
24-
Label string `json:"label"`
25-
Hosts DatabaseHost `json:"hosts"`
26-
Region string `json:"region"`
27-
Type string `json:"type"`
28-
Engine string `json:"engine"`
29-
Version string `json:"version"`
30-
ClusterSize int `json:"cluster_size"`
31-
ReplicationType string `json:"replication_type"`
32-
SSLConnection bool `json:"ssl_connection"`
33-
Encrypted bool `json:"encrypted"`
34-
AllowList []string `json:"allow_list"`
35-
InstanceURI string `json:"instance_uri"`
36-
Created *time.Time `json:"-"`
37-
Updated *time.Time `json:"-"`
38-
Updates DatabaseMaintenanceWindow `json:"updates"`
22+
ID int `json:"id"`
23+
Status DatabaseStatus `json:"status"`
24+
Label string `json:"label"`
25+
Hosts DatabaseHost `json:"hosts"`
26+
Region string `json:"region"`
27+
Type string `json:"type"`
28+
Engine string `json:"engine"`
29+
Version string `json:"version"`
30+
ClusterSize int `json:"cluster_size"`
31+
Platform DatabasePlatform `json:"platform"`
32+
33+
// Members has dynamic keys so it is a map
34+
Members map[string]DatabaseMemberType `json:"members"`
35+
36+
// Deprecated: ReplicationType is a deprecated property.
37+
ReplicationType string `json:"replication_type,omitempty"`
38+
// Deprecated: SSLConnection is a deprecated property.
39+
SSLConnection bool `json:"ssl_connection,omitempty"`
40+
// Deprecated: Encrypted is a deprecated property.
41+
Encrypted bool `json:"encrypted,omitempty"`
42+
43+
AllowList []string `json:"allow_list"`
44+
InstanceURI string `json:"instance_uri"`
45+
Created *time.Time `json:"-"`
46+
Updated *time.Time `json:"-"`
47+
Updates DatabaseMaintenanceWindow `json:"updates"`
48+
Fork *DatabaseFork `json:"fork"`
49+
OldestRestoreTime *time.Time `json:"-"`
3950
}
4051

4152
func (d *MySQLDatabase) UnmarshalJSON(b []byte) error {
4253
type Mask MySQLDatabase
4354

4455
p := struct {
4556
*Mask
46-
Created *parseabletime.ParseableTime `json:"created"`
47-
Updated *parseabletime.ParseableTime `json:"updated"`
57+
Created *parseabletime.ParseableTime `json:"created"`
58+
Updated *parseabletime.ParseableTime `json:"updated"`
59+
OldestRestoreTime *parseabletime.ParseableTime `json:"oldest_restore_time"`
4860
}{
4961
Mask: (*Mask)(d),
5062
}
@@ -55,30 +67,41 @@ func (d *MySQLDatabase) UnmarshalJSON(b []byte) error {
5567

5668
d.Created = (*time.Time)(p.Created)
5769
d.Updated = (*time.Time)(p.Updated)
70+
d.OldestRestoreTime = (*time.Time)(p.OldestRestoreTime)
5871
return nil
5972
}
6073

6174
// MySQLCreateOptions fields are used when creating a new MySQL Database
6275
type MySQLCreateOptions struct {
63-
Label string `json:"label"`
64-
Region string `json:"region"`
65-
Type string `json:"type"`
66-
Engine string `json:"engine"`
67-
AllowList []string `json:"allow_list,omitempty"`
68-
ReplicationType string `json:"replication_type,omitempty"`
69-
ClusterSize int `json:"cluster_size,omitempty"`
70-
Encrypted bool `json:"encrypted,omitempty"`
71-
SSLConnection bool `json:"ssl_connection,omitempty"`
76+
Label string `json:"label"`
77+
Region string `json:"region"`
78+
Type string `json:"type"`
79+
Engine string `json:"engine"`
80+
AllowList []string `json:"allow_list,omitempty"`
81+
ClusterSize int `json:"cluster_size,omitempty"`
82+
83+
// Deprecated: ReplicationType is a deprecated property.
84+
ReplicationType string `json:"replication_type,omitempty"`
85+
// Deprecated: Encrypted is a deprecated property.
86+
Encrypted bool `json:"encrypted,omitempty"`
87+
// Deprecated: SSLConnection is a deprecated property.
88+
SSLConnection bool `json:"ssl_connection,omitempty"`
89+
90+
Fork *DatabaseFork `json:"fork,omitempty"`
7291
}
7392

7493
// MySQLUpdateOptions fields are used when altering the existing MySQL Database
7594
type MySQLUpdateOptions struct {
76-
Label string `json:"label,omitempty"`
77-
AllowList *[]string `json:"allow_list,omitempty"`
78-
Updates *DatabaseMaintenanceWindow `json:"updates,omitempty"`
95+
Label string `json:"label,omitempty"`
96+
AllowList *[]string `json:"allow_list,omitempty"`
97+
Updates *DatabaseMaintenanceWindow `json:"updates,omitempty"`
98+
Type string `json:"type,omitempty"`
99+
ClusterSize int `json:"cluster_size,omitempty"`
100+
Version string `json:"version,omitempty"`
79101
}
80102

81103
// MySQLDatabaseBackup is information for interacting with a backup for the existing MySQL Database
104+
// Deprecated: MySQLDatabaseBackup is a deprecated struct.
82105
type MySQLDatabaseBackup struct {
83106
ID int `json:"id"`
84107
Label string `json:"label"`
@@ -87,6 +110,7 @@ type MySQLDatabaseBackup struct {
87110
}
88111

89112
// MySQLBackupCreateOptions are options used for CreateMySQLDatabaseBackup(...)
113+
// Deprecated: MySQLBackupCreateOptions is a deprecated struct.
90114
type MySQLBackupCreateOptions struct {
91115
Label string `json:"label"`
92116
Target MySQLDatabaseTarget `json:"target"`
@@ -132,6 +156,7 @@ func (c *Client) ListMySQLDatabases(ctx context.Context, opts *ListOptions) ([]M
132156
}
133157

134158
// ListMySQLDatabaseBackups lists all MySQL Database Backups associated with the given MySQL Database
159+
// Deprecated: ListMySQLDatabaseBackups is a deprecated method.
135160
func (c *Client) ListMySQLDatabaseBackups(ctx context.Context, databaseID int, opts *ListOptions) ([]MySQLDatabaseBackup, error) {
136161
response, err := getPaginatedResults[MySQLDatabaseBackup](ctx, c, formatAPIPath("databases/mysql/instances/%d/backups", databaseID), opts)
137162
if err != nil {
@@ -211,6 +236,7 @@ func (c *Client) ResetMySQLDatabaseCredentials(ctx context.Context, databaseID i
211236
}
212237

213238
// GetMySQLDatabaseBackup returns a specific MySQL Database Backup with the given ids
239+
// Deprecated: GetMySQLDatabaseBackup is a deprecated method.
214240
func (c *Client) GetMySQLDatabaseBackup(ctx context.Context, databaseID int, backupID int) (*MySQLDatabaseBackup, error) {
215241
e := formatAPIPath("databases/mysql/instances/%d/backups/%d", databaseID, backupID)
216242
response, err := doGETRequest[MySQLDatabaseBackup](ctx, c, e)
@@ -222,13 +248,15 @@ func (c *Client) GetMySQLDatabaseBackup(ctx context.Context, databaseID int, bac
222248
}
223249

224250
// RestoreMySQLDatabaseBackup returns the given MySQL Database with the given Backup
251+
// Deprecated: RestoreMySQLDatabaseBackup is a deprecated method.
225252
func (c *Client) RestoreMySQLDatabaseBackup(ctx context.Context, databaseID int, backupID int) error {
226253
e := formatAPIPath("databases/mysql/instances/%d/backups/%d/restore", databaseID, backupID)
227254
_, err := doPOSTRequest[MySQLDatabaseBackup, any](ctx, c, e)
228255
return err
229256
}
230257

231258
// CreateMySQLDatabaseBackup creates a snapshot for the given MySQL database
259+
// Deprecated: CreateMySQLDatabaseBackup is a deprecated method.
232260
func (c *Client) CreateMySQLDatabaseBackup(ctx context.Context, databaseID int, opts MySQLBackupCreateOptions) error {
233261
e := formatAPIPath("databases/mysql/instances/%d/backups", databaseID)
234262
_, err := doPOSTRequest[MySQLDatabaseBackup](ctx, c, e, opts)

0 commit comments

Comments
 (0)