Skip to content

Commit 4127d72

Browse files
authored
chore: add cover index for applications and roles table (#8013)
1 parent d5cbeb8 commit 4127d72

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { sql } from '@silverhand/slonik';
2+
3+
import type { AlterationScript } from '../lib/types/alteration.js';
4+
5+
const alteration: AlterationScript = {
6+
up: async (pool) => {
7+
await pool.query(sql`
8+
create index applications__include_type_is_third_party
9+
on applications (tenant_id) include (type, is_third_party);
10+
`);
11+
12+
// Update table statistics to help query planner use the new index efficiently
13+
await pool.query(sql`
14+
analyze applications;
15+
`);
16+
17+
await pool.query(sql`
18+
create index roles__include_type_name
19+
on roles (tenant_id) include (type, name);
20+
`);
21+
22+
// Update table statistics to help query planner use the new index efficiently
23+
await pool.query(sql`
24+
analyze roles;
25+
`);
26+
},
27+
down: async (pool) => {
28+
await pool.query(sql`
29+
drop index if exists applications__include_type_is_third_party;
30+
`);
31+
32+
await pool.query(sql`
33+
drop index if exists roles__include_type_name;
34+
`);
35+
},
36+
};
37+
38+
export default alteration;

packages/schemas/tables/applications.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ create table applications (
2323
create index applications__id
2424
on applications (tenant_id, id);
2525

26+
create index applications__include_type_is_third_party
27+
on applications (tenant_id) include (type, is_third_party);
28+
2629
create index applications__is_third_party
2730
on applications (tenant_id, is_third_party);
2831

packages/schemas/tables/roles.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ create table roles (
1919
create index roles__id
2020
on roles (tenant_id, id);
2121

22+
create index roles__include_type_name
23+
on roles (tenant_id) include (type, name);
24+
2225
create index roles__type
2326
on roles (tenant_id, type);
2427

0 commit comments

Comments
 (0)