MCPcopy Create free account
hub / github.com/Effect-TS/effect / pgDump

Function pgDump

packages/sql/pg/src/PgMigrator.ts:48–73  ·  view source on GitHub ↗
(args: Array<string>)

Source from the content-addressed store, hash-verified

46> = Migrator.make({
47 dumpSchema(path, table) {
48 const pgDump = (args: Array<string>) =>
49 Effect.gen(function*() {
50 const sql = yield* PgClient
51 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner
52 const dump = yield* ChildProcess.make("pg_dump", [...args, "--no-owner", "--no-privileges"], {
53 env: {
54 PATH: (globalThis as any).process?.env.PATH,
55 PGHOST: sql.config.host,
56 PGPORT: sql.config.port?.toString(),
57 PGUSER: sql.config.username,
58 PGPASSWORD: sql.config.password
59 ? Redacted.value(sql.config.password)
60 : undefined,
61 PGDATABASE: sql.config.database,
62 PGSSLMODE: sql.config.ssl ? "require" : "prefer"
63 }
64 }).pipe(spawner.string)
65
66 return dump.replace(/^--.*$/gm, "")
67 .replace(/^SET .*$/gm, "")
68 .replace(/^SELECT pg_catalog\..*$/gm, "")
69 .replace(/\n{2,}/gm, "\n\n")
70 .trim()
71 }).pipe(
72 Effect.mapError((error) => new Migrator.MigrationError({ kind: "Failed", message: error.message }))
73 )
74
75 const pgDumpSchema = pgDump(["--schema-only"])
76

Callers 1

dumpSchemaFunction · 0.85

Calls 5

pipeMethod · 0.65
makeMethod · 0.65
toStringMethod · 0.65
valueMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected