Skip to content

Commit 6bc0e10

Browse files
committed
chore: update tests to new config behavior
1 parent 29ff0ff commit 6bc0e10

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

src/config/config_test.sql

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ DO $$
3737
c.data #> array['tables', 'users', 'name'] ? 'cast_as'));
3838

3939
-- Match index removed
40-
PERFORM eql_v2.remove_search_config('users', 'name', 'match');
40+
PERFORM eql_v2.remove_search_config('users', 'name', 'match', migrating => true);
4141
ASSERT NOT (SELECT _search_config_exists('users', 'name', 'match'));
4242

43-
-- All indexes removed, delete the emtpty pending config
44-
PERFORM eql_v2.remove_search_config('users', 'name', 'unique');
45-
ASSERT (SELECT NOT EXISTS (SELECT FROM eql_v2_configuration c WHERE c.state = 'pending'));
43+
-- All indexes removed, but column config preserved
44+
PERFORM eql_v2.remove_search_config('users', 'name', 'unique', migrating => true);
45+
ASSERT (SELECT EXISTS (SELECT FROM eql_v2_configuration c WHERE c.state = 'pending'));
46+
ASSERT (SELECT data #> array['tables', 'users', 'name', 'indexes'] = '{}' FROM eql_v2_configuration c WHERE c.state = 'pending');
4647

4748
END;
4849
$$ LANGUAGE plpgsql;
@@ -82,15 +83,16 @@ DO $$
8283

8384

8485
-- Match index removed
85-
PERFORM eql_v2.remove_search_config('users', 'name', 'match');
86+
PERFORM eql_v2.remove_search_config('users', 'name', 'match', migrating => true);
8687
ASSERT NOT (SELECT _search_config_exists('users', 'name', 'match'));
8788

8889
-- Match index removed
89-
PERFORM eql_v2.remove_search_config('blah', 'vtha', 'unique');
90+
PERFORM eql_v2.remove_search_config('blah', 'vtha', 'unique', migrating => true);
9091
ASSERT NOT (SELECT _search_config_exists('users', 'vtha', 'unique'));
9192

92-
-- All indexes removed, delete the emtpty pending config
93-
ASSERT (SELECT NOT EXISTS (SELECT FROM eql_v2_configuration c WHERE c.state = 'pending'));
93+
-- All indexes removed, but column config preserved
94+
ASSERT (SELECT EXISTS (SELECT FROM eql_v2_configuration c WHERE c.state = 'pending'));
95+
ASSERT (SELECT data #> array['tables', 'blah', 'vtha', 'indexes'] = '{}' FROM eql_v2_configuration c WHERE c.state = 'pending');
9496

9597
END;
9698
$$ LANGUAGE plpgsql;
@@ -122,9 +124,10 @@ DO $$
122124
WHERE c.state = 'pending' AND
123125
c.data #> array['tables', 'users', 'name'] ? 'cast_as'));
124126

125-
-- All indexes removed, delete the emtpty pending config
126-
PERFORM eql_v2.remove_search_config('users', 'name', 'match');
127-
ASSERT (SELECT NOT EXISTS (SELECT FROM eql_v2_configuration c WHERE c.state = 'pending'));
127+
-- All indexes removed, but column config preserved
128+
PERFORM eql_v2.remove_search_config('users', 'name', 'match', migrating => true);
129+
ASSERT (SELECT EXISTS (SELECT FROM eql_v2_configuration c WHERE c.state = 'pending'));
130+
ASSERT (SELECT data #> array['tables', 'users', 'name', 'indexes'] = '{}' FROM eql_v2_configuration c WHERE c.state = 'pending');
128131
END;
129132
$$ LANGUAGE plpgsql;
130133

src/config/functions.sql

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,16 @@ AS $$
285285

286286
PERFORM eql_v2.remove_encrypted_constraint(table_name, column_name);
287287

288-
-- update the config and migrate (even if empty)
289-
UPDATE public.eql_v2_configuration SET data = _config WHERE state = 'pending';
290-
291-
IF NOT migrating THEN
292-
PERFORM eql_v2.migrate_config();
293-
PERFORM eql_v2.activate_config();
288+
-- if config is completely empty, delete it; otherwise update it
289+
IF _config #> array['tables'] = '{}' THEN
290+
DELETE FROM public.eql_v2_configuration WHERE state = 'pending';
291+
ELSE
292+
UPDATE public.eql_v2_configuration SET data = _config WHERE state = 'pending';
293+
294+
IF NOT migrating THEN
295+
PERFORM eql_v2.migrate_config();
296+
PERFORM eql_v2.activate_config();
297+
END IF;
294298
END IF;
295299

296300
-- exeunt

0 commit comments

Comments
 (0)