From 6579bbd5c7c76dea64b08044d5cb508f732cd7b5 Mon Sep 17 00:00:00 2001 From: Toni Kangas Date: Fri, 8 Dec 2023 18:53:31 +0200 Subject: [PATCH] feat(dbaas): add support for nested properties --- CHANGELOG.md | 3 +++ upcloud/managed_database.go | 25 +++++++++++++----------- upcloud/managed_database_test.go | 33 ++++++++++++++++++++++++++++++++ upcloud/utils.go | 4 ++++ 4 files changed, 54 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88e88bb5..73be90cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] +### Added +- Managed Database sub-properties support. E.g., PostgreSQL property `timescaledb` is of type `object` and has `max_background_workers` sub-property. + ## [6.10.0] ### Added diff --git a/upcloud/managed_database.go b/upcloud/managed_database.go index c83dac9f..aed5a98d 100644 --- a/upcloud/managed_database.go +++ b/upcloud/managed_database.go @@ -817,17 +817,20 @@ func (s *ManagedDatabaseServicePlanZones) UnmarshalJSON(b []byte) error { // ManagedDatabaseServiceProperty contains help for database property usage and validation type ManagedDatabaseServiceProperty struct { - CreateOnly bool `json:"createOnly,omitempty"` - Default interface{} `json:"default,omitempty"` - Example interface{} `json:"example,omitempty"` - MaxLength int `json:"maxLength,omitempty"` - MinLength int `json:"minLength,omitempty"` - Pattern string `json:"pattern,omitempty"` - Type interface{} `json:"type"` - Title string `json:"title"` - Description string `json:"description,omitempty"` - Enum interface{} `json:"enum,omitempty"` - UserError string `json:"user_error,omitempty"` + CreateOnly bool `json:"createOnly,omitempty"` + Default interface{} `json:"default,omitempty"` + Example interface{} `json:"example,omitempty"` + MaxLength int `json:"maxLength,omitempty"` + Maximum *float64 `json:"maximum,omitempty"` + MinLength int `json:"minLength,omitempty"` + Minimum *float64 `json:"minimum,omitempty"` + Pattern string `json:"pattern,omitempty"` + Type interface{} `json:"type"` + Title string `json:"title"` + Description string `json:"description,omitempty"` + Enum interface{} `json:"enum,omitempty"` + UserError string `json:"user_error,omitempty"` + Properties map[string]ManagedDatabaseServiceProperty `json:"properties,omitempty"` } // ManagedDatabaseMetadata contains additional read-only informational data about the managed database diff --git a/upcloud/managed_database_test.go b/upcloud/managed_database_test.go index 20a87ab8..29154cc1 100644 --- a/upcloud/managed_database_test.go +++ b/upcloud/managed_database_test.go @@ -349,6 +349,22 @@ func TestManagedDatabaseType_UnmarshalJSON(t *testing.T) { "title": "Public Access", "type": "boolean", "description": "Allow access to the service from the public Internet" + }, + "timescaledb": { + "title": "TimescaleDB extension configuration values", + "type": "object", + "properties": { + "max_background_workers": { + "default": 16, + "example": 8, + "title": "timescaledb.max_background_workers", + "type": "integer", + "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.", + "minimum": 1, + "maximum": 4096 + } + }, + "description": "System-wide settings for the timescaledb extension" } } }` @@ -376,6 +392,23 @@ func TestManagedDatabaseType_UnmarshalJSON(t *testing.T) { Type: "boolean", Description: "Allow access to the service from the public Internet", }, + // `timescaledb` is a PostgreSQL property (not MySQL), but that shouldn't make difference from marshaling point-of-view. + "timescaledb": { + Title: "TimescaleDB extension configuration values", + Description: "System-wide settings for the timescaledb extension", + Type: "object", + Properties: map[string]ManagedDatabaseServiceProperty{ + "max_background_workers": { + Default: 16.0, + Example: 8.0, + Title: "timescaledb.max_background_workers", + Type: "integer", + 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.", + Minimum: Float64Ptr(1), + Maximum: Float64Ptr(4096), + }, + }, + }, }, } diff --git a/upcloud/utils.go b/upcloud/utils.go index 8503c555..9caf504d 100644 --- a/upcloud/utils.go +++ b/upcloud/utils.go @@ -84,6 +84,10 @@ func BoolPtr(v bool) *bool { return &v } +func Float64Ptr(v float64) *float64 { + return &v +} + func IntPtr(v int) *int { return &v }