The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 07:00 UTC
fix(server): dev seeding accepts migration histories the server boots (#24665)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Victor Vogel committed
Nov 1, 2026 at 16:00 UTC
eb129c0600cafb2ff237d085a1b3ac0581b34985
2 files changed
+69
-39
apps/server/scripts/migrate-dev-db.test.ts
+67
@@ -253,6 +253,73 @@ it.layer(NodeServices.layer)("migrate-dev-db", (it) => {
253
}),
254
);
255
256
+ it.effect("seeds from a source that recorded another migration below V2", () =>
257
+ Effect.gen(function* () {
258
+ const fs = yield* FileSystem.FileSystem;
259
+ const sourceDir = yield* fs.makeTempDirectoryScoped({ prefix: "migrate-dev-db-local-" });
260
+ const destDir = yield* fs.makeTempDirectoryScoped({ prefix: "migrate-dev-db-local-dest-" });
261
+ const source = yield* createFixtureSource(sourceDir);
262
+ yield* withDatabase(
263
+ source,
264
+ Effect.gen(function* () {
265
+ const sql = yield* SqlClient.SqlClient;
266
+ yield* sql`UPDATE effect_sql_migrations SET name = 'SiteLocalMigration'
267
+ WHERE migration_id = 51`;
268
+ }),
269
+ );
270
+
271
+ const result = yield* runMigrateDevDb(
272
+ { baseDir: destDir, source, projects: 5, threadsPerProject: 2 },
273
+ { sharedHome: sourceDir },
274
+ );
275
+ const threads = yield* withDatabase(
276
+ result.databasePath,
277
+ Effect.gen(function* () {
278
+ const sql = yield* SqlClient.SqlClient;
279
+ return yield* sql<{ thread_id: string }>`
280
+ SELECT thread_id FROM orchestration_v2_projection_threads ORDER BY thread_id`;
281
+ }),
282
+ );
283
+ assert.deepStrictEqual(
284
+ threads.map((row) => row.thread_id),
285
+ ["fork-thread", "settled-thread", "stopped-thread"],
286
+ );
287
+ }),
288
+ );
289
+
290
+ it.effect("refuses a source whose V2 migration history clashes with this checkout", () =>
291
+ Effect.gen(function* () {
292
+ const fs = yield* FileSystem.FileSystem;
293
+ const sourceDir = yield* fs.makeTempDirectoryScoped({ prefix: "migrate-dev-db-clash-" });
294
+ const destDir = yield* fs.makeTempDirectoryScoped({ prefix: "migrate-dev-db-clash-dest-" });
295
+ const source = yield* createFixtureSource(sourceDir);
296
+ yield* withDatabase(
297
+ source,
298
+ Effect.gen(function* () {
299
+ const sql = yield* SqlClient.SqlClient;
300
+ yield* sql`UPDATE effect_sql_migrations SET name = 'OtherBuildMigration'
301
+ WHERE migration_id = 60`;
302
+ }),
303
+ );
304
+
305
+ const destination = yield* createFixtureSource(destDir);
306
+ const sourceBefore = yield* fs.readFile(source);
307
+ const destinationBefore = yield* fs.readFile(destination);
308
+
309
+ const error = yield* runMigrateDevDb(
310
+ { baseDir: destDir, source, projects: 5, threadsPerProject: 2 },
311
+ { sharedHome: sourceDir },
312
+ ).pipe(Effect.flip);
313
+ assert.equal(error._tag, "MigrateDevDbPhaseError");
314
+ if (error._tag === "MigrateDevDbPhaseError") {
315
+ assert.equal(error.phase, "migrate");
316
+ assert.include(String(error.cause), "60_ThreadSnapshotWindowIndexes");
317
+ }
318
+ assert.deepStrictEqual(yield* fs.readFile(source), sourceBefore);
319
+ assert.deepStrictEqual(yield* fs.readFile(destination), destinationBefore);
320
+ }),
321
+ );
322
+
323
it.effect("refuses while a dev server holds the destination", () =>
324
Effect.gen(function* () {
325
const fs = yield* FileSystem.FileSystem;
apps/server/scripts/migrate-dev-db.ts
+2
-39
@@ -17,7 +17,7 @@ import { Command, Flag } from "effect/cli";
17
18
import * as ProjectionStore from "../src/orchestration-v2/ProjectionStore.ts";
19
import { rebuildMessageSearch } from "../src/orchestration-v2/messageSearchIndex.ts";
20
-import { migrationManifest, runMigrations } from "../src/persistence/Migrations.ts";
20
+import { runMigrations } from "../src/persistence/Migrations.ts";
21
import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
22
23
export class MigrateDevDbNotInWorktreeError extends Schema.TaggedError<MigrateDevDbNotInWorktreeError>()(
@@ -89,23 +89,10 @@ export class MigrateDevDbDestinationBusyError extends Schema.TaggedError<Migrate
89
}
90
}
91
92
-export class MigrateDevDbSlotCollisionError extends Schema.TaggedError<MigrateDevDbSlotCollisionError>()(
93
- "MigrateDevDbSlotCollisionError",
94
- {
95
- slot: Schema.Number,
96
- codeName: Schema.String,
97
- appliedName: Schema.String,
98
- },
99
-) {
100
- override get message(): string {
101
- return `Migration slot collision at ${this.slot}: this checkout registers '${this.codeName}' but the database already applied '${this.appliedName}' in that slot. Renumber the new migration to a free slot.`;
102
- }
103
-}
104
-
92
export class MigrateDevDbPhaseError extends Schema.TaggedError<MigrateDevDbPhaseError>()(
93
"MigrateDevDbPhaseError",
94
{
108
- phase: Schema.Literals(["snapshot", "prune", "compact", "migrate", "verify"]),
95
+ phase: Schema.Literals(["snapshot", "prune", "compact", "migrate"]),
96
databasePath: Schema.String,
97
cause: Schema.Defect(),
98
},
@@ -416,19 +403,6 @@ const pruneSnapshot = Effect.fn("pruneDevDbSnapshot")(function* (input: RunMigra
403
};
404
});
405
419
-const verifyMigrationSlots = Effect.fn("verifyMigrationSlots")(function* () {
420
- const sql = yield* SqlClient.SqlClient;
421
- const applied = yield* sql<{ migration_id: number; name: string }>`
422
- SELECT migration_id, name FROM effect_sql_migrations`;
423
- const appliedById = new Map(applied.map((row) => [Number(row.migration_id), row.name]));
424
- for (const [slot, codeName] of migrationManifest) {
425
- const appliedName = appliedById.get(slot);
426
- if (appliedName !== undefined && appliedName !== codeName) {
427
- return yield* new MigrateDevDbSlotCollisionError({ slot, codeName, appliedName });
428
- }
429
- }
430
-});
431
-
406
export const runMigrateDevDb = Effect.fn("runMigrateDevDb")(function* (
407
input: RunMigrateDevDbInput,
408
options: RunMigrateDevDbOptions = {},
@@ -510,17 +484,6 @@ export const runMigrateDevDb = Effect.fn("runMigrateDevDb")(function* (
484
wrapPhase("migrate", snapshotPath),
485
);
486
513
- // Detect migration slot collisions before replacing the worktree database.
514
- yield* verifyMigrationSlots().pipe(
515
- Effect.provide(NodeSqliteClient.layer({ filename: snapshotPath })),
516
- Effect.catchTags({
517
- SqlError: (cause) =>
518
- Effect.fail(
519
- new MigrateDevDbPhaseError({ phase: "verify", databasePath: snapshotPath, cause }),
520
- ),
521
- }),
522
- );
523
-
487
yield* Console.log(
488
`Pruning to ${input.projects} projects, ${input.threadsPerProject} stopped threads each...`,
489
);