(path, table)
| 36 | FileSystem | Path | PgClient | Client.SqlClient | CommandExecutor | R2 |
| 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 | |
| 69 | const pgDumpMigrations = pgDump([ |
| 70 | "--column-inserts", |
| 71 | "--data-only", |
| 72 | `--table=${table}` |
| 73 | ]) |
| 74 | |
| 75 | const pgDumpAll = Effect.map( |
| 76 | Effect.all([pgDumpSchema, pgDumpMigrations], { concurrency: 2 }), |
| 77 | ([schema, migrations]) => schema + "\n\n" + migrations |
| 78 | ) |
| 79 | |
| 80 | const pgDumpFile = (path: string) => |
| 81 | Effect.gen(function*() { |
| 82 | const fs = yield* FileSystem |
| 83 | const path_ = yield* Path |
| 84 | const dump = yield* pgDumpAll |
| 85 | yield* fs.makeDirectory(path_.dirname(path), { recursive: true }) |
| 86 | yield* fs.writeFileString(path, dump) |
| 87 | }).pipe( |
| 88 | Effect.mapError((error) => new Migrator.MigrationError({ reason: "failed", message: error.message })) |
| 89 | ) |
| 90 | |
| 91 | return pgDumpFile(path) |
| 92 | } |
| 93 | }) |
| 94 | |
| 95 | /** |
no test coverage detected
searching dependent graphs…