1import * as Effect from "effect/Effect";
2import * as SqlClient from "effect/sql/SqlClient";
3
4/**
5 * Tracks the incremental import of v1 materialized thread state into the v2
6 * event model. Shells are imported synchronously at startup; full transcripts
7 * are hydrated on demand and by a low-priority background pass. This table
8 * setup is composed by migration 055.
9 */
10export default Effect.gen(function* () {
11 const sql = yield* SqlClient.SqlClient;
12
13 yield* sql`
14 CREATE TABLE orchestration_v2_legacy_imports (
15 thread_id TEXT PRIMARY KEY,
16 source_updated_at TEXT NOT NULL,
17 shell_imported_at TEXT NOT NULL,
18 transcript_imported_at TEXT,
19 imported_message_count INTEGER NOT NULL DEFAULT 0,
20 last_error TEXT
21 )
22 `;
23
24 yield* sql`
25 CREATE INDEX orchestration_v2_legacy_imports_pending_transcript_idx
26 ON orchestration_v2_legacy_imports(transcript_imported_at, shell_imported_at, thread_id)
27 `;
28});