Skip to content

Commit f659f07

Browse files
fix(server): number the message search text migration 081
Main's last migration is 080. The migrator skips every id up to the highest recorded one, so leaving 081 empty would strand whichever change takes it. Also drops a test that only re-ran trigger recreation after all migrations. AI-assisted; verified with the tests and tools listed above.
1 parent 1b5e744 commit f659f07

5 files changed

Lines changed: 11 additions & 32 deletions

File tree

‎apps/server/src/orchestration-v2/messageSearchIndex.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ export const messageSearchText = (sql: SqlClient.SqlClient) =>
6464

6565
/**
6666
* A message's stored text with apostrophes folded, what the index held before
67-
* migration 82. Migration 69's backfill uses it. `payload` is the message's
67+
* migration 81. Migration 69's backfill uses it. `payload` is the message's
6868
* JSON column.
6969
*/
7070
export const indexedMessageText = (sql: SqlClient.SqlClient, payload: string) =>
7171
sql.literal(foldApostrophes(`json_extract(${payload}, '$.text')`));
7272

7373
// What the index stores: a message's readable text with apostrophes folded.
74-
// Migrations 69 and 74 create the triggers before migration 82 adds
74+
// Migrations 69 and 74 create the triggers before migration 81 adds
7575
// search_text, and `t3 doctor` can rebuild a database that has not migrated,
7676
// so those fall back to the stored text.
7777
const indexedText = Effect.fn("MessageSearchIndex.indexedText")(function* (
@@ -101,7 +101,7 @@ export const createMessageSearchTriggers = Effect.fn("MessageSearchIndex.createT
101101
`;
102102
// Streaming deltas rewrite the row many times a second; skip them until the
103103
// message settles. Upserts rewrite every column, so re-index only when what
104-
// the index stores changed; migration 82's backfill writes only search_text.
104+
// the index stores changed; migration 81's backfill writes only search_text.
105105
// Deleting a rowid the index never held is a no-op.
106106
yield* sql`
107107
CREATE TRIGGER orchestration_v2_message_search_update

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ import Migration0077 from "./Migrations/077_RepairBooleanSettledOverride.ts";
8383
import Migration0078 from "./Migrations/078_DropOrchestrationEventCorrelationIndex.ts";
8484
import Migration0079 from "./Migrations/079_DelegatedRecoveryIndexes.ts";
8585
import Migration0080 from "./Migrations/080_ScheduledTaskThreadMode.ts";
86-
import Migration0082 from "./Migrations/082_ProjectionMessageSearchText.ts";
86+
import Migration0081 from "./Migrations/081_ProjectionMessageSearchText.ts";
8787

8888
const migrationEntries = [
8989
[1, "OrchestrationEvents", Migration0001],
@@ -167,7 +167,7 @@ const migrationEntries = [
167167
[78, "DropOrchestrationEventCorrelationIndex", Migration0078],
168168
[79, "DelegatedRecoveryIndexes", Migration0079],
169169
[80, "ScheduledTaskThreadMode", Migration0080],
170-
[82, "ProjectionMessageSearchText", Migration0082],
170+
[81, "ProjectionMessageSearchText", Migration0081],
171171
] as const;
172172

173173
export const migrationManifest = migrationEntries.map(([id, name]) => [id, name] as const);

apps/server/src/persistence/Migrations/082_ProjectionMessageSearchText.test.ts renamed to apps/server/src/persistence/Migrations/081_ProjectionMessageSearchText.test.ts

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
55
import * as Effect from "effect/Effect";
66
import * as SqlClient from "effect/sql/SqlClient";
77

8-
import { recreateMessageSearchTriggers } from "../../orchestration-v2/messageSearchIndex.ts";
98
import { runMigrations } from "../Migrations.ts";
109

1110
const createdAt = "2026-10-01T00:00:00.000Z";
@@ -33,12 +32,12 @@ const indexed = (sql: SqlClient.SqlClient, phrase: string) =>
3332
`.pipe(Effect.map((rows) => rows.map((row) => row.message_id)));
3433

3534
it.layer(NodeSqliteClient.layer({ filename: ":memory:" }))(
36-
"082_ProjectionMessageSearchText",
35+
"081_ProjectionMessageSearchText",
3736
(it) => {
3837
it.effect("backfills readable text only for messages whose citations read differently", () =>
3938
Effect.gen(function* () {
4039
const sql = yield* SqlClient.SqlClient;
41-
yield* runMigrations({ toMigrationInclusive: 81 });
40+
yield* runMigrations({ toMigrationInclusive: 80 });
4241
const insertMessage = (messageId: string, text: unknown) => sql`
4342
INSERT INTO orchestration_v2_projection_messages (
4443
message_id, thread_id, role, streaming, created_at, updated_at, payload_json
@@ -71,8 +70,8 @@ it.layer(NodeSqliteClient.layer({ filename: ":memory:" }))(
7170
{ discard: true },
7271
);
7372

74-
assert.deepEqual(yield* runMigrations({ toMigrationInclusive: 82 }), [
75-
[82, "ProjectionMessageSearchText"],
73+
assert.deepEqual(yield* runMigrations({ toMigrationInclusive: 81 }), [
74+
[81, "ProjectionMessageSearchText"],
7675
]);
7776
const rows = yield* sql<{
7877
readonly message_id: string;
@@ -93,25 +92,5 @@ it.layer(NodeSqliteClient.layer({ filename: ":memory:" }))(
9392
assert.lengthOf(yield* indexed(sql, '"what are you talking about"'), 502);
9493
}),
9594
);
96-
97-
it.effect("keeps indexing readable text when a later migration recreates the triggers", () =>
98-
Effect.gen(function* () {
99-
const sql = yield* SqlClient.SqlClient;
100-
yield* runMigrations();
101-
yield* recreateMessageSearchTriggers(sql);
102-
103-
yield* sql`
104-
INSERT INTO orchestration_v2_projection_messages (
105-
message_id, thread_id, role, streaming, created_at, updated_at, payload_json,
106-
search_text
107-
) VALUES (
108-
'recreated', 'thread:quote', 'user', 0, ${createdAt}, ${createdAt},
109-
${JSON.stringify({ text: `${quote} lantern recreated` })},
110-
${`${readable} lantern recreated`}
111-
)
112-
`;
113-
assert.deepEqual(yield* indexed(sql, '"talking about lantern recreated"'), ["recreated"]);
114-
}),
115-
);
11695
},
11796
);

apps/server/src/persistence/Migrations/082_ProjectionMessageSearchText.ts renamed to apps/server/src/persistence/Migrations/081_ProjectionMessageSearchText.ts

File renamed without changes.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe("V2 preview upgrade", () => {
6060
[78, "DropOrchestrationEventCorrelationIndex"],
6161
[79, "DelegatedRecoveryIndexes"],
6262
[80, "ScheduledTaskThreadMode"],
63-
[82, "ProjectionMessageSearchText"],
63+
[81, "ProjectionMessageSearchText"],
6464
]);
6565
assert.deepStrictEqual(yield* runMigrations(), []);
6666
assert.deepStrictEqual(yield* sql`SELECT * FROM orchestration_v2_legacy_imports`, imports);
@@ -164,7 +164,7 @@ describe("V2 preview upgrade", () => {
164164
[78, "DropOrchestrationEventCorrelationIndex"],
165165
[79, "DelegatedRecoveryIndexes"],
166166
[80, "ScheduledTaskThreadMode"],
167-
[82, "ProjectionMessageSearchText"],
167+
[81, "ProjectionMessageSearchText"],
168168
]);
169169
}).pipe(Effect.provide(NodeSqliteClient.layer({ filename: ":memory:" }))),
170170
);

0 commit comments

Comments
 (0)