Skip to content

Commit b23b343

Browse files
authored
feat(dbaas): add support for nested properties (#280)
1 parent d42fbae commit b23b343

File tree

4 files changed

+54
-11
lines changed

4 files changed

+54
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/)
55

66
## [Unreleased]
77

8+
### Added
9+
- Managed Database sub-properties support. E.g., PostgreSQL property `timescaledb` is of type `object` and has `max_background_workers` sub-property.
10+
811
## [6.10.0]
912

1013
### Added

upcloud/managed_database.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -817,17 +817,20 @@ func (s *ManagedDatabaseServicePlanZones) UnmarshalJSON(b []byte) error {
817817

818818
// ManagedDatabaseServiceProperty contains help for database property usage and validation
819819
type ManagedDatabaseServiceProperty struct {
820-
CreateOnly bool `json:"createOnly,omitempty"`
821-
Default interface{} `json:"default,omitempty"`
822-
Example interface{} `json:"example,omitempty"`
823-
MaxLength int `json:"maxLength,omitempty"`
824-
MinLength int `json:"minLength,omitempty"`
825-
Pattern string `json:"pattern,omitempty"`
826-
Type interface{} `json:"type"`
827-
Title string `json:"title"`
828-
Description string `json:"description,omitempty"`
829-
Enum interface{} `json:"enum,omitempty"`
830-
UserError string `json:"user_error,omitempty"`
820+
CreateOnly bool `json:"createOnly,omitempty"`
821+
Default interface{} `json:"default,omitempty"`
822+
Example interface{} `json:"example,omitempty"`
823+
MaxLength int `json:"maxLength,omitempty"`
824+
Maximum *float64 `json:"maximum,omitempty"`
825+
MinLength int `json:"minLength,omitempty"`
826+
Minimum *float64 `json:"minimum,omitempty"`
827+
Pattern string `json:"pattern,omitempty"`
828+
Type interface{} `json:"type"`
829+
Title string `json:"title"`
830+
Description string `json:"description,omitempty"`
831+
Enum interface{} `json:"enum,omitempty"`
832+
UserError string `json:"user_error,omitempty"`
833+
Properties map[string]ManagedDatabaseServiceProperty `json:"properties,omitempty"`
831834
}
832835

833836
// ManagedDatabaseMetadata contains additional read-only informational data about the managed database

upcloud/managed_database_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,22 @@ func TestManagedDatabaseType_UnmarshalJSON(t *testing.T) {
349349
"title": "Public Access",
350350
"type": "boolean",
351351
"description": "Allow access to the service from the public Internet"
352+
},
353+
"timescaledb": {
354+
"title": "TimescaleDB extension configuration values",
355+
"type": "object",
356+
"properties": {
357+
"max_background_workers": {
358+
"default": 16,
359+
"example": 8,
360+
"title": "timescaledb.max_background_workers",
361+
"type": "integer",
362+
"description": "The number of background workers for timescaledb operations. You should configure this setting to the sum of your number of databases and the total number of concurrent background workers you want running at any given point in time.",
363+
"minimum": 1,
364+
"maximum": 4096
365+
}
366+
},
367+
"description": "System-wide settings for the timescaledb extension"
352368
}
353369
}
354370
}`
@@ -376,6 +392,23 @@ func TestManagedDatabaseType_UnmarshalJSON(t *testing.T) {
376392
Type: "boolean",
377393
Description: "Allow access to the service from the public Internet",
378394
},
395+
// `timescaledb` is a PostgreSQL property (not MySQL), but that shouldn't make difference from marshaling point-of-view.
396+
"timescaledb": {
397+
Title: "TimescaleDB extension configuration values",
398+
Description: "System-wide settings for the timescaledb extension",
399+
Type: "object",
400+
Properties: map[string]ManagedDatabaseServiceProperty{
401+
"max_background_workers": {
402+
Default: 16.0,
403+
Example: 8.0,
404+
Title: "timescaledb.max_background_workers",
405+
Type: "integer",
406+
Description: "The number of background workers for timescaledb operations. You should configure this setting to the sum of your number of databases and the total number of concurrent background workers you want running at any given point in time.",
407+
Minimum: Float64Ptr(1),
408+
Maximum: Float64Ptr(4096),
409+
},
410+
},
411+
},
379412
},
380413
}
381414

upcloud/utils.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ func BoolPtr(v bool) *bool {
8484
return &v
8585
}
8686

87+
func Float64Ptr(v float64) *float64 {
88+
return &v
89+
}
90+
8791
func IntPtr(v int) *int {
8892
return &v
8993
}

0 commit comments

Comments
 (0)