Skip to content

Commit 93a3e8f

Browse files
fix(server): stop maintaining the unused event correlation index (pingdotgg#23211)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 296b089 commit 93a3e8f

4 files changed

Lines changed: 52 additions & 0 deletions

File tree

‎apps/server/src/persistence/Migrations.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

‎apps/server/src/persistence/Migrations.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import Migration0074 from "./Migrations/074_ExcludeAttachmentPlaceholdersFromSea
8080
import Migration0075 from "./Migrations/075_SubagentDeliveryState.ts";
8181
import Migration0076 from "./Migrations/076_ProjectionProjectsPinArchive.ts";
8282
import Migration0077 from "./Migrations/077_RepairBooleanSettledOverride.ts";
83+
import Migration0078 from "./Migrations/078_DropOrchestrationEventCorrelationIndex.ts";
8384

8485
const migrationEntries = [
8586
[1, "OrchestrationEvents", Migration0001],
@@ -160,6 +161,7 @@ const migrationEntries = [
160161
[75, "SubagentDeliveryState", Migration0075],
161162
[76, "ProjectionProjectsPinArchive", Migration0076],
162163
[77, "RepairBooleanSettledOverride", Migration0077],
164+
[78, "DropOrchestrationEventCorrelationIndex", Migration0078],
163165
] as const;
164166

165167
export const migrationManifest = migrationEntries.map(([id, name]) => [id, name] as const);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as Effect from "effect/Effect";
2+
import * as SqlClient from "effect/sql/SqlClient";
3+
4+
export default Effect.gen(function* () {
5+
const sql = yield* SqlClient.SqlClient;
6+
7+
// No query filters events by correlation_id, so this index only adds write
8+
// and storage cost. The column and its values stay.
9+
yield* sql`DROP INDEX IF EXISTS idx_orch_events_correlation_id`;
10+
});

‎apps/server/src/persistence/reconcileV2PreviewMigration.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ describe("V2 preview upgrade", () => {
5757
[75, "SubagentDeliveryState"],
5858
[76, "ProjectionProjectsPinArchive"],
5959
[77, "RepairBooleanSettledOverride"],
60+
[78, "DropOrchestrationEventCorrelationIndex"],
6061
]);
6162
assert.deepStrictEqual(yield* runMigrations(), []);
6263
assert.deepStrictEqual(yield* sql`SELECT * FROM orchestration_v2_legacy_imports`, imports);
@@ -157,6 +158,7 @@ describe("V2 preview upgrade", () => {
157158
[75, "SubagentDeliveryState"],
158159
[76, "ProjectionProjectsPinArchive"],
159160
[77, "RepairBooleanSettledOverride"],
161+
[78, "DropOrchestrationEventCorrelationIndex"],
160162
]);
161163
}).pipe(Effect.provide(NodeSqliteClient.layer({ filename: ":memory:" }))),
162164
);

0 commit comments

Comments
 (0)