Skip to content

Commit 9633762

Browse files
Support DBaaS V2.0 (#633)
* Implemented changes for DBaaS v2.0 and added deprecation notices * Added fork field to ManagedDB struct * Addressed PR comments * Addressed more PR comments
1 parent 857b24b commit 9633762

13 files changed

+3799
-52826
lines changed

databases.go

Lines changed: 102 additions & 23 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,45 @@ 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+
Fork *DatabaseFork `json:"fork"`
78+
79+
// Members has dynamic keys so it is a map
80+
Members map[string]DatabaseMemberType `json:"members"`
81+
82+
// Deprecated: ReplicationType is a deprecated property, as it is no longer supported in DBaaS V2.
83+
ReplicationType string `json:"replication_type"`
84+
// Deprecated: SSLConnection is a deprecated property, as it is no longer supported in DBaaS V2.
85+
SSLConnection bool `json:"ssl_connection"`
86+
// Deprecated: Encrypted is a deprecated property, as it is no longer supported in DBaaS V2.
87+
Encrypted bool `json:"encrypted"`
88+
89+
AllowList []string `json:"allow_list"`
90+
InstanceURI string `json:"instance_uri"`
91+
Created *time.Time `json:"-"`
92+
Updated *time.Time `json:"-"`
93+
OldestRestoreTime *time.Time `json:"-"`
7194
}
7295

7396
// DatabaseHost for Primary/Secondary of Database
@@ -85,11 +108,21 @@ type DatabaseEngine struct {
85108

86109
// DatabaseMaintenanceWindow stores information about a MySQL cluster's maintenance window
87110
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"`
111+
DayOfWeek DatabaseDayOfWeek `json:"day_of_week"`
112+
Duration int `json:"duration"`
113+
Frequency DatabaseMaintenanceFrequency `json:"frequency"`
114+
HourOfDay int `json:"hour_of_day"`
115+
116+
Pending []DatabaseMaintenanceWindowPending `json:"pending,omitempty"`
117+
118+
// Deprecated: WeekOfMonth is a deprecated property, as it is no longer supported in DBaaS V2.
119+
WeekOfMonth *int `json:"week_of_month,omitempty"`
120+
}
121+
122+
type DatabaseMaintenanceWindowPending struct {
123+
Deadline *time.Time `json:"-"`
124+
Description string `json:"description"`
125+
PlannedFor *time.Time `json:"-"`
93126
}
94127

95128
// DatabaseType is information about the supported Database Types by Linode Managed Databases
@@ -120,13 +153,20 @@ type ClusterPrice struct {
120153
Monthly float32 `json:"monthly"`
121154
}
122155

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

126165
p := struct {
127166
*Mask
128-
Created *parseabletime.ParseableTime `json:"created"`
129-
Updated *parseabletime.ParseableTime `json:"updated"`
167+
Created *parseabletime.ParseableTime `json:"created"`
168+
Updated *parseabletime.ParseableTime `json:"updated"`
169+
OldestRestoreTime *parseabletime.ParseableTime `json:"oldest_restore_time"`
130170
}{
131171
Mask: (*Mask)(d),
132172
}
@@ -137,6 +177,45 @@ func (d *Database) UnmarshalJSON(b []byte) error {
137177

138178
d.Created = (*time.Time)(p.Created)
139179
d.Updated = (*time.Time)(p.Updated)
180+
d.OldestRestoreTime = (*time.Time)(p.OldestRestoreTime)
181+
return nil
182+
}
183+
184+
func (d *DatabaseFork) UnmarshalJSON(b []byte) error {
185+
type Mask DatabaseFork
186+
187+
p := struct {
188+
*Mask
189+
RestoreTime *parseabletime.ParseableTime `json:"restore_time"`
190+
}{
191+
Mask: (*Mask)(d),
192+
}
193+
194+
if err := json.Unmarshal(b, &p); err != nil {
195+
return err
196+
}
197+
198+
d.RestoreTime = (*time.Time)(p.RestoreTime)
199+
return nil
200+
}
201+
202+
func (d *DatabaseMaintenanceWindowPending) UnmarshalJSON(b []byte) error {
203+
type Mask DatabaseMaintenanceWindowPending
204+
205+
p := struct {
206+
*Mask
207+
Deadline *parseabletime.ParseableTime `json:"deadline"`
208+
PlannedFor *parseabletime.ParseableTime `json:"planned_for"`
209+
}{
210+
Mask: (*Mask)(d),
211+
}
212+
213+
if err := json.Unmarshal(b, &p); err != nil {
214+
return err
215+
}
216+
217+
d.Deadline = (*time.Time)(p.Deadline)
218+
d.PlannedFor = (*time.Time)(p.PlannedFor)
140219
return nil
141220
}
142221

go.work.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7
4545
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
4646
golang.org/x/crypto v0.30.0 h1:RwoQn3GkWiMkzlX562cLB7OxWvjH1L8xutO2WoJcRoY=
4747
golang.org/x/crypto v0.30.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
48+
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
4849
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
4950
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
5051
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=

mysql.go

Lines changed: 65 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, as it is no longer supported in DBaaS V2.
37+
ReplicationType string `json:"replication_type"`
38+
// Deprecated: SSLConnection is a deprecated property, as it is no longer supported in DBaaS V2.
39+
SSLConnection bool `json:"ssl_connection"`
40+
// Deprecated: Encrypted is a deprecated property, as it is no longer supported in DBaaS V2.
41+
Encrypted bool `json:"encrypted"`
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,42 @@ 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, as it is no longer supported in DBaaS V2.
84+
ReplicationType string `json:"replication_type,omitempty"`
85+
// Deprecated: Encrypted is a deprecated property, as it is no longer supported in DBaaS V2.
86+
Encrypted bool `json:"encrypted,omitempty"`
87+
// Deprecated: SSLConnection is a deprecated property, as it is no longer supported in DBaaS V2.
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, as the backup endpoints are no longer supported in DBaaS V2.
105+
// In DBaaS V2, databases can be backed up via database forking.
82106
type MySQLDatabaseBackup struct {
83107
ID int `json:"id"`
84108
Label string `json:"label"`
@@ -87,6 +111,8 @@ type MySQLDatabaseBackup struct {
87111
}
88112

89113
// MySQLBackupCreateOptions are options used for CreateMySQLDatabaseBackup(...)
114+
// Deprecated: MySQLBackupCreateOptions is a deprecated struct, as the backup endpoints are no longer supported in DBaaS V2.
115+
// In DBaaS V2, databases can be backed up via database forking.
90116
type MySQLBackupCreateOptions struct {
91117
Label string `json:"label"`
92118
Target MySQLDatabaseTarget `json:"target"`
@@ -132,6 +158,8 @@ func (c *Client) ListMySQLDatabases(ctx context.Context, opts *ListOptions) ([]M
132158
}
133159

134160
// ListMySQLDatabaseBackups lists all MySQL Database Backups associated with the given MySQL Database
161+
// Deprecated: ListMySQLDatabaseBackups is a deprecated method, as the backup endpoints are no longer supported in DBaaS V2.
162+
// In DBaaS V2, databases can be backed up via database forking.
135163
func (c *Client) ListMySQLDatabaseBackups(ctx context.Context, databaseID int, opts *ListOptions) ([]MySQLDatabaseBackup, error) {
136164
response, err := getPaginatedResults[MySQLDatabaseBackup](ctx, c, formatAPIPath("databases/mysql/instances/%d/backups", databaseID), opts)
137165
if err != nil {
@@ -211,6 +239,8 @@ func (c *Client) ResetMySQLDatabaseCredentials(ctx context.Context, databaseID i
211239
}
212240

213241
// GetMySQLDatabaseBackup returns a specific MySQL Database Backup with the given ids
242+
// Deprecated: GetMySQLDatabaseBackup is a deprecated method, as the backup endpoints are no longer supported in DBaaS V2.
243+
// In DBaaS V2, databases can be backed up via database forking.
214244
func (c *Client) GetMySQLDatabaseBackup(ctx context.Context, databaseID int, backupID int) (*MySQLDatabaseBackup, error) {
215245
e := formatAPIPath("databases/mysql/instances/%d/backups/%d", databaseID, backupID)
216246
response, err := doGETRequest[MySQLDatabaseBackup](ctx, c, e)
@@ -222,13 +252,17 @@ func (c *Client) GetMySQLDatabaseBackup(ctx context.Context, databaseID int, bac
222252
}
223253

224254
// RestoreMySQLDatabaseBackup returns the given MySQL Database with the given Backup
255+
// Deprecated: RestoreMySQLDatabaseBackup is a deprecated method, as the backup endpoints are no longer supported in DBaaS V2.
256+
// In DBaaS V2, databases can be backed up via database forking.
225257
func (c *Client) RestoreMySQLDatabaseBackup(ctx context.Context, databaseID int, backupID int) error {
226258
e := formatAPIPath("databases/mysql/instances/%d/backups/%d/restore", databaseID, backupID)
227259
_, err := doPOSTRequest[MySQLDatabaseBackup, any](ctx, c, e)
228260
return err
229261
}
230262

231263
// CreateMySQLDatabaseBackup creates a snapshot for the given MySQL database
264+
// Deprecated: CreateMySQLDatabaseBackup is a deprecated method, as the backup endpoints are no longer supported in DBaaS V2.
265+
// In DBaaS V2, databases can be backed up via database forking.
232266
func (c *Client) CreateMySQLDatabaseBackup(ctx context.Context, databaseID int, opts MySQLBackupCreateOptions) error {
233267
e := formatAPIPath("databases/mysql/instances/%d/backups", databaseID)
234268
_, err := doPOSTRequest[MySQLDatabaseBackup](ctx, c, e, opts)

0 commit comments

Comments
 (0)