@effect/sql-pg 4.0.0-beta.7 → 4.0.0-beta.8
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/dist/PgMigrator.d.ts +8 -4
- package/dist/PgMigrator.d.ts.map +1 -1
- package/dist/PgMigrator.js +47 -56
- package/dist/PgMigrator.js.map +1 -1
- package/package.json +3 -3
- package/src/PgMigrator.ts +73 -60
package/dist/PgMigrator.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
-
import
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as FileSystem from "effect/FileSystem";
|
|
5
6
|
import * as Layer from "effect/Layer";
|
|
7
|
+
import * as Path from "effect/Path";
|
|
8
|
+
import type * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner";
|
|
6
9
|
import * as Migrator from "effect/unstable/sql/Migrator";
|
|
7
|
-
import type
|
|
10
|
+
import type { SqlClient } from "effect/unstable/sql/SqlClient";
|
|
8
11
|
import type { SqlError } from "effect/unstable/sql/SqlError";
|
|
12
|
+
import { PgClient } from "./PgClient.ts";
|
|
9
13
|
/**
|
|
10
14
|
* @since 1.0.0
|
|
11
15
|
*/
|
|
@@ -14,10 +18,10 @@ export * from "effect/unstable/sql/Migrator";
|
|
|
14
18
|
* @category constructor
|
|
15
19
|
* @since 1.0.0
|
|
16
20
|
*/
|
|
17
|
-
export declare const run: <R2 = never>(options: Migrator.MigratorOptions<R2>) => Effect.Effect<ReadonlyArray<readonly [id: number, name: string]>, Migrator.MigrationError | SqlError,
|
|
21
|
+
export declare const run: <R2 = never>(options: Migrator.MigratorOptions<R2>) => Effect.Effect<ReadonlyArray<readonly [id: number, name: string]>, Migrator.MigrationError | SqlError, SqlClient | PgClient | ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem | Path.Path | R2>;
|
|
18
22
|
/**
|
|
19
23
|
* @category layers
|
|
20
24
|
* @since 1.0.0
|
|
21
25
|
*/
|
|
22
|
-
export declare const layer: <R>(options: Migrator.MigratorOptions<R>) => Layer.Layer<never, Migrator.MigrationError | SqlError,
|
|
26
|
+
export declare const layer: <R>(options: Migrator.MigratorOptions<R>) => Layer.Layer<never, Migrator.MigrationError | SqlError, SqlClient | PgClient | ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem | Path.Path | R>;
|
|
23
27
|
//# sourceMappingURL=PgMigrator.d.ts.map
|
package/dist/PgMigrator.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PgMigrator.d.ts","sourceRoot":"","sources":["../src/PgMigrator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"PgMigrator.d.ts","sourceRoot":"","sources":["../src/PgMigrator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAA;AAGnC,OAAO,KAAK,KAAK,mBAAmB,MAAM,6CAA6C,CAAA;AACvF,OAAO,KAAK,QAAQ,MAAM,8BAA8B,CAAA;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC;;GAEG;AACH,cAAc,8BAA8B,CAAA;AAE5C;;;GAGG;AACH,eAAO,MAAM,GAAG,EAAE,CAAC,EAAE,GAAG,KAAK,EAC3B,OAAO,EAAE,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,KAClC,MAAM,CAAC,MAAM,CAChB,aAAa,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,EAClD,QAAQ,CAAC,cAAc,GAAG,QAAQ,EAChC,SAAS,GACT,QAAQ,GACR,mBAAmB,CAAC,mBAAmB,GACvC,UAAU,CAAC,UAAU,GACrB,IAAI,CAAC,IAAI,GACT,EAAE,CAuDJ,CAAA;AAEF;;;GAGG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,EACrB,SAAS,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,KACnC,KAAK,CAAC,KAAK,CACZ,KAAK,EACL,QAAQ,CAAC,cAAc,GAAG,QAAQ,EAChC,SAAS,GACT,QAAQ,GACR,mBAAmB,CAAC,mBAAmB,GACvC,UAAU,CAAC,UAAU,GACrB,IAAI,CAAC,IAAI,GACT,CAAC,CACiC,CAAA"}
|
package/dist/PgMigrator.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as FileSystem from "effect/FileSystem";
|
|
1
6
|
import * as Layer from "effect/Layer";
|
|
7
|
+
import * as Path from "effect/Path";
|
|
8
|
+
import * as Redacted from "effect/Redacted";
|
|
9
|
+
import * as ChildProcess from "effect/unstable/process/ChildProcess";
|
|
2
10
|
import * as Migrator from "effect/unstable/sql/Migrator";
|
|
11
|
+
import { PgClient } from "./PgClient.js";
|
|
3
12
|
/**
|
|
4
13
|
* @since 1.0.0
|
|
5
14
|
*/
|
|
@@ -9,62 +18,44 @@ export * from "effect/unstable/sql/Migrator";
|
|
|
9
18
|
* @since 1.0.0
|
|
10
19
|
*/
|
|
11
20
|
export const run = /*#__PURE__*/Migrator.make({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
// const pgDumpAll = Effect.map(
|
|
51
|
-
// Effect.all([pgDumpSchema, pgDumpMigrations], { concurrency: 2 }),
|
|
52
|
-
// ([schema, migrations]) => schema + "\n\n" + migrations
|
|
53
|
-
// )
|
|
54
|
-
//
|
|
55
|
-
// const pgDumpFile = (path: string) =>
|
|
56
|
-
// Effect.gen(function*() {
|
|
57
|
-
// const fs = yield* FileSystem
|
|
58
|
-
// const path_ = yield* Path
|
|
59
|
-
// const dump = yield* pgDumpAll
|
|
60
|
-
// yield* fs.makeDirectory(path_.dirname(path), { recursive: true })
|
|
61
|
-
// yield* fs.writeFileString(path, dump)
|
|
62
|
-
// }).pipe(
|
|
63
|
-
// Effect.mapError((error) => new Migrator.MigrationError({ kind: "Failed", message: error.message }))
|
|
64
|
-
// )
|
|
65
|
-
//
|
|
66
|
-
// return pgDumpFile(path)
|
|
67
|
-
// }
|
|
21
|
+
dumpSchema(path, table) {
|
|
22
|
+
const pgDump = args => Effect.gen(function* () {
|
|
23
|
+
const sql = yield* PgClient;
|
|
24
|
+
const dump = yield* ChildProcess.make("pg_dump", [...args, "--no-owner", "--no-privileges"], {
|
|
25
|
+
env: {
|
|
26
|
+
PATH: globalThis.process?.env.PATH,
|
|
27
|
+
PGHOST: sql.config.host,
|
|
28
|
+
PGPORT: sql.config.port?.toString(),
|
|
29
|
+
PGUSER: sql.config.username,
|
|
30
|
+
PGPASSWORD: sql.config.password ? Redacted.value(sql.config.password) : undefined,
|
|
31
|
+
PGDATABASE: sql.config.database,
|
|
32
|
+
PGSSLMODE: sql.config.ssl ? "require" : "prefer"
|
|
33
|
+
}
|
|
34
|
+
}).pipe(ChildProcess.string);
|
|
35
|
+
return dump.replace(/^--.*$/gm, "").replace(/^SET .*$/gm, "").replace(/^SELECT pg_catalog\..*$/gm, "").replace(/\n{2,}/gm, "\n\n").trim();
|
|
36
|
+
}).pipe(Effect.mapError(error => new Migrator.MigrationError({
|
|
37
|
+
kind: "Failed",
|
|
38
|
+
message: error.message
|
|
39
|
+
})));
|
|
40
|
+
const pgDumpSchema = pgDump(["--schema-only"]);
|
|
41
|
+
const pgDumpMigrations = pgDump(["--column-inserts", "--data-only", `--table=${table}`]);
|
|
42
|
+
const pgDumpAll = Effect.map(Effect.all([pgDumpSchema, pgDumpMigrations], {
|
|
43
|
+
concurrency: 2
|
|
44
|
+
}), ([schema, migrations]) => schema + "\n\n" + migrations);
|
|
45
|
+
const pgDumpFile = path => Effect.gen(function* () {
|
|
46
|
+
const fs = yield* FileSystem.FileSystem;
|
|
47
|
+
const path_ = yield* Path.Path;
|
|
48
|
+
const dump = yield* pgDumpAll;
|
|
49
|
+
yield* fs.makeDirectory(path_.dirname(path), {
|
|
50
|
+
recursive: true
|
|
51
|
+
});
|
|
52
|
+
yield* fs.writeFileString(path, dump);
|
|
53
|
+
}).pipe(Effect.mapError(error => new Migrator.MigrationError({
|
|
54
|
+
kind: "Failed",
|
|
55
|
+
message: error.message
|
|
56
|
+
})));
|
|
57
|
+
return pgDumpFile(path);
|
|
58
|
+
}
|
|
68
59
|
});
|
|
69
60
|
/**
|
|
70
61
|
* @category layers
|
package/dist/PgMigrator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PgMigrator.js","names":["Layer","Migrator","run","make","layer","options","effectDiscard"],"sources":["../src/PgMigrator.ts"],"sourcesContent":[null],"mappings":"
|
|
1
|
+
{"version":3,"file":"PgMigrator.js","names":["Effect","FileSystem","Layer","Path","Redacted","ChildProcess","Migrator","PgClient","run","make","dumpSchema","path","table","pgDump","args","gen","sql","dump","env","PATH","globalThis","process","PGHOST","config","host","PGPORT","port","toString","PGUSER","username","PGPASSWORD","password","value","undefined","PGDATABASE","database","PGSSLMODE","ssl","pipe","string","replace","trim","mapError","error","MigrationError","kind","message","pgDumpSchema","pgDumpMigrations","pgDumpAll","map","all","concurrency","schema","migrations","pgDumpFile","fs","path_","makeDirectory","dirname","recursive","writeFileString","layer","options","effectDiscard"],"sources":["../src/PgMigrator.ts"],"sourcesContent":[null],"mappings":"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","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/sql-pg",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "A PostgreSQL toolkit for Effect",
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
"@testcontainers/postgresql": "^11.11.0",
|
|
47
47
|
"@types/pg": "^8.16.0",
|
|
48
48
|
"@types/pg-cursor": "^2.7.2",
|
|
49
|
-
"effect": "^4.0.0-beta.
|
|
49
|
+
"effect": "^4.0.0-beta.8"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"effect": "^4.0.0-beta.
|
|
52
|
+
"effect": "^4.0.0-beta.8"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"pg": "^8.18.0",
|
package/src/PgMigrator.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
-
import
|
|
4
|
+
import * as Effect from "effect/Effect"
|
|
5
|
+
import * as FileSystem from "effect/FileSystem"
|
|
5
6
|
import * as Layer from "effect/Layer"
|
|
7
|
+
import * as Path from "effect/Path"
|
|
8
|
+
import * as Redacted from "effect/Redacted"
|
|
9
|
+
import * as ChildProcess from "effect/unstable/process/ChildProcess"
|
|
10
|
+
import type * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner"
|
|
6
11
|
import * as Migrator from "effect/unstable/sql/Migrator"
|
|
7
|
-
import type
|
|
12
|
+
import type { SqlClient } from "effect/unstable/sql/SqlClient"
|
|
8
13
|
import type { SqlError } from "effect/unstable/sql/SqlError"
|
|
14
|
+
import { PgClient } from "./PgClient.ts"
|
|
9
15
|
|
|
10
16
|
/**
|
|
11
17
|
* @since 1.0.0
|
|
@@ -21,64 +27,66 @@ export const run: <R2 = never>(
|
|
|
21
27
|
) => Effect.Effect<
|
|
22
28
|
ReadonlyArray<readonly [id: number, name: string]>,
|
|
23
29
|
Migrator.MigrationError | SqlError,
|
|
24
|
-
|
|
30
|
+
| SqlClient
|
|
31
|
+
| PgClient
|
|
32
|
+
| ChildProcessSpawner.ChildProcessSpawner
|
|
33
|
+
| FileSystem.FileSystem
|
|
34
|
+
| Path.Path
|
|
35
|
+
| R2
|
|
25
36
|
> = Migrator.make({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
//
|
|
80
|
-
// return pgDumpFile(path)
|
|
81
|
-
// }
|
|
37
|
+
dumpSchema(path, table) {
|
|
38
|
+
const pgDump = (args: Array<string>) =>
|
|
39
|
+
Effect.gen(function*() {
|
|
40
|
+
const sql = yield* PgClient
|
|
41
|
+
const dump = yield* ChildProcess.make("pg_dump", [...args, "--no-owner", "--no-privileges"], {
|
|
42
|
+
env: {
|
|
43
|
+
PATH: (globalThis as any).process?.env.PATH,
|
|
44
|
+
PGHOST: sql.config.host,
|
|
45
|
+
PGPORT: sql.config.port?.toString(),
|
|
46
|
+
PGUSER: sql.config.username,
|
|
47
|
+
PGPASSWORD: sql.config.password
|
|
48
|
+
? Redacted.value(sql.config.password)
|
|
49
|
+
: undefined,
|
|
50
|
+
PGDATABASE: sql.config.database,
|
|
51
|
+
PGSSLMODE: sql.config.ssl ? "require" : "prefer"
|
|
52
|
+
}
|
|
53
|
+
}).pipe(ChildProcess.string)
|
|
54
|
+
|
|
55
|
+
return dump.replace(/^--.*$/gm, "")
|
|
56
|
+
.replace(/^SET .*$/gm, "")
|
|
57
|
+
.replace(/^SELECT pg_catalog\..*$/gm, "")
|
|
58
|
+
.replace(/\n{2,}/gm, "\n\n")
|
|
59
|
+
.trim();
|
|
60
|
+
}).pipe(
|
|
61
|
+
Effect.mapError((error) => new Migrator.MigrationError({ kind: "Failed", message: error.message }))
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
const pgDumpSchema = pgDump(["--schema-only"])
|
|
65
|
+
|
|
66
|
+
const pgDumpMigrations = pgDump([
|
|
67
|
+
"--column-inserts",
|
|
68
|
+
"--data-only",
|
|
69
|
+
`--table=${table}`
|
|
70
|
+
])
|
|
71
|
+
|
|
72
|
+
const pgDumpAll = Effect.map(
|
|
73
|
+
Effect.all([pgDumpSchema, pgDumpMigrations], { concurrency: 2 }),
|
|
74
|
+
([schema, migrations]) => schema + "\n\n" + migrations
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
const pgDumpFile = (path: string) =>
|
|
78
|
+
Effect.gen(function*() {
|
|
79
|
+
const fs = yield* FileSystem.FileSystem
|
|
80
|
+
const path_ = yield* Path.Path
|
|
81
|
+
const dump = yield* pgDumpAll
|
|
82
|
+
yield* fs.makeDirectory(path_.dirname(path), { recursive: true })
|
|
83
|
+
yield* fs.writeFileString(path, dump)
|
|
84
|
+
}).pipe(
|
|
85
|
+
Effect.mapError((error) => new Migrator.MigrationError({ kind: "Failed", message: error.message }))
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
return pgDumpFile(path)
|
|
89
|
+
}
|
|
82
90
|
})
|
|
83
91
|
|
|
84
92
|
/**
|
|
@@ -90,5 +98,10 @@ export const layer = <R>(
|
|
|
90
98
|
): Layer.Layer<
|
|
91
99
|
never,
|
|
92
100
|
Migrator.MigrationError | SqlError,
|
|
93
|
-
|
|
101
|
+
| SqlClient
|
|
102
|
+
| PgClient
|
|
103
|
+
| ChildProcessSpawner.ChildProcessSpawner
|
|
104
|
+
| FileSystem.FileSystem
|
|
105
|
+
| Path.Path
|
|
106
|
+
| R
|
|
94
107
|
> => Layer.effectDiscard(run(options))
|