Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: CloudDedicated database creation ignores the given name #98

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Bug Fixes

1. [#94](https://github.com/InfluxCommunity/influxdb3-go/pull/94): Resource leak from unclosed `Response`
1. [#98](https://github.com/InfluxCommunity/influxdb3-go/pull/98): Cloud Dedicated database creation ignores the name given by an argument

### CI

Expand Down
11 changes: 7 additions & 4 deletions influxdb3/management_cloud_decicated.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,19 @@ func NewCloudDedicatedClient(client *Client) *CloudDedicatedClient {
return &CloudDedicatedClient{client: client}
}

// CreateDatabase creates a new database
// CreateDatabase creates a new database. If Database.ClusterDatabaseName is
// not provided, it defaults to the database name configured in Client.
func (d *CloudDedicatedClient) CreateDatabase(ctx context.Context, config *CloudDedicatedClientConfig, db *Database) error {
if db == nil {
return errors.New("database must not nil")
}

if d.client.config.Database == "" {
return errors.New("database name must not be empty")
if db.ClusterDatabaseName == "" {
if d.client.config.Database == "" {
return errors.New("database name must not be empty")
}
db.ClusterDatabaseName = d.client.config.Database
Comment on lines +97 to +101
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Describe this behaviour in function documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but before doing it, I'm considering whether this fallback may be unexpected for users. Do you think this behavior should be left with documentation, or should we just drop it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep this fallback and update documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed with eea7b21

}
db.ClusterDatabaseName = d.client.config.Database

if len(db.ClusterDatabasePartitionTemplate) > MaxPartitions {
return fmt.Errorf("partition template should not have more than %d tags or tag buckets", MaxPartitions)
Expand Down
24 changes: 22 additions & 2 deletions influxdb3/management_cloud_dedicated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ func TestDedicatedClientCreateDatabase(t *testing.T) {
wantBody map[string]any
wantErr bool
}{
{
name: "create database with defaults",
db: &Database{
ClusterDatabasePartitionTemplate: []PartitionTemplate{},
},
clientConfig: &ClientConfig{
Host: "",
Token: "my-token",
Organization: "default-organization",
Database: "default-database",
},
wantBody: map[string]any{
"name": "default-database",
"maxTables": float64(500),
"maxColumnsPerTable": float64(250),
"retentionPeriod": float64(0),
"partitionTemplate": []any{},
},
wantErr: false,
},
{
name: "create database with name and defaults",
db: &Database{
Expand All @@ -59,7 +79,7 @@ func TestDedicatedClientCreateDatabase(t *testing.T) {
Database: "default-database",
},
wantBody: map[string]any{
"name": "default-database",
"name": "test-database",
"maxTables": float64(500),
"maxColumnsPerTable": float64(250),
"retentionPeriod": float64(0),
Expand Down Expand Up @@ -95,7 +115,7 @@ func TestDedicatedClientCreateDatabase(t *testing.T) {
Database: "default-database",
},
wantBody: map[string]any{
"name": "default-database",
"name": "test-database",
"maxTables": float64(1000),
"maxColumnsPerTable": float64(500),
"retentionPeriod": float64(1000),
Expand Down