Open History to see the last commit
1import { assert, it } from "@effect/vitest";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import * as SqlClient from "effect/sql/SqlClient";
5
6import { migrationEntries, runMigrations } from "../Migrations.ts";
7import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
8
9const layer = it.layer(Layer.mergeAll(NodeSqliteClient.layer({ filename: ":memory:" })));
10
11layer("055_OrchestrationV2", (it) => {
12 it.effect("keeps released migrations contiguous", () =>
13 Effect.sync(() => {
14 assert.deepStrictEqual(
15 migrationEntries.map(([id]) => id),
16 Array.from({ length: 64 }, (_, index) => index + 1),
17 );
18 }),
19 );
20
21 it.effect("upgrades released schema 53 through the latest migrations", () =>
22 Effect.gen(function* () {
23 const sql = yield* SqlClient.SqlClient;
24 yield* runMigrations({ toMigrationInclusive: 53 });
25
26 const executed = yield* runMigrations();
27 assert.deepStrictEqual(executed, [
28 [54, "ProjectionThreadsAutoSettleDisabledAt"],
29 [55, "OrchestrationV2"],
30 [56, "RemoveRedundantProjectionIndexes"],
31 [57, "ScheduledTaskWebhooks"],
32 [58, "WebhookRelayDeliveries"],
33 [59, "McpAppModelContext"],
34 [60, "ThreadSnapshotWindowIndexes"],
35 [61, "PullRequestReviewGuides"],
36 [62, "ThreadFailureLookupIndex"],
37 [63, "DropUnusedV1Projections"],
38 [64, "CanonicalizeThreadPullRequestLinks"],
39 ]);
40 assert.deepStrictEqual(yield* runMigrations(), []);
41
42 const migrations = yield* sql<{
43 readonly migration_id: number;
44 readonly name: string;
45 }>`
46 SELECT migration_id, name
47 FROM effect_sql_migrations
48 WHERE migration_id >= 48
49 ORDER BY migration_id
50 `;
51 assert.deepStrictEqual(migrations, [
52 { migration_id: 48, name: "ProjectionThreadBranchPullRequest" },
53 { migration_id: 49, name: "ProjectionThreadsActiveOrderKey" },
54 { migration_id: 50, name: "ProjectionThreadPullRequests" },
55 { migration_id: 51, name: "ProjectionThreadMessageContext" },
56 { migration_id: 52, name: "ProjectionThreadTitleState" },
57 { migration_id: 53, name: "PullRequestFilesViewed" },
58 { migration_id: 54, name: "ProjectionThreadsAutoSettleDisabledAt" },
59 { migration_id: 55, name: "OrchestrationV2" },
60 { migration_id: 56, name: "RemoveRedundantProjectionIndexes" },
61 { migration_id: 57, name: "ScheduledTaskWebhooks" },
62 { migration_id: 58, name: "WebhookRelayDeliveries" },
63 { migration_id: 59, name: "McpAppModelContext" },
64 { migration_id: 60, name: "ThreadSnapshotWindowIndexes" },
65 { migration_id: 61, name: "PullRequestReviewGuides" },
66 { migration_id: 62, name: "ThreadFailureLookupIndex" },
67 { migration_id: 63, name: "DropUnusedV1Projections" },
68 { migration_id: 64, name: "CanonicalizeThreadPullRequestLinks" },
69 ]);
70
71 const tables = yield* sql<{ readonly name: string }>`
72 SELECT name
73 FROM sqlite_master
74 WHERE type = 'table'
75 AND name IN (
76 'orchestration_v2_projection_threads',
77 'orchestration_v2_projection_subagents',
78 'orchestration_v2_effect_outbox',
79 'orchestration_v2_turn_item_positions',
80 'orchestration_v2_projection_metadata',
81 'orchestration_v2_projection_provider_session_bindings',
82 'orchestration_v2_thread_launch_workflows',
83 'orchestration_v2_legacy_imports',
84 'scheduled_tasks'
85 )
86 ORDER BY name
87 `;
88 assert.deepStrictEqual(
89 tables.map(({ name }) => name),
90 [
91 "orchestration_v2_effect_outbox",
92 "orchestration_v2_legacy_imports",
93 "orchestration_v2_projection_metadata",
94 "orchestration_v2_projection_provider_session_bindings",
95 "orchestration_v2_projection_subagents",
96 "orchestration_v2_projection_threads",
97 "orchestration_v2_thread_launch_workflows",
98 "orchestration_v2_turn_item_positions",
99 "scheduled_tasks",
100 ],
101 );
102
103 const eventColumns = yield* sql<{ readonly name: string }>`
104 PRAGMA table_info(orchestration_events)
105 `;
106 const receiptColumns = yield* sql<{ readonly name: string }>`
107 PRAGMA table_info(orchestration_command_receipts)
108 `;
109 const threadColumns = yield* sql<{ readonly name: string }>`
110 PRAGMA table_info(orchestration_v2_projection_threads)
111 `;
112 const subagentColumns = yield* sql<{ readonly name: string }>`
113 PRAGMA table_info(orchestration_v2_projection_subagents)
114 `;
115 assert.ok(eventColumns.some(({ name }) => name === "application_event_version"));
116 assert.ok(receiptColumns.some(({ name }) => name === "command_type"));
117 assert.ok(threadColumns.some(({ name }) => name === "provider_instance_id"));
118 assert.ok(subagentColumns.some(({ name }) => name === "driver"));
119 assert.ok(subagentColumns.some(({ name }) => name === "provider_instance_id"));
120
121 const indexes = yield* sql<{ readonly name: string }>`
122 SELECT name
123 FROM sqlite_master
124 WHERE type = 'index'
125 AND name IN (
126 'idx_orchestration_events_application_high_water',
127 'orchestration_events_v2_created_threads_idx',
128 'orchestration_v2_projection_turn_items_shell_pending_idx'
129 )
130 ORDER BY name
131 `;
132 assert.deepStrictEqual(
133 indexes.map(({ name }) => name),
134 [
135 "idx_orchestration_events_application_high_water",
136 "orchestration_events_v2_created_threads_idx",
137 "orchestration_v2_projection_turn_items_shell_pending_idx",
138 ],
139 );
140 }),
141 );
142});