Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

019_ProjectionSnapshotLookupIndexes.test.ts

73 lines2.2 KB

1import { assert, it } from "@effect/vitest";
2import { Effect, Layer } from "effect";
3import * as SqlClient from "effect/unstable/sql/SqlClient";
4​
5import { runMigrations } from "../Migrations.ts";
6import * as NodeSqliteClient from "../NodeSqliteClient.ts";
7​
8const layer = it.layer(Layer.mergeAll(NodeSqliteClient.layerMemory()));
9​
10layer("019_ProjectionSnapshotLookupIndexes", (it) => {
11 it.effect("creates indexes for targeted projection lookup filters", () =>
12 Effect.gen(function* () {
13 const sql = yield* SqlClient.SqlClient;
14​
15 yield* runMigrations({ toMigrationInclusive: 18 });
16 yield* runMigrations({ toMigrationInclusive: 19 });
17​
18 const projectIndexes = yield* sql<{
19 readonly seq: number;
20 readonly name: string;
21 readonly unique: number;
22 readonly origin: string;
23 readonly partial: number;
24 }>`
25 PRAGMA index_list(projection_projects)
26 `;
27 assert.ok(
28 projectIndexes.some(
29 (index) => index.name === "idx_projection_projects_workspace_root_deleted_at",
30 ),
31 );
32​
33 const projectIndexColumns = yield* sql<{
34 readonly seqno: number;
35 readonly cid: number;
36 readonly name: string;
37 }>`
38 PRAGMA index_info('idx_projection_projects_workspace_root_deleted_at')
39 `;
40 assert.deepStrictEqual(
41 projectIndexColumns.map((column) => column.name),
42 ["workspace_root", "deleted_at"],
43 );
44​
45 const threadIndexes = yield* sql<{
46 readonly seq: number;
47 readonly name: string;
48 readonly unique: number;
49 readonly origin: string;
50 readonly partial: number;
51 }>`
52 PRAGMA index_list(projection_threads)
53 `;
54 assert.ok(
55 threadIndexes.some(
56 (index) => index.name === "idx_projection_threads_project_deleted_created",
57 ),
58 );
59​
60 const threadIndexColumns = yield* sql<{
61 readonly seqno: number;
62 readonly cid: number;
63 readonly name: string;
64 }>`
65 PRAGMA index_info('idx_projection_threads_project_deleted_created')
66 `;
67 assert.deepStrictEqual(
68 threadIndexColumns.map((column) => column.name),
69 ["project_id", "deleted_at", "created_at"],
70 );
71 }),
72 );
73});