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

101_DelegatedTaskReadIndexes.ts

22 lines1.0 KB

1import * as Effect from "effect/Effect";
2import * as SqlClient from "effect/sql/SqlClient";
3​
4import { DELEGATED_TASK_MESSAGE_CONDITION } from "../../orchestration-v2/delegatedTaskMessage.ts";
5​
6export default Effect.gen(function* () {
7 const sql = yield* SqlClient.SqlClient;
8​
9 // Finalizing a delegated task finds its tasks' runs and the child's wakes without reading the
10 // child's history. ProjectionStore.getDelegatedChildControls and the delegatedTaskMessagesOnly read
11 // must spell the same expressions.
12 yield* sql`
13 CREATE INDEX IF NOT EXISTS orchestration_v2_projection_runs_delegated_task_idx
14 ON orchestration_v2_projection_runs(thread_id, json_extract(payload_json, '$.delegatedTaskId'))
15 WHERE json_valid(payload_json) AND json_extract(payload_json, '$.delegatedTaskId') IS NOT NULL
16 `;
17 yield* sql.unsafe(`
18 CREATE INDEX IF NOT EXISTS orchestration_v2_projection_messages_delegated_task_idx
19 ON orchestration_v2_projection_messages(thread_id, created_at, message_id)
20 WHERE ${DELEGATED_TASK_MESSAGE_CONDITION}
21 `);
22});