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 * @since 4.0.0
11 */
12import type * as Effect from "effect/Effect"
13import * as Layer from "effect/Layer"
14import * as Migrator from "effect/sql/Migrator"
15import type * as Client from "effect/sql/SqlClient"
16import type { SqlError } from "effect/sql/SqlError"
17
18/**
19 * @since 4.0.0
20 */
21export * from "effect/sql/Migrator"
22
23/**
24 * Runs SQL migrations for ClickHouse using the supplied migrator options and
25 * returns the applied migration IDs and names.
26 *
27 * @category running
28 * @since 4.0.0
29 */
30export const run: <R2 = never>(
31 { loader, schemaDirectory, table }: Migrator.MigratorOptions<R2>
32) => Effect.Effect<
33 ReadonlyArray<readonly [id: number, name: string]>,
34 Migrator.MigrationError | SqlError,
35 Client.SqlClient | R2
36> = Migrator.make({})
37
38/**
39 * Creates a layer that runs the configured ClickHouse migrations during layer
40 * construction and provides no services.
41 *
42 * @category layers
43 * @since 4.0.0
44 */
45export const layer = <R>(
46 options: Migrator.MigratorOptions<R>
47): Layer.Layer<
48 never,
49 Migrator.MigrationError | SqlError,
50 Client.SqlClient | R
51> => Layer.effectDiscard(run(options))