1/**
2 * Utilities for applying Effect SQL migrations to Microsoft SQL Server.
3 *
4 * This module re-exports the shared `Migrator` loaders and error types, then
5 * provides `run` and `layer` helpers for applying ordered migrations through
6 * the current SQL Server `SqlClient`. `run` returns the applied migration IDs
7 * and names, while `layer` runs 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 using the configured `SqlClient`, returning the migrations that were applied.
25 *
26 * @category running
27 * @since 4.0.0
28 */
29export const run: <R>(
30 options: Migrator.MigratorOptions<R>
31) => Effect.Effect<
32 ReadonlyArray<readonly [id: number, name: string]>,
33 SqlError | Migrator.MigrationError,
34 Client.SqlClient | R
35> = Migrator.make({})
36
37/**
38 * Creates a layer that runs the configured SQL migrations during layer construction.
39 *
40 * @category layers
41 * @since 4.0.0
42 */
43export const layer = <R>(
44 options: Migrator.MigratorOptions<R>
45): Layer.Layer<never, SqlError | Migrator.MigrationError, Client.SqlClient | R> => Layer.effectDiscard(run(options))