Skip to content

Commit e8162b0

Browse files
authored
Dev (#290)
* notes for squashed test migrations * filters update - gin btree index notes - proper index normalization for checks * recreate test db before gen
1 parent 7ca0317 commit e8162b0

File tree

20 files changed

+346
-108
lines changed

20 files changed

+346
-108
lines changed

bin/project

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,12 +659,15 @@ clean_yq_array() {
659659
}
660660

661661
go_test() {
662-
local cache_opt="-count=1"
662+
local cache_opt="-count=1" exit_code=1
663663
cache_all "$GEN_CACHE/go-test.md5" .env.$X_ENV db/ >/dev/null && cache_opt=""
664664

665665
set -x
666666
APP_ENV="$X_ENV" go test ${go_test_flags[@]} $cache_opt $@
667+
exit_code=$?
667668
set +x
669+
670+
return $exit_code
668671
}
669672

670673
# Run post-generation scripts in the internal package.
@@ -1227,9 +1230,9 @@ x.test.backend.setup() {
12271230
# NOTE: tests run independently in Go so we can't have a function be called and run
12281231
# only once before any test starts
12291232
run_shared_services up -d --build --remove-orphans --force-recreate --wait
1230-
x.gen
12311233
# no need to migrate, done on every test run internally
12321234
docker.postgres.drop_and_recreate_db $POSTGRES_TEST_DB
1235+
x.gen
12331236
} 2>&4 | xlog >&3; } 4>&1 | xerr >&3; } 3>&1
12341237
xsetup.backup.cleanup
12351238
}
@@ -1350,8 +1353,7 @@ test_backend_watch() {
13501353
--format='%T %f' \
13511354
--timefmt='%s' \
13521355
. && clear &&
1353-
go_test -tags $tags "$@" &&
1354-
echo "${GREEN}✓ All tests passing${OFF}"
1356+
{ go_test -tags $tags "$@" && echo "${GREEN}✓ All tests passing${OFF}"; } || echo "${RED}X Tests failed${OFF}"
13551357
done
13561358
}
13571359

cmd/initial-data/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func main() {
254254
demoWorkItems := []*db.WorkItem{}
255255
var wg sync.WaitGroup
256256
semaphore := make(chan struct{}, 2000)
257-
for i := 1; i <= 100; i++ {
257+
for i := 1; i <= 200; i++ {
258258
semaphore <- struct{}{} // acquire
259259
wg.Add(1)
260260

db/post-migrations/003_cache_tables_triggers.up.sql

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
create or replace function remove_comments (input_string text)
1+
-- NOTE: do not use `extensions.` prefix for indexes. Already in search_path.
2+
create or replace function normalize_index_def (input_string text)
23
returns text
34
as $$
45
declare
@@ -8,12 +9,15 @@ begin
89
output_string := REGEXP_REPLACE(input_string , '/\*([^*]|\*+[^*/])*\*+/' , '' , 'g');
910
-- Remove -- style comments
1011
output_string := REGEXP_REPLACE(output_string , '--.*?\n' , '' , 'g');
11-
-- Replace newlines with spaces
12+
-- Replace newlines
1213
output_string := REGEXP_REPLACE(output_string , E'[\n\r]+' , ' ' , 'g');
13-
-- Replace consecutive spaces with a single space
14+
-- No ; in stored def
15+
output_string := REGEXP_REPLACE(output_string , ';$' , '' , 'g');
1416
output_string := REGEXP_REPLACE(output_string , ' +' , ' ' , 'g');
15-
-- Trim leading and trailing whitespace
16-
output_string := TRIM(output_string);
17+
output_string := REGEXP_REPLACE(output_string , '\s*\(\s*' , '(' , 'g');
18+
output_string := REGEXP_REPLACE(output_string , '\s*\)\s*' , ')' , 'g');
19+
output_string := REGEXP_REPLACE(output_string , '\s*,\s*' , ',' , 'g');
20+
output_string := TRIM(LOWER(output_string));
1721

1822
return output_string;
1923
end;
@@ -36,15 +40,13 @@ begin
3640
return false;
3741
end if;
3842

39-
execute FORMAT('SELECT remove_comments(pg_get_indexdef(''%I''::regclass));' , index_name) into existing_def;
40-
new_index_def := remove_comments (new_index_def);
41-
if existing_def is null then
42-
return true;
43-
ELSIF existing_def <> new_index_def then
44-
return true;
45-
else
43+
execute FORMAT('SELECT normalize_index_def(pg_get_indexdef(''%I''::regclass));' , index_name) into existing_def;
44+
new_index_def := normalize_index_def (new_index_def);
45+
if existing_def is null or existing_def <> new_index_def then
4646
return false;
4747
end if;
48+
49+
return true;
4850
end;
4951
$$
5052
language plpgsql;
@@ -225,31 +227,57 @@ begin
225227
perform
226228
create_or_update_work_item_cache_table (project_name);
227229

228-
idx_name := FORMAT('cache__%I_gin_index' , project_name);
230+
idx_name := FORMAT('public.cache__%I_gin_index' , project_name);
231+
232+
233+
/*
234+
- gin cannot use sort index, just btrees (or using btree_gin since pg12). the only alternative would be RUM
235+
but its not guaranteed to be always faster. also doesnt support like op unless changing code:
236+
see https://github.com/postgrespro/rum/issues/34 for supporting LIKE.
237+
- gin is apparently not too helpful for very short string searches.
238+
- btree not usable for text except for equals and startsWith.
239+
240+
create index on cache__demo_work_items using gin (
241+
description gin_trgm_ops
242+
, last_message_at
243+
, reopened);
229244
245+
set enable_seqscan = "off";
246+
explain analyze select * from cache__demo_work_items where description ilike '%54%' order by last_message_at desc;
247+
248+
1000 rows dataset: (to properly test index, rows returned must be >0)
249+
Index Scan Backward using cache__demo_work_items_last_message_at_idx on cache__demo_work_items (cost=0.28..58.22 rows=20 width=145) (actual time=0.059..0.725 rows=20 loops=1)
250+
Filter: (description ~~* '%54%'::text)
251+
Rows Removed by Filter: 980
252+
*/
230253
case project_name
231254
when 'demo_work_items' then
232255
idx_def := 'using gin (
233-
title extensions.gin_trgm_ops
234-
, line extensions.gin_trgm_ops
235-
, ref extensions.gin_trgm_ops
256+
title gin_trgm_ops
257+
, line gin_trgm_ops
258+
, description gin_trgm_ops
259+
, ref gin_trgm_ops
260+
, last_message_at
236261
, reopened)';
237262
when 'demo_two_work_items' then
238263
idx_def := 'using gin (
239-
title extensions.gin_trgm_ops
264+
title gin_trgm_ops
265+
, description gin_trgm_ops
240266
)';
241267
else
242268
idx_def := ''; raise exception 'No index definition found for cache__%' , project_name;
243269
end case;
244270

245271
if idx_def <> '' and not same_index_definition (idx_name , idx_def) then
246-
execute FORMAT('create index newidx on cache__%I %s;' , project_name , idx_def);
247-
--
248-
execute FORMAT('drop index if exists %s;' , idx_name);
249-
--
250-
execute FORMAT('alter index newidx rename to %s;' , idx_name);
251-
else
252-
raise notice 'skipping identical create index statement: %' , idx_name;
272+
raise notice 'recreating differing index: %' , idx_name;
273+
--
274+
execute FORMAT('create index newidx on cache__%I %s;' , project_name , idx_def);
275+
--
276+
execute FORMAT('drop index if exists %I;' , idx_name);
277+
--
278+
execute FORMAT('alter index newidx rename to %I;' , idx_name);
279+
else
280+
raise notice 'skipping identical create index statement: %' , idx_name;
253281
end if;
254282

255283
execute FORMAT('create or replace trigger work_items_sync_trigger_%1$I

e2e/client/gen/model/paginationFilterPrimitive.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import type { PaginationFilterPrimitiveFilterMode } from './paginationFilterPrimitiveFilterMode'
99

1010
export interface PaginationFilterPrimitive {
11+
caseSensitive?: boolean | null
1112
filterMode: PaginationFilterPrimitiveFilterMode
1213
value: string | null
1314
}

frontend/src/client-validator/gen/dereferenced-schema.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6410,6 +6410,12 @@
64106410
"string",
64116411
"null"
64126412
]
6413+
},
6414+
"caseSensitive": {
6415+
"type": [
6416+
"boolean",
6417+
"null"
6418+
]
64136419
}
64146420
},
64156421
"required": [
@@ -6483,6 +6489,12 @@
64836489
"string",
64846490
"null"
64856491
]
6492+
},
6493+
"caseSensitive": {
6494+
"type": [
6495+
"boolean",
6496+
"null"
6497+
]
64866498
}
64876499
},
64886500
"required": [
@@ -6562,6 +6574,12 @@
65626574
"string",
65636575
"null"
65646576
]
6577+
},
6578+
"caseSensitive": {
6579+
"type": [
6580+
"boolean",
6581+
"null"
6582+
]
65656583
}
65666584
},
65676585
"required": [
@@ -6654,6 +6672,12 @@
66546672
"string",
66556673
"null"
66566674
]
6675+
},
6676+
"caseSensitive": {
6677+
"type": [
6678+
"boolean",
6679+
"null"
6680+
]
66576681
}
66586682
},
66596683
"required": [
@@ -13334,6 +13358,12 @@
1333413358
"string",
1333513359
"null"
1333613360
]
13361+
},
13362+
"caseSensitive": {
13363+
"type": [
13364+
"boolean",
13365+
"null"
13366+
]
1333713367
}
1333813368
},
1333913369
"required": [
@@ -13407,6 +13437,12 @@
1340713437
"string",
1340813438
"null"
1340913439
]
13440+
},
13441+
"caseSensitive": {
13442+
"type": [
13443+
"boolean",
13444+
"null"
13445+
]
1341013446
}
1341113447
},
1341213448
"required": [
@@ -13486,6 +13522,12 @@
1348613522
"string",
1348713523
"null"
1348813524
]
13525+
},
13526+
"caseSensitive": {
13527+
"type": [
13528+
"boolean",
13529+
"null"
13530+
]
1348913531
}
1349013532
},
1349113533
"required": [
@@ -13578,6 +13620,12 @@
1357813620
"string",
1357913621
"null"
1358013622
]
13623+
},
13624+
"caseSensitive": {
13625+
"type": [
13626+
"boolean",
13627+
"null"
13628+
]
1358113629
}
1358213630
},
1358313631
"required": [

frontend/src/client-validator/gen/models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ export interface WorkItemBase {
614614
export interface PaginationFilterPrimitive {
615615
filterMode: PaginationFilterModes
616616
value: string | null
617+
caseSensitive?: boolean | null
617618
}
618619
export interface PaginationFilterArray {
619620
filterMode: PaginationFilterModes

frontend/src/client-validator/gen/schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,6 +2448,12 @@
24482448
"string",
24492449
"null"
24502450
]
2451+
},
2452+
"caseSensitive": {
2453+
"type": [
2454+
"boolean",
2455+
"null"
2456+
]
24512457
}
24522458
},
24532459
"required": [

frontend/src/gen/model/paginationFilterPrimitive.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type * as EntityIDs from 'src/gen/entity-ids'
99
import type { PaginationFilterPrimitiveFilterMode } from './paginationFilterPrimitiveFilterMode';
1010

1111
export interface PaginationFilterPrimitive {
12+
caseSensitive?: boolean | null;
1213
filterMode: PaginationFilterPrimitiveFilterMode;
1314
value: string | null;
1415
}

frontend/src/types/schema.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ export interface components {
808808
PaginationFilterPrimitive: {
809809
filterMode: components["schemas"]["PaginationFilterModes"];
810810
value: string | null;
811+
caseSensitive?: boolean | null;
811812
};
812813
PaginationFilterArray: {
813814
filterMode: components["schemas"]["PaginationFilterModes"];

internal/models/openapi_types.gen.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)