Skip to content

Commit

Permalink
feat(dbaas): add support for nested properties
Browse files Browse the repository at this point in the history
  • Loading branch information
kangasta committed Dec 8, 2023
1 parent d42fbae commit 6989308
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 14 additions & 11 deletions upcloud/managed_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions upcloud/managed_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}`
Expand Down Expand Up @@ -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: 1,
Maximum: 4096,
},
},
},
},
}

Expand Down

0 comments on commit 6989308

Please sign in to comment.