Skip to content

Commit 45f48c9

Browse files
Merge pull request #57 from mculp/main
change from `present?` (Rails) to native Ruby check
2 parents 2365fa3 + 48102ef commit 45f48c9

File tree

4 files changed

+41
-17
lines changed

4 files changed

+41
-17
lines changed

README.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -354,21 +354,14 @@ client.ready?
354354

355355
### Tenants
356356

357-
Any schema can be multi-tenant
357+
Any schema can be multi-tenant by passing in these options for to `schema.create()`.
358358

359359
```ruby
360360
client.schema.create(
361361
# Other keys...
362-
mutli_tenant: true, # passes { enabled: true } to weaviate
363-
)
364-
```
365-
366-
You can also manually specify your multi tenancy configuration with a hash
367-
368-
```ruby
369-
client.schema.create(
370-
# Other keys...
371-
mutli_tenant: { enabled: true, autoTenantCreation: true, autoTenantActivation: true },
362+
multi_tenant: true,
363+
auto_tenant_creation: true,
364+
auto_tenant_activation: true
372365
)
373366
```
374367

lib/weaviate/objects.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def create(
5050
req.body = {}
5151
req.body["class"] = class_name
5252
req.body["properties"] = properties
53-
req.body["tenant"] = tenant unless tenant.blank?
53+
req.body["tenant"] = tenant unless tenant.nil?
5454
req.body["id"] = id unless id.nil?
5555
req.body["vector"] = vector unless vector.nil?
5656
end

lib/weaviate/schema.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ def create(
2626
class_name:,
2727
description: nil,
2828
properties: nil,
29-
multi_tenant: nil,
29+
multi_tenant: false,
30+
auto_tenant_creation: false,
31+
auto_tenant_activation: false,
3032
vector_index_type: nil,
3133
vector_index_config: nil,
3234
vectorizer: nil,
@@ -43,11 +45,15 @@ def create(
4345
req.body["vectorizer"] = vectorizer unless vectorizer.nil?
4446
req.body["moduleConfig"] = module_config unless module_config.nil?
4547
req.body["properties"] = properties unless properties.nil?
46-
if multi_tenant.is_a?(Hash)
47-
req.body["multiTenancyConfig"] = multi_tenant
48-
elsif multi_tenant.present?
49-
req.body["multiTenancyConfig"] = {enabled: true}
48+
49+
if multi_tenant
50+
req.body["multiTenancyConfig"] = {
51+
enabled: multi_tenant,
52+
autoTenantCreation: auto_tenant_creation,
53+
autoTenantActivation: auto_tenant_activation
54+
}
5055
end
56+
5157
req.body["invertedIndexConfig"] = inverted_index_config unless inverted_index_config.nil?
5258
req.body["replicationConfig"] = replication_config unless replication_config.nil?
5359
end

spec/weaviate/schema_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,31 @@
7676
)
7777
expect(response.dig("class")).to eq("Question")
7878
end
79+
80+
context "when auto_tenant_creation passed" do
81+
before do
82+
@captured_request = nil
83+
allow_any_instance_of(Faraday::Connection).to receive(:post) do |_, path, &block|
84+
expect(path).to eq("schema")
85+
req = OpenStruct.new(body: {})
86+
block.call(req)
87+
@captured_request = req
88+
response
89+
end
90+
end
91+
92+
it "sets up multiTenancyConfig with autoTenantCreation and autoTenantActivation enabled" do
93+
schema.create(
94+
class_name: "Question",
95+
description: "Information from a Jeopardy! question",
96+
multi_tenant: true,
97+
auto_tenant_creation: true,
98+
auto_tenant_activation: true
99+
)
100+
101+
expect(@captured_request.body["multiTenancyConfig"]).to eq({enabled: true, autoTenantCreation: true, autoTenantActivation: true})
102+
end
103+
end
79104
end
80105

81106
describe "#delete" do

0 commit comments

Comments
 (0)