@@ -78,6 +78,44 @@ describe("runMigrations", () => {
7878 } ) . pipe ( Effect . provide ( NodeSqliteClient . layer ( { filename : ":memory:" } ) ) ) ,
7979 ) ;
8080
81+ it . effect ( "drops the unused correlation index and keeps correlation values" , ( ) =>
82+ Effect . gen ( function * ( ) {
83+ const sql = yield * SqlClient . SqlClient ;
84+ yield * runMigrations ( { toMigrationInclusive : 54 } ) ;
85+ yield * sql `
86+ INSERT INTO orchestration_events (
87+ event_id, aggregate_kind, stream_id, stream_version, event_type, occurred_at,
88+ command_id, causation_event_id, correlation_id, actor_kind, payload_json, metadata_json
89+ )
90+ VALUES (
91+ 'event-1', 'thread', 'thread-1', 0, 'thread.created', '2026-01-01T00:00:00.000Z',
92+ 'command-1', NULL, 'correlation-1', 'client', '{}', '{}'
93+ )
94+ ` ;
95+
96+ yield * runMigrations ( ) ;
97+
98+ const indexes = yield * sql < { readonly name : string } > `
99+ SELECT name FROM sqlite_master
100+ WHERE type = 'index' AND tbl_name = 'orchestration_events' AND sql IS NOT NULL
101+ ` ;
102+ const indexNames = indexes . map ( ( row ) => row . name ) ;
103+ assert . notInclude ( indexNames , "idx_orch_events_correlation_id" ) ;
104+ for ( const kept of [
105+ "idx_orch_events_stream_version" ,
106+ "idx_orch_events_stream_sequence" ,
107+ "idx_orch_events_command_id" ,
108+ "idx_orchestration_events_agent_stream_sequence" ,
109+ ] ) {
110+ assert . include ( indexNames , kept ) ;
111+ }
112+ const events = yield * sql < { readonly correlation_id : string | null } > `
113+ SELECT correlation_id FROM orchestration_events WHERE event_id = 'event-1'
114+ ` ;
115+ assert . deepStrictEqual ( events , [ { correlation_id : "correlation-1" } ] ) ;
116+ } ) . pipe ( Effect . provide ( NodeSqliteClient . layer ( { filename : ":memory:" } ) ) ) ,
117+ ) ;
118+
81119 it . effect . each ( [ 30 , 54 ] ) ( "still starts with a site-local migration at id %s" , ( id ) =>
82120 Effect . gen ( function * ( ) {
83121 const sql = yield * SqlClient . SqlClient ;
0 commit comments