@devries-cameron20 / t3code Mirror · read-only / commits / 8af1fc110e
Fork 0

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 21, 21:00 UTC

fix(dev): import seed snapshots with peer preview migrations (#25058)

Julius Marminge committed Nov 11, 2026 at 16:09 UTC 8af1fc110e909a13a26a7c31b6f91e2a1f421a46
2 files changed +100 -5
apps/server/scripts/migrate-dev-db.test.ts
+72 -5
@@ -14,8 +14,14 @@ const withDatabase = <A, E>(
14 effect: Effect.Effect<A, E, SqlClient.SqlClient>,
15 ) => effect.pipe(Effect.provide(NodeSqliteClient.layer({ filename: databasePath })));
16
17 +const insertPeerLink = (sql: SqlClient.SqlClient) => sql`INSERT INTO peer_environment_links
18 + (environment_id, secret_name, label, urls_json, access, linked_at, expires_at)
19 + VALUES ('environment-box', 'peer-link-box', 'Box', '["https://box.example"]', 'auto',
20 + '2026-08-01', '2027-08-01')`;
21 +
22 const createFixtureSource = Effect.fn("createMigrateDevDbFixtureSource")(function* (
23 baseDir: string,
24 + toMigrationInclusive?: number,
25 ) {
26 const fs = yield* FileSystem.FileSystem;
27 const path = yield* Path.Path;
@@ -26,7 +32,7 @@ const createFixtureSource = Effect.fn("createMigrateDevDbFixtureSource")(functio
32 databasePath,
33 Effect.gen(function* () {
34 const sql = yield* SqlClient.SqlClient;
29 - yield* runMigrations();
35 + yield* runMigrations({ toMigrationInclusive });
36
37 yield* sql`INSERT INTO projection_projects
38 (project_id, title, workspace_root, scripts_json, created_at, updated_at, deleted_at)
@@ -120,10 +126,7 @@ const createFixtureSource = Effect.fn("createMigrateDevDbFixtureSource")(functio
126 VALUES ('delivery-1', 'task-1', 'key-1', 1900000000000, '{}', '{}', '[]')`;
127 yield* sql`INSERT INTO auth_sessions (session_id, subject, scopes, method, issued_at, expires_at)
128 VALUES ('session-1', 'user', '[]', 'pairing', '2026-08-01', '2027-08-01')`;
123 - yield* sql`INSERT INTO peer_environment_links
124 - (environment_id, secret_name, label, urls_json, access, linked_at, expires_at)
125 - VALUES ('environment-box', 'peer-link-box', 'Box', '["https://box.example"]', 'auto',
126 - '2026-08-01', '2027-08-01')`;
129 + if (toMigrationInclusive === undefined) yield* insertPeerLink(sql);
130 }),
131 );
132 return databasePath;
@@ -355,6 +358,70 @@ it.layer(NodeServices.layer)("migrate-dev-db", (it) => {
358 }),
359 );
360
361 + it.effect("imports a dev seed whose ids after 67 came from the peer links branch", () =>
362 + Effect.gen(function* () {
363 + const fs = yield* FileSystem.FileSystem;
364 + const sourceDir = yield* fs.makeTempDirectoryScoped({ prefix: "migrate-dev-db-peer-" });
365 + const destDir = yield* fs.makeTempDirectoryScoped({ prefix: "migrate-dev-db-peer-dest-" });
366 + const source = yield* createFixtureSource(sourceDir, 67);
367 + // Mirrors a real ~/.t3 seed written by a build whose 68-70 differ from main's.
368 + yield* withDatabase(
369 + source,
370 + Effect.gen(function* () {
371 + const sql = yield* SqlClient.SqlClient;
372 + yield* sql`CREATE TABLE peer_environment_links (
373 + environment_id TEXT PRIMARY KEY,
374 + secret_name TEXT NOT NULL,
375 + label TEXT NOT NULL,
376 + urls_json TEXT NOT NULL,
377 + access TEXT NOT NULL,
378 + linked_at TEXT NOT NULL,
379 + expires_at TEXT NOT NULL,
380 + last_reached_at TEXT,
381 + last_error TEXT,
382 + fenced INTEGER NOT NULL DEFAULT 0)`;
383 + yield* sql`CREATE INDEX orchestration_v2_projection_turn_items_waiting_link_idx
384 + ON orchestration_v2_projection_turn_items(thread_id, updated_at DESC, turn_item_id DESC)
385 + WHERE type = 'link_request' AND status = 'waiting'`;
386 + yield* insertPeerLink(sql);
387 + yield* sql`INSERT INTO effect_sql_migrations (migration_id, name) VALUES
388 + (68, 'PeerLinks'), (69, 'PeerLinkFence'), (70, 'WaitingLinkRequestIndex')`;
389 + }),
390 + );
391 +
392 + const result = yield* runMigrateDevDb(
393 + { baseDir: destDir, source, projects: 5, threadsPerProject: 2 },
394 + { sharedHome: sourceDir },
395 + );
396 +
397 + const imported = yield* withDatabase(
398 + result.databasePath,
399 + Effect.gen(function* () {
400 + const sql = yield* SqlClient.SqlClient;
401 + const threads = yield* sql<{ thread_id: string }>`
402 + SELECT thread_id FROM orchestration_v2_projection_threads ORDER BY thread_id`;
403 + const schema = yield* sql<{ name: string }>`
404 + SELECT name FROM sqlite_master WHERE name IN (
405 + 'orchestration_v2_projection_turn_items_stop_request_idx',
406 + 'orchestration_v2_message_search')
407 + ORDER BY name`;
408 + return { threads, schema };
409 + }),
410 + );
411 + assert.deepStrictEqual(
412 + imported.threads.map((row) => row.thread_id),
413 + ["fork-thread", "settled-thread", "stopped-thread"],
414 + );
415 + assert.deepStrictEqual(
416 + imported.schema.map((row) => row.name),
417 + [
418 + "orchestration_v2_message_search",
419 + "orchestration_v2_projection_turn_items_stop_request_idx",
420 + ],
421 + );
422 + }),
423 + );
424 +
425 it.effect("refuses while a dev server holds the destination", () =>
426 Effect.gen(function* () {
427 const fs = yield* FileSystem.FileSystem;
apps/server/scripts/migrate-dev-db.ts
+28
@@ -410,6 +410,33 @@ const pruneSnapshot = Effect.fn("pruneDevDbSnapshot")(function* (input: RunMigra
410 };
411 });
412
413 +// Peer links preview builds recorded 68-70 before main took those slots for other migrations.
414 +// A snapshot with exactly that history drops the preview's schema so main's 68+ can run.
415 +const PEER_LINKS_PREVIEW_HISTORY = [
416 + "68:PeerLinks",
417 + "69:PeerLinkFence",
418 + "70:WaitingLinkRequestIndex",
419 +];
420 +
421 +const forgetPeerLinksPreviewHistory = Effect.fn("forgetPeerLinksPreviewHistory")(function* () {
422 + const sql = yield* SqlClient.SqlClient;
423 + const tables = yield* sql`
424 + SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'effect_sql_migrations'`;
425 + if (tables.length === 0) return;
426 + const tail = yield* sql<{ migration_id: number; name: string }>`
427 + SELECT migration_id, name FROM effect_sql_migrations WHERE migration_id >= 68
428 + ORDER BY migration_id`;
429 + const history = tail.map((row) => `${row.migration_id}:${row.name}`);
430 + if (history.join() !== PEER_LINKS_PREVIEW_HISTORY.join()) return;
431 + yield* sql.withTransaction(
432 + Effect.gen(function* () {
433 + yield* sql`DROP INDEX IF EXISTS orchestration_v2_projection_turn_items_waiting_link_idx`;
434 + yield* sql`DROP TABLE IF EXISTS peer_environment_links`;
435 + yield* sql`DELETE FROM effect_sql_migrations WHERE migration_id >= 68`;
436 + }),
437 + );
438 +});
439 +
440 export const runMigrateDevDb = Effect.fn("runMigrateDevDb")(function* (
441 input: RunMigrateDevDbInput,
442 options: RunMigrateDevDbOptions = {},
@@ -485,6 +512,7 @@ export const runMigrateDevDb = Effect.fn("runMigrateDevDb")(function* (
512 const executed = yield* Effect.gen(function* () {
513 const sql = yield* SqlClient.SqlClient;
514 yield* sql.unsafe("PRAGMA foreign_keys = ON").unprepared;
515 + yield* forgetPeerLinksPreviewHistory();
516 return yield* runMigrations();
517 }).pipe(
518 Effect.provide(NodeSqliteClient.layer({ filename: snapshotPath })),