| 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("051_ProjectionThreadMessageContext", (it) => { |
| 12 | it.effect("accepts context added by an earlier development migration", () => |
| 13 | Effect.gen(function* () { |
| 14 | const sql = yield* SqlClient.SqlClient; |
| 15 | |
| 16 | yield* runMigrations({ toMigrationInclusive: 50 }); |
| 17 | yield* sql` |
| 18 | ALTER TABLE projection_thread_messages |
| 19 | ADD COLUMN context_json TEXT |
| 20 | `; |
| 21 | |
| 22 | yield* runMigrations({ toMigrationInclusive: 51 }); |
| 23 | |
| 24 | const columns = yield* sql<{ readonly name: string; readonly notnull: number }>` |
| 25 | PRAGMA table_info(projection_thread_messages) |
| 26 | `; |
| 27 | const context = columns.find((column) => column.name === "context_json"); |
| 28 | const migrations = yield* sql<{ readonly migration_id: number }>` |
| 29 | SELECT migration_id |
| 30 | FROM effect_sql_migrations |
| 31 | WHERE migration_id = 51 |
| 32 | `; |
| 33 | |
| 34 | assert.equal(context?.name, "context_json"); |
| 35 | assert.equal(context?.notnull, 0); |
| 36 | assert.equal(migrations.length, 1); |
| 37 | }), |
| 38 | ); |
| 39 | }); |