Skip to content

Commit fed0d16

Browse files
committed
refactor: rename add_index to add_search_term
1 parent 1ed5e8b commit fed0d16

File tree

8 files changed

+145
-138
lines changed

8 files changed

+145
-138
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ In order to perform searchable operations on encrypted data, you must configure
191191
192192
### Adding an index
193193

194-
Add an index to an encrypted column using the `eql_v2.add_index` function:
194+
Add an index to an encrypted column using the `eql_v2.add_search_config` function:
195195

196196
```sql
197-
SELECT eql_v2.add_index(
197+
SELECT eql_v2.add_search_config(
198198
'table_name', -- Name of the table
199199
'column_name', -- Name of the column
200200
'index_name', -- Index kind ('unique', 'match', 'ore', 'ste_vec')
@@ -208,7 +208,7 @@ You can read more about the index configuration options [here](docs/reference/IN
208208
**Example (Unique index):**
209209

210210
```sql
211-
SELECT eql_v2.add_index(
211+
SELECT eql_v2.add_search_config(
212212
'users',
213213
'encrypted_email',
214214
'unique',
@@ -236,7 +236,7 @@ Enable equality search on encrypted data using the `eql_v2.unique` function.
236236
**Index configuration example:**
237237

238238
```sql
239-
SELECT eql_v2.add_index(
239+
SELECT eql_v2.add_search_config(
240240
'users',
241241
'encrypted_email',
242242
'unique',
@@ -266,7 +266,7 @@ Enables basic full-text search on encrypted data using the `eql_v2.match` functi
266266
**Index configuration example:**
267267

268268
```sql
269-
SELECT eql_v2.add_index(
269+
SELECT eql_v2.add_search_config(
270270
'users',
271271
'encrypted_email',
272272
'match',

docs/reference/INDEX.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# EQL index configuration
22

33
The following functions allow you to configure indexes for encrypted columns.
4-
All these functions modify the `cs_configuration_v2` table in your database, and are added during the EQL installation.
4+
All these functions modify the `eql_v2_configuration` table in your database, and are added during the EQL installation.
55

6-
> **IMPORTANT:** When you modify or add an index, you must re-encrypt data that's already been stored in the database.
6+
> **IMPORTANT:** When you modify or add search configuration index, you must re-encrypt data that's already been stored in the database.
77
> The CipherStash encryption solution will encrypt the data based on the current state of the configuration.
88
9-
### Adding an index (`cs_add_index`)
9+
### Configuring search (`eql_v2.add_search_config`)
1010

1111
Add an index to an encrypted column.
1212

1313
```sql
14-
SELECT cs_add_index_v2(
14+
SELECT eql_v2.add_search_config(
1515
'table_name', -- Name of the table
1616
'column_name', -- Name of the column
1717
'index_name', -- Index kind ('unique', 'match', 'ore', 'ste_vec')

docs/reference/JSON.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Similar to how you configure indexes for text data, you can configure indexes fo
3636
The only difference is that you need to specify the `cast_as` parameter as `json` or `jsonb`.
3737

3838
```sql
39-
SELECT cs_add_index_v2(
39+
SELECT eql_v2.add_search_config(
4040
'users',
4141
'encrypted_json',
4242
'ste_vec',

docs/tutorials/GETTINGSTARTED.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ We now have our database schema setup to store encrypted data.
160160

161161
In this part we will learn about why we need to add indexes and how to add them.
162162

163-
When you install EQL, a table called `cs_configuration_v2` is created in your database.
163+
When you install EQL, a table called `eql_v2_configuration` is created in your database.
164164

165165
Adding indexes updates this table with the details and configuration needed for CipherStash Proxy to know how to encrypt your data, and what types of queries are able to be performed
166166

@@ -196,7 +196,7 @@ SELECT cs_add_index_v2('users', 'email_encrypted', 'ore', 'text');
196196
CREATE INDEX ON users (cs_ore_64_8_v2(email_encrypted));
197197
```
198198

199-
After adding these indexes, our `cs_configuration_v2` table will look like this:
199+
After adding these indexes, our `eql_v2_configuration` table will look like this:
200200

201201
```bash
202202
id | 1
@@ -228,7 +228,7 @@ Prerequisites:
228228
- [Database is setup](#setup-your-database)
229229
- [Indexes added](#adding-indexes)
230230

231-
Ensure CipherStash Proxy has the most up to date configuration from the `cs_configuration_v2` table.
231+
Ensure CipherStash Proxy has the most up to date configuration from the `eql_v2_configuration` table.
232232

233233
CipherStash Proxy pings the database every 60 seconds to refresh the configuration but we can force the refresh by running:
234234

src/config/config_test.sql

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
--
55
-- Helper function for assertions
66
--
7-
DROP FUNCTION IF EXISTS _index_exists(text, text, text, text);
8-
CREATE FUNCTION _index_exists(table_name text, column_name text, index_name text, state text DEFAULT 'pending')
7+
DROP FUNCTION IF EXISTS _search_config_exists(text, text, text, text);
8+
CREATE FUNCTION _search_config_exists(table_name text, column_name text, index_name text, state text DEFAULT 'pending')
99
RETURNS boolean
1010
LANGUAGE sql STRICT PARALLEL SAFE
1111
BEGIN ATOMIC
@@ -25,23 +25,23 @@ DO $$
2525
BEGIN
2626

2727
-- Add indexes
28-
PERFORM eql_v2.add_index('users', 'name', 'match');
29-
ASSERT (SELECT _index_exists('users', 'name', 'match'));
28+
PERFORM eql_v2.add_search_config('users', 'name', 'match');
29+
ASSERT (SELECT _search_config_exists('users', 'name', 'match'));
3030

3131
-- Add index with cast
32-
PERFORM eql_v2.add_index('users', 'name', 'unique', 'int');
33-
ASSERT (SELECT _index_exists('users', 'name', 'unique'));
32+
PERFORM eql_v2.add_search_config('users', 'name', 'unique', 'int');
33+
ASSERT (SELECT _search_config_exists('users', 'name', 'unique'));
3434

3535
ASSERT (SELECT EXISTS (SELECT id FROM eql_v2_configuration c
3636
WHERE c.state = 'pending' AND
3737
c.data #> array['tables', 'users', 'name'] ? 'cast_as'));
3838

3939
-- Match index removed
40-
PERFORM eql_v2.remove_index('users', 'name', 'match');
41-
ASSERT NOT (SELECT _index_exists('users', 'name', 'match'));
40+
PERFORM eql_v2.remove_search_config('users', 'name', 'match');
41+
ASSERT NOT (SELECT _search_config_exists('users', 'name', 'match'));
4242

4343
-- All indexes removed, delete the emtpty pending config
44-
PERFORM eql_v2.remove_index('users', 'name', 'unique');
44+
PERFORM eql_v2.remove_search_config('users', 'name', 'unique');
4545
ASSERT (SELECT NOT EXISTS (SELECT FROM eql_v2_configuration c WHERE c.state = 'pending'));
4646

4747
END;
@@ -60,16 +60,16 @@ DO $$
6060
BEGIN
6161

6262
-- Add indexes
63-
PERFORM eql_v2.add_index('users', 'name', 'match');
64-
ASSERT (SELECT _index_exists('users', 'name', 'match'));
63+
PERFORM eql_v2.add_search_config('users', 'name', 'match');
64+
ASSERT (SELECT _search_config_exists('users', 'name', 'match'));
6565

6666
ASSERT (SELECT EXISTS (SELECT id FROM eql_v2_configuration c
6767
WHERE c.state = 'pending' AND
6868
c.data #> array['tables', 'users', 'name', 'indexes'] ? 'match'));
6969

7070
-- Add index with cast
71-
PERFORM eql_v2.add_index('blah', 'vtha', 'unique', 'int');
72-
ASSERT (SELECT _index_exists('blah', 'vtha', 'unique'));
71+
PERFORM eql_v2.add_search_config('blah', 'vtha', 'unique', 'int');
72+
ASSERT (SELECT _search_config_exists('blah', 'vtha', 'unique'));
7373

7474
ASSERT (SELECT EXISTS (SELECT id FROM eql_v2_configuration c
7575
WHERE c.state = 'pending' AND
@@ -82,12 +82,12 @@ DO $$
8282

8383

8484
-- Match index removed
85-
PERFORM eql_v2.remove_index('users', 'name', 'match');
86-
ASSERT NOT (SELECT _index_exists('users', 'name', 'match'));
85+
PERFORM eql_v2.remove_search_config('users', 'name', 'match');
86+
ASSERT NOT (SELECT _search_config_exists('users', 'name', 'match'));
8787

8888
-- Match index removed
89-
PERFORM eql_v2.remove_index('blah', 'vtha', 'unique');
90-
ASSERT NOT (SELECT _index_exists('users', 'vtha', 'unique'));
89+
PERFORM eql_v2.remove_search_config('blah', 'vtha', 'unique');
90+
ASSERT NOT (SELECT _search_config_exists('users', 'vtha', 'unique'));
9191

9292
-- All indexes removed, delete the emtpty pending config
9393
ASSERT (SELECT NOT EXISTS (SELECT FROM eql_v2_configuration c WHERE c.state = 'pending'));
@@ -107,12 +107,12 @@ $$ LANGUAGE plpgsql;
107107

108108
DO $$
109109
BEGIN
110-
PERFORM eql_v2.add_index('users', 'name', 'match');
111-
ASSERT (SELECT _index_exists('users', 'name', 'match'));
110+
PERFORM eql_v2.add_search_config('users', 'name', 'match');
111+
ASSERT (SELECT _search_config_exists('users', 'name', 'match'));
112112

113113
-- Pending configuration contains the path `user/name.match.option`
114-
PERFORM eql_v2.modify_index('users', 'name', 'match', 'int', '{"option": "value"}'::jsonb);
115-
ASSERT (SELECT _index_exists('users', 'name', 'match'));
114+
PERFORM eql_v2.modify_search_config('users', 'name', 'match', 'int', '{"option": "value"}'::jsonb);
115+
ASSERT (SELECT _search_config_exists('users', 'name', 'match'));
116116

117117
ASSERT (SELECT EXISTS (SELECT id FROM eql_v2_configuration c
118118
WHERE c.state = 'pending' AND
@@ -123,7 +123,7 @@ DO $$
123123
c.data #> array['tables', 'users', 'name'] ? 'cast_as'));
124124

125125
-- All indexes removed, delete the emtpty pending config
126-
PERFORM eql_v2.remove_index('users', 'name', 'match');
126+
PERFORM eql_v2.remove_search_config('users', 'name', 'match');
127127
ASSERT (SELECT NOT EXISTS (SELECT FROM eql_v2_configuration c WHERE c.state = 'pending'));
128128
END;
129129
$$ LANGUAGE plpgsql;
@@ -160,16 +160,16 @@ INSERT INTO eql_v2_configuration (state, data) VALUES (
160160
-- An encrypting config should exist
161161
DO $$
162162
BEGIN
163-
ASSERT (SELECT _index_exists('users', 'blah', 'match', 'active'));
163+
ASSERT (SELECT _search_config_exists('users', 'blah', 'match', 'active'));
164164

165-
PERFORM eql_v2.add_index('users', 'name', 'match');
165+
PERFORM eql_v2.add_search_config('users', 'name', 'match');
166166

167167
-- index added to name
168-
ASSERT (SELECT _index_exists('users', 'name', 'match' ));
168+
ASSERT (SELECT _search_config_exists('users', 'name', 'match' ));
169169

170170
-- pending is a copy of the active config
171171
-- and the active index still exists
172-
ASSERT (SELECT _index_exists('users', 'blah', 'match'));
172+
ASSERT (SELECT _search_config_exists('users', 'blah', 'match'));
173173

174174
END;
175175
$$ LANGUAGE plpgsql;

src/config/functions.sql

Lines changed: 8 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,16 @@
11
-- REQUIRE: src/config/types.sql
2+
-- REQUIRE: src/config/functions_private.sql
23
--
3-
-- Configuration functions
4+
-- Customer-facing configuration functions
5+
-- Depends on private functions for implemenation
46
--
57
--
68

7-
8-
CREATE FUNCTION eql_v2.config_default(config jsonb)
9-
RETURNS jsonb
10-
IMMUTABLE PARALLEL SAFE
11-
AS $$
12-
BEGIN
13-
IF config IS NULL THEN
14-
SELECT jsonb_build_object('v', 1, 'tables', jsonb_build_object()) INTO config;
15-
END IF;
16-
RETURN config;
17-
END;
18-
$$ LANGUAGE plpgsql;
19-
20-
21-
22-
CREATE FUNCTION eql_v2.config_add_table(table_name text, config jsonb)
23-
RETURNS jsonb
24-
IMMUTABLE PARALLEL SAFE
25-
AS $$
26-
DECLARE
27-
tbl jsonb;
28-
BEGIN
29-
IF NOT config #> array['tables'] ? table_name THEN
30-
SELECT jsonb_insert(config, array['tables', table_name], jsonb_build_object()) INTO config;
31-
END IF;
32-
RETURN config;
33-
END;
34-
$$ LANGUAGE plpgsql;
35-
36-
37-
-- Add the column if it doesn't exist
38-
39-
CREATE FUNCTION eql_v2.config_add_column(table_name text, column_name text, config jsonb)
40-
RETURNS jsonb
41-
IMMUTABLE PARALLEL SAFE
42-
AS $$
43-
DECLARE
44-
col jsonb;
45-
BEGIN
46-
IF NOT config #> array['tables', table_name] ? column_name THEN
47-
SELECT jsonb_build_object('indexes', jsonb_build_object()) into col;
48-
SELECT jsonb_set(config, array['tables', table_name, column_name], col) INTO config;
49-
END IF;
50-
RETURN config;
51-
END;
52-
$$ LANGUAGE plpgsql;
53-
54-
55-
-- Set the cast
56-
57-
CREATE FUNCTION eql_v2.config_add_cast(table_name text, column_name text, cast_as text, config jsonb)
58-
RETURNS jsonb
59-
IMMUTABLE PARALLEL SAFE
60-
AS $$
61-
BEGIN
62-
SELECT jsonb_set(config, array['tables', table_name, column_name, 'cast_as'], to_jsonb(cast_as)) INTO config;
63-
RETURN config;
64-
END;
65-
$$ LANGUAGE plpgsql;
66-
67-
68-
-- Add the column if it doesn't exist
69-
70-
CREATE FUNCTION eql_v2.config_add_index(table_name text, column_name text, index_name text, opts jsonb, config jsonb)
71-
RETURNS jsonb
72-
IMMUTABLE PARALLEL SAFE
73-
AS $$
74-
BEGIN
75-
SELECT jsonb_insert(config, array['tables', table_name, column_name, 'indexes', index_name], opts) INTO config;
76-
RETURN config;
77-
END;
78-
$$ LANGUAGE plpgsql;
79-
80-
81-
--
82-
-- Default options for match index
83-
--
84-
85-
CREATE FUNCTION eql_v2.config_match_default()
86-
RETURNS jsonb
87-
LANGUAGE sql STRICT PARALLEL SAFE
88-
BEGIN ATOMIC
89-
SELECT jsonb_build_object(
90-
'k', 6,
91-
'm', 2048,
92-
'include_original', true,
93-
'tokenizer', json_build_object('kind', 'ngram', 'token_length', 3),
94-
'token_filters', json_build_array(json_build_object('kind', 'downcase')));
95-
END;
96-
979
--
9810
-- Adds an index term to the configuration
9911
--
10012

101-
CREATE FUNCTION eql_v2.add_index(table_name text, column_name text, index_name text, cast_as text DEFAULT 'text', opts jsonb DEFAULT '{}')
13+
CREATE FUNCTION eql_v2.add_search_config(table_name text, column_name text, index_name text, cast_as text DEFAULT 'text', opts jsonb DEFAULT '{}')
10214
RETURNS jsonb
10315

10416
AS $$
@@ -149,7 +61,7 @@ $$ LANGUAGE plpgsql;
14961

15062

15163

152-
CREATE FUNCTION eql_v2.remove_index(table_name text, column_name text, index_name text)
64+
CREATE FUNCTION eql_v2.remove_search_config(table_name text, column_name text, index_name text)
15365
RETURNS jsonb
15466
AS $$
15567
DECLARE
@@ -209,12 +121,12 @@ $$ LANGUAGE plpgsql;
209121

210122

211123

212-
CREATE FUNCTION eql_v2.modify_index(table_name text, column_name text, index_name text, cast_as text DEFAULT 'text', opts jsonb DEFAULT '{}')
124+
CREATE FUNCTION eql_v2.modify_search_config(table_name text, column_name text, index_name text, cast_as text DEFAULT 'text', opts jsonb DEFAULT '{}')
213125
RETURNS jsonb
214126
AS $$
215127
BEGIN
216-
PERFORM eql_v2.remove_index(table_name, column_name, index_name);
217-
RETURN eql_v2.add_index(table_name, column_name, index_name, cast_as, opts);
128+
PERFORM eql_v2.remove_search_config(table_name, column_name, index_name);
129+
RETURN eql_v2.add_search_config(table_name, column_name, index_name, cast_as, opts);
218130
END;
219131
$$ LANGUAGE plpgsql;
220132

0 commit comments

Comments
 (0)