| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as SqlClient from "effect/sql/SqlClient"; |
| 3 | |
| 4 | // Index setup composed by migration 055. |
| 5 | export default Effect.gen(function* () { |
| 6 | const sql = yield* SqlClient.SqlClient; |
| 7 | |
| 8 | yield* sql` |
| 9 | CREATE INDEX orchestration_events_v2_created_threads_idx |
| 10 | ON orchestration_events(stream_id) |
| 11 | WHERE application_event_version = 2 |
| 12 | AND aggregate_kind = 'thread' |
| 13 | AND event_type = 'thread.created' |
| 14 | `; |
| 15 | yield* sql` |
| 16 | CREATE INDEX orchestration_v2_projection_runs_recovery_idx |
| 17 | ON orchestration_v2_projection_runs(status, thread_id) |
| 18 | WHERE status IN ('queued', 'preparing', 'starting', 'running', 'waiting') |
| 19 | `; |
| 20 | yield* sql` |
| 21 | CREATE INDEX orchestration_v2_projection_requests_recovery_idx |
| 22 | ON orchestration_v2_projection_runtime_requests(thread_id) |
| 23 | WHERE status = 'pending' |
| 24 | `; |
| 25 | yield* sql` |
| 26 | CREATE INDEX orchestration_v2_projection_turn_items_recovery_idx |
| 27 | ON orchestration_v2_projection_turn_items(thread_id) |
| 28 | WHERE type IN ('command_execution', 'dynamic_tool', 'subagent') |
| 29 | AND status IN ('pending', 'running', 'waiting') |
| 30 | `; |
| 31 | }); |