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/unstable/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: 56 }, (_, 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 ]);
32 assert.deepStrictEqual(yield* runMigrations(), []);
33
34 const migrations = yield* sql<{
35 readonly migration_id: number;
36 readonly name: string;
37 }>`
38 SELECT migration_id, name
39 FROM effect_sql_migrations
40 WHERE migration_id >= 48
41 ORDER BY migration_id
42 `;
43 assert.deepStrictEqual(migrations, [
44 { migration_id: 48, name: "ProjectionThreadBranchPullRequest" },
45 { migration_id: 49, name: "ProjectionThreadsActiveOrderKey" },
46 { migration_id: 50, name: "ProjectionThreadPullRequests" },
47 { migration_id: 51, name: "ProjectionThreadMessageContext" },
48 { migration_id: 52, name: "ProjectionThreadTitleState" },
49 { migration_id: 53, name: "PullRequestFilesViewed" },
50 { migration_id: 54, name: "ProjectionThreadsAutoSettleDisabledAt" },
51 { migration_id: 55, name: "OrchestrationV2" },
52 { migration_id: 56, name: "RemoveRedundantProjectionIndexes" },
53 ]);
54
55 const tables = yield* sql<{ readonly name: string }>`
56 SELECT name
57 FROM sqlite_master
58 WHERE type = 'table'
59 AND name IN (
60 'orchestration_v2_projection_threads',
61 'orchestration_v2_projection_subagents',
62 'orchestration_v2_effect_outbox',
63 'orchestration_v2_turn_item_positions',
64 'orchestration_v2_projection_metadata',
65 'orchestration_v2_projection_provider_session_bindings',
66 'orchestration_v2_thread_launch_workflows',
67 'orchestration_v2_legacy_imports',
68 'scheduled_tasks'
69 )
70 ORDER BY name
71 `;
72 assert.deepStrictEqual(
73 tables.map(({ name }) => name),
74 [
75 "orchestration_v2_effect_outbox",
76 "orchestration_v2_legacy_imports",
77 "orchestration_v2_projection_metadata",
78 "orchestration_v2_projection_provider_session_bindings",
79 "orchestration_v2_projection_subagents",
80 "orchestration_v2_projection_threads",
81 "orchestration_v2_thread_launch_workflows",
82 "orchestration_v2_turn_item_positions",
83 "scheduled_tasks",
84 ],
85 );
86
87 const eventColumns = yield* sql<{ readonly name: string }>`
88 PRAGMA table_info(orchestration_events)
89 `;
90 const receiptColumns = yield* sql<{ readonly name: string }>`
91 PRAGMA table_info(orchestration_command_receipts)
92 `;
93 const threadColumns = yield* sql<{ readonly name: string }>`
94 PRAGMA table_info(orchestration_v2_projection_threads)
95 `;
96 const subagentColumns = yield* sql<{ readonly name: string }>`
97 PRAGMA table_info(orchestration_v2_projection_subagents)
98 `;
99 assert.ok(eventColumns.some(({ name }) => name === "application_event_version"));
100 assert.ok(receiptColumns.some(({ name }) => name === "command_type"));
101 assert.ok(threadColumns.some(({ name }) => name === "provider_instance_id"));
102 assert.ok(subagentColumns.some(({ name }) => name === "driver"));
103 assert.ok(subagentColumns.some(({ name }) => name === "provider_instance_id"));
104
105 const indexes = yield* sql<{ readonly name: string }>`
106 SELECT name
107 FROM sqlite_master
108 WHERE type = 'index'
109 AND name IN (
110 'idx_orchestration_events_application_high_water',
111 'orchestration_events_v2_created_threads_idx',
112 'orchestration_v2_projection_turn_items_shell_pending_idx'
113 )
114 ORDER BY name
115 `;
116 assert.deepStrictEqual(
117 indexes.map(({ name }) => name),
118 [
119 "idx_orchestration_events_application_high_water",
120 "orchestration_events_v2_created_threads_idx",
121 "orchestration_v2_projection_turn_items_shell_pending_idx",
122 ],
123 );
124 }),
125 );
126});