Open History to see the last commit
1/**
2 * Runs database migrations for PGlite projects that use Effect SQL.
3 *
4 * This module re-exports the shared migration loaders and errors, then provides
5 * `run` and `layer` helpers that apply pending migration files with the current
6 * `SqlClient`. It does not require a separate PGlite service; the active SQL
7 * client supplies the database connection.
8 *
9 * @stability unstable
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"
22export {
23 /**
24 * @stability unstable
25 * @category loaders
26 * @since 4.0.0
27 */
28 fromFileSystem
29} from "effect/sql/MigratorFileSystem"
30
31/**
32 * Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
33 *
34 * @stability unstable
35 * @category running
36 * @since 4.0.0
37 */
38export const run: <R2 = never>(
39 options: Migrator.MigratorOptions<R2>
40) => Effect.Effect<
41 ReadonlyArray<readonly [id: number, name: string]>,
42 Migrator.MigrationError | SqlError,
43 Client.SqlClient | R2
44> = Migrator.make({})
45
46/**
47 * Creates a layer that runs the configured SQL migrations during layer construction.
48 *
49 * @stability unstable
50 * @category layers
51 * @since 4.0.0
52 */
53export const layer = <R>(
54 options: Migrator.MigratorOptions<R>
55): Layer.Layer<never, Migrator.MigrationError | SqlError, Client.SqlClient | R> => Layer.effectDiscard(run(options))