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, 04:45 UTC
| 1 | /** |
| 2 | * ClickHouse adapter for the shared Effect SQL migration runner. |
| 3 | * |
| 4 | * This module re-exports the common `Migrator` loaders and error types, then |
| 5 | * provides `run` and `layer` helpers that apply ordered migrations through the |
| 6 | * current ClickHouse `SqlClient`. `run` returns the applied migration IDs and |
| 7 | * names, while `layer` runs the migrations during layer construction and |
| 8 | * provides no services. |
| 9 | * |
| 10 | * @stability unstable |
| 11 | * @since 4.0.0 |
| 12 | */ |
| 13 | import * as Effect from "effect/Effect" |
| 14 | import * as Layer from "effect/Layer" |
| 15 | import * as Migrator from "effect/sql/Migrator" |
| 16 | import type * as Client from "effect/sql/SqlClient" |
| 17 | import type { SqlError } from "effect/sql/SqlError" |
| 18 | import { ClientMethod } from "./ClickhouseClient.ts" |
| 19 | |
| 20 | /** |
| 21 | * @since 4.0.0 |
| 22 | */ |
| 23 | export * from "effect/sql/Migrator" |
| 24 | export { |
| 25 | /** |
| 26 | * @stability unstable |
| 27 | * @category loaders |
| 28 | * @since 4.0.0 |
| 29 | */ |
| 30 | fromFileSystem |
| 31 | } from "effect/sql/MigratorFileSystem" |
| 32 | |
| 33 | /** |
| 34 | * Runs SQL migrations for ClickHouse using the supplied migrator options and |
| 35 | * returns the applied migration IDs and names. |
| 36 | * |
| 37 | * @stability unstable |
| 38 | * @category running |
| 39 | * @since 4.0.0 |
| 40 | */ |
| 41 | export const run: <R2 = never>( |
| 42 | { loader, schemaDirectory, table }: Migrator.MigratorOptions<R2> |
| 43 | ) => Effect.Effect< |
| 44 | ReadonlyArray<readonly [id: number, name: string]>, |
| 45 | Migrator.MigrationError | SqlError, |
| 46 | Client.SqlClient | R2 |
| 47 | > = Migrator.make({ |
| 48 | transformWrites: (effect) => Effect.provideService(effect, ClientMethod, "command") |
| 49 | }) |
| 50 | |
| 51 | /** |
| 52 | * Creates a layer that runs the configured ClickHouse migrations during layer |
| 53 | * construction and provides no services. |
| 54 | * |
| 55 | * @stability unstable |
| 56 | * @category layers |
| 57 | * @since 4.0.0 |
| 58 | */ |
| 59 | export const layer = <R>( |
| 60 | options: Migrator.MigratorOptions<R> |
| 61 | ): Layer.Layer< |
| 62 | never, |
| 63 | Migrator.MigrationError | SqlError, |
| 64 | Client.SqlClient | R |
| 65 | > => Layer.effectDiscard(run(options)) |