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