| 1 | import { assert, it } from "@effect/vitest"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import * as SqlClient from "effect/sql/SqlClient"; |
| 5 | |
| 6 | import { runMigrations } from "../Migrations.ts"; |
| 7 | import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient"; |
| 8 | |
| 9 | const layer = it.layer(Layer.mergeAll(NodeSqliteClient.layer({ filename: ":memory:" }))); |
| 10 | |
| 11 | layer("027_028_ProviderInstanceIdColumns", (it) => { |
| 12 | it.effect("continues when provider_session_runtime was partially migrated", () => |
| 13 | Effect.gen(function* () { |
| 14 | const sql = yield* SqlClient.SqlClient; |
| 15 | |
| 16 | yield* runMigrations({ toMigrationInclusive: 26 }); |
| 17 | yield* sql` |
| 18 | ALTER TABLE provider_session_runtime |
| 19 | ADD COLUMN provider_instance_id TEXT |
| 20 | `; |
| 21 | |
| 22 | yield* runMigrations({ toMigrationInclusive: 28 }); |
| 23 | |
| 24 | const migrations = yield* sql<{ |
| 25 | readonly migration_id: number; |
| 26 | readonly name: string; |
| 27 | }>` |
| 28 | SELECT migration_id, name |
| 29 | FROM effect_sql_migrations |
| 30 | WHERE migration_id IN (27, 28) |
| 31 | ORDER BY migration_id |
| 32 | `; |
| 33 | assert.deepStrictEqual(migrations, [ |
| 34 | { |
| 35 | migration_id: 27, |
| 36 | name: "ProviderSessionRuntimeInstanceId", |
| 37 | }, |
| 38 | { |
| 39 | migration_id: 28, |
| 40 | name: "ProjectionThreadSessionInstanceId", |
| 41 | }, |
| 42 | ]); |
| 43 | |
| 44 | const providerSessionColumns = yield* sql<{ readonly name: string }>` |
| 45 | PRAGMA table_info(provider_session_runtime) |
| 46 | `; |
| 47 | assert.ok(providerSessionColumns.some((column) => column.name === "provider_instance_id")); |
| 48 | |
| 49 | const projectionThreadSessionColumns = yield* sql<{ readonly name: string }>` |
| 50 | PRAGMA table_info(projection_thread_sessions) |
| 51 | `; |
| 52 | assert.ok( |
| 53 | projectionThreadSessionColumns.some((column) => column.name === "provider_instance_id"), |
| 54 | ); |
| 55 | |
| 56 | const providerSessionIndexes = yield* sql<{ readonly name: string }>` |
| 57 | PRAGMA index_list(provider_session_runtime) |
| 58 | `; |
| 59 | assert.ok( |
| 60 | providerSessionIndexes.some( |
| 61 | (index) => index.name === "idx_provider_session_runtime_instance", |
| 62 | ), |
| 63 | ); |
| 64 | |
| 65 | const projectionThreadSessionIndexes = yield* sql<{ readonly name: string }>` |
| 66 | PRAGMA index_list(projection_thread_sessions) |
| 67 | `; |
| 68 | assert.ok( |
| 69 | projectionThreadSessionIndexes.some( |
| 70 | (index) => index.name === "idx_projection_thread_sessions_instance", |
| 71 | ), |
| 72 | ); |
| 73 | }), |
| 74 | ); |
| 75 | }); |