@vrplatform/kysely 1.3.45-40394938404 → 1.3.45-40436448893

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,44 @@
1
+ import type { Kysely } from 'kysely';
2
+ import { sql } from 'kysely';
3
+
4
+ // GET /transactions looks up who created each listed transaction in
5
+ // audit.mutation. The general subject index forces a heap read for every
6
+ // mutation of the transaction (updates included) before the INSERT filter, and
7
+ // cold reads took 330-445 ms for 100 rows on the largest teams. This partial index holds only the
8
+ // creation rows and carries the columns the lookup reads. On large databases
9
+ // run scripts/ben-2/pro-19855-create-audit-index.ts first: it builds the index
10
+ // concurrently, and this migration then skips it. The lookup must
11
+ // keep `subject_type` and `op` as constants so a generic plan can use the index.
12
+ export async function up(db: Kysely<unknown>): Promise<void> {
13
+ await sql`set local lock_timeout = '5s'`.execute(db);
14
+ await sql`set local statement_timeout = '30min'`.execute(db);
15
+ const existing = await sql<{ valid: boolean }>`
16
+ select (i.indisvalid and i.indisready) as valid
17
+ from pg_index as i
18
+ inner join pg_class as index_class on index_class.oid = i.indexrelid
19
+ where index_class.relname = 'audit_mutation_transaction_insert_idx'
20
+ `.execute(db);
21
+ // `create index if not exists` locks the table before it finds the index, which
22
+ // times out on a busy database, so skip a valid pre-built index here.
23
+ if (existing.rows[0]?.valid) return;
24
+ // A failed concurrent build leaves an invalid index that `if not exists`
25
+ // would keep, so drop it first.
26
+ if (existing.rows[0]) {
27
+ await sql`
28
+ drop index audit.audit_mutation_transaction_insert_idx
29
+ `.execute(db);
30
+ }
31
+ await sql`
32
+ create index audit_mutation_transaction_insert_idx
33
+ on audit.mutation (tenant_id, subject_id) include (action_id, created_at)
34
+ where subject_type = 'transaction' and op = 'INSERT'
35
+ `.execute(db);
36
+ }
37
+
38
+ export async function down(db: Kysely<unknown>): Promise<void> {
39
+ await sql`set local lock_timeout = '5s'`.execute(db);
40
+ await sql`set local statement_timeout = '60s'`.execute(db);
41
+ await sql`
42
+ drop index if exists audit.audit_mutation_transaction_insert_idx
43
+ `.execute(db);
44
+ }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.3.45-40394938404",
6
+ "version": "1.3.45-40436448893",
7
7
  "description": "",
8
8
  "main": "build/main/index.js",
9
9
  "module": "build/module/index.js",