| 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 | */ |
| 12 | import type * as Effect from "effect/Effect" |
| 13 | import * as Layer from "effect/Layer" |
| 14 | import * as Migrator from "effect/sql/Migrator" |
| 15 | import type * as Client from "effect/sql/SqlClient" |
| 16 | import type { SqlError } from "effect/sql/SqlError" |
| 17 | |
| 18 | /** |
| 19 | * @since 4.0.0 |
| 20 | */ |
| 21 | export * 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 | */ |
| 29 | export 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 | */ |
| 43 | export const layer = <R>( |
| 44 | options: Migrator.MigratorOptions<R> |
| 45 | ): Layer.Layer<never, SqlError | Migrator.MigrationError, Client.SqlClient | R> => Layer.effectDiscard(run(options)) |