Skip to content
This repository was archived by the owner on Jan 27, 2023. It is now read-only.

Commit 8e246b6

Browse files
committed
move uniqueness check to each subclass
1 parent 0958abc commit 8e246b6

11 files changed

Lines changed: 48 additions & 17 deletions

lib/cipherstash/client.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,6 @@ def create_collection(name, schema)
155155
}
156156

157157
indexes = schema.fetch("indexes", {}).map do |idx_name, idx_settings|
158-
if Index.invalid_unique_constraint?(idx_settings["unique"], idx_settings["kind"])
159-
raise CipherStash::Client::Error::InvalidSchemaError, "Unique constraint not allowed on type #{idx_settings["kind"].inspect}"
160-
end
161-
162158
# New match, dynamic-match, and field-dynamic-match indexes should use filter indexes.
163159
# ORE match indexes require specifically using a *-ore-match index.
164160
idx_settings["kind"] = case idx_settings["kind"]

lib/cipherstash/index.rb

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,6 @@ def subclass_from_kind(kind)
3535
end
3636
end
3737

38-
def invalid_unique_constraint?(unique, kind)
39-
[
40-
"match",
41-
"ore-match",
42-
"filter-match",
43-
"field-dynamic-match",
44-
"field-dynamic-filter-match",
45-
"field-dynamic-ore-match",
46-
"dynamic-match",
47-
"dynamic-filter-match",
48-
"dynamic-ore-match"].include?(kind) && unique
49-
end
50-
5138
def generate(id, settings, schema_versions)
5239
subclass = subclass_from_kind(settings["mapping"]["kind"])
5340
subclass.new(id, settings, schema_versions)
@@ -56,6 +43,10 @@ def generate(id, settings, schema_versions)
5643
def settings(name, base_settings, schema)
5744
subclass = subclass_from_kind(base_settings["kind"])
5845

46+
if base_settings.key?("unique") && !subclass.uniqueness_supported?
47+
raise CipherStash::Client::Error::InvalidSchemaError, "Unique constraint not allowed on type #{base_settings["kind"].inspect}"
48+
end
49+
5950
{
6051
meta: subclass.meta(name),
6152
mapping: subclass.mapping(base_settings, schema),
@@ -144,6 +135,14 @@ def orderable?
144135
# that do
145136
false
146137
end
138+
139+
# Does this index support a unique constraint?
140+
#
141+
# @return [bool]
142+
#
143+
def uniqueness_supported?
144+
false
145+
end
147146

148147
# Examine the given record and send back index vectors.
149148
#

lib/cipherstash/index/dynamic_filter_match.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ def self.meta(name)
2626
def orderable?
2727
false
2828
end
29+
30+
def self.uniqueness_supported?
31+
false
32+
end
2933

3034
def analyze(uuid, record)
3135
blid = blob_from_uuid(uuid)

lib/cipherstash/index/dynamic_ore_match.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ def orderable?
2222
false
2323
end
2424

25+
def self.uniqueness_supported?
26+
false
27+
end
28+
2529
def analyze(uuid, record)
2630
blid = blob_from_uuid(uuid)
2731
raw_terms = collect_string_fields(record).map(&:last)

lib/cipherstash/index/exact.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ def orderable?
2626
false
2727
end
2828

29+
def self.uniqueness_supported?
30+
true
31+
end
32+
2933
def analyze(uuid, record)
3034
blid = blob_from_uuid(uuid)
3135

lib/cipherstash/index/field_dynamic_exact.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def self.meta(name)
1818
self.ore_meta(name)
1919
end
2020

21+
def self.uniqueness_supported?
22+
false
23+
end
24+
2125
def analyze(uuid, record)
2226
blid = blob_from_uuid(uuid)
2327

lib/cipherstash/index/field_dynamic_filter_match.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ def self.meta(name)
2323
self.filter_meta(name)
2424
end
2525

26+
def self.uniqueness_supported?
27+
false
28+
end
29+
2630
def analyze(uuid, record)
2731
blid = blob_from_uuid(uuid)
2832

lib/cipherstash/index/field_dynamic_ore_match.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def self.meta(name)
1818
self.ore_meta(name)
1919
end
2020

21+
def self.uniqueness_supported?
22+
false
23+
end
24+
2125
def analyze(uuid, record)
2226
blid = blob_from_uuid(uuid)
2327

lib/cipherstash/index/filter_match.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ def orderable?
2727
false
2828
end
2929

30+
def self.uniqueness_supported?
31+
false
32+
end
33+
3034
def analyze(uuid, record)
3135
blid = blob_from_uuid(uuid)
3236

lib/cipherstash/index/ore_match.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ def orderable?
2222
false
2323
end
2424

25+
def self.uniqueness_supported?
26+
false
27+
end
28+
2529
def analyze(uuid, record)
2630
blid = blob_from_uuid(uuid)
2731

0 commit comments

Comments
 (0)