| 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_v2_projection_turn_items_thread_run_idx |
| 10 | ON orchestration_v2_projection_turn_items(thread_id, run_id) |
| 11 | `; |
| 12 | // Shell background work includes idle items as well as pending/running/waiting. |
| 13 | // Keep this predicate aligned with ProjectionStore's pending-item query. |
| 14 | yield* sql` |
| 15 | CREATE INDEX orchestration_v2_projection_turn_items_shell_pending_idx |
| 16 | ON orchestration_v2_projection_turn_items(thread_id, run_id) |
| 17 | WHERE type IN ('command_execution', 'dynamic_tool', 'subagent') |
| 18 | AND status NOT IN ('completed', 'interrupted', 'failed', 'cancelled') |
| 19 | `; |
| 20 | yield* sql` |
| 21 | CREATE INDEX orchestration_v2_projection_messages_latest_user_idx |
| 22 | ON orchestration_v2_projection_messages(thread_id, updated_at DESC, message_id DESC) |
| 23 | WHERE role = 'user' |
| 24 | `; |
| 25 | }); |