@effect/sql-pg 4.0.0-beta.8 → 4.0.0-beta.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/PgClient.d.ts +118 -37
- package/dist/PgClient.d.ts.map +1 -1
- package/dist/PgClient.js +415 -195
- package/dist/PgClient.js.map +1 -1
- package/dist/PgMigrator.d.ts +18 -6
- package/dist/PgMigrator.d.ts.map +1 -1
- package/dist/PgMigrator.js +20 -6
- package/dist/PgMigrator.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/package.json +9 -9
- package/src/PgClient.ts +622 -268
- package/src/PgMigrator.ts +20 -7
- package/src/index.ts +3 -3
package/src/PgMigrator.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Runs database migrations for PostgreSQL projects that use Effect SQL.
|
|
3
|
+
*
|
|
4
|
+
* This module reuses the shared SQL migrator and connects it to PostgreSQL. It
|
|
5
|
+
* exposes the common migration helpers and adds `run` and `layer` functions
|
|
6
|
+
* that apply pending migration files with the current SQL client. When schema
|
|
7
|
+
* dumps are requested, it uses `pg_dump` and the usual process and filesystem
|
|
8
|
+
* services.
|
|
9
|
+
*
|
|
10
|
+
* @since 4.0.0
|
|
3
11
|
*/
|
|
4
12
|
import * as Effect from "effect/Effect"
|
|
5
13
|
import * as FileSystem from "effect/FileSystem"
|
|
@@ -7,20 +15,22 @@ import * as Layer from "effect/Layer"
|
|
|
7
15
|
import * as Path from "effect/Path"
|
|
8
16
|
import * as Redacted from "effect/Redacted"
|
|
9
17
|
import * as ChildProcess from "effect/unstable/process/ChildProcess"
|
|
10
|
-
import
|
|
18
|
+
import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner"
|
|
11
19
|
import * as Migrator from "effect/unstable/sql/Migrator"
|
|
12
20
|
import type { SqlClient } from "effect/unstable/sql/SqlClient"
|
|
13
21
|
import type { SqlError } from "effect/unstable/sql/SqlError"
|
|
14
22
|
import { PgClient } from "./PgClient.ts"
|
|
15
23
|
|
|
16
24
|
/**
|
|
17
|
-
* @since
|
|
25
|
+
* @since 4.0.0
|
|
18
26
|
*/
|
|
19
27
|
export * from "effect/unstable/sql/Migrator"
|
|
20
28
|
|
|
21
29
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
30
|
+
* Runs PostgreSQL SQL migrations using the configured clients. Schema dumps use `pg_dump` and require child process, filesystem, and path services.
|
|
31
|
+
*
|
|
32
|
+
* @category constructors
|
|
33
|
+
* @since 4.0.0
|
|
24
34
|
*/
|
|
25
35
|
export const run: <R2 = never>(
|
|
26
36
|
options: Migrator.MigratorOptions<R2>
|
|
@@ -38,6 +48,7 @@ export const run: <R2 = never>(
|
|
|
38
48
|
const pgDump = (args: Array<string>) =>
|
|
39
49
|
Effect.gen(function*() {
|
|
40
50
|
const sql = yield* PgClient
|
|
51
|
+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner
|
|
41
52
|
const dump = yield* ChildProcess.make("pg_dump", [...args, "--no-owner", "--no-privileges"], {
|
|
42
53
|
env: {
|
|
43
54
|
PATH: (globalThis as any).process?.env.PATH,
|
|
@@ -50,7 +61,7 @@ export const run: <R2 = never>(
|
|
|
50
61
|
PGDATABASE: sql.config.database,
|
|
51
62
|
PGSSLMODE: sql.config.ssl ? "require" : "prefer"
|
|
52
63
|
}
|
|
53
|
-
}).pipe(
|
|
64
|
+
}).pipe(spawner.string)
|
|
54
65
|
|
|
55
66
|
return dump.replace(/^--.*$/gm, "")
|
|
56
67
|
.replace(/^SET .*$/gm, "")
|
|
@@ -90,8 +101,10 @@ export const run: <R2 = never>(
|
|
|
90
101
|
})
|
|
91
102
|
|
|
92
103
|
/**
|
|
104
|
+
* Creates a layer that runs PostgreSQL migrations during layer construction, including `pg_dump`-based schema dump support when requested.
|
|
105
|
+
*
|
|
93
106
|
* @category layers
|
|
94
|
-
* @since
|
|
107
|
+
* @since 4.0.0
|
|
95
108
|
*/
|
|
96
109
|
export const layer = <R>(
|
|
97
110
|
options: Migrator.MigratorOptions<R>
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @since
|
|
2
|
+
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
// @barrel: Auto-generated exports. Do not edit manually.
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* @since
|
|
8
|
+
* @since 4.0.0
|
|
9
9
|
*/
|
|
10
10
|
export * as PgClient from "./PgClient.ts"
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* @since
|
|
13
|
+
* @since 4.0.0
|
|
14
14
|
*/
|
|
15
15
|
export * as PgMigrator from "./PgMigrator.ts"
|