| 37 | > = Migrator.make({ |
| 38 | dumpSchema(path, table) { |
| 39 | const mysqlDump = (args: Array<string>) => |
| 40 | Effect.gen(function*() { |
| 41 | const sql = yield* MysqlClient |
| 42 | |
| 43 | const url = sql.config.url ? new URL(Redacted.value(sql.config.url)) : undefined |
| 44 | |
| 45 | const host = url?.hostname ?? sql.config.host |
| 46 | const port = url?.port ?? sql.config.port?.toString() |
| 47 | const username = url?.username ?? sql.config.username |
| 48 | const password = url?.password ? Redacted.make(url.password) : sql.config.password |
| 49 | const database = url?.pathname?.slice(1) ?? sql.config.database |
| 50 | |
| 51 | const dump = yield* pipe( |
| 52 | Command.make( |
| 53 | "mysqldump", |
| 54 | ...(host ? ["-h", host] : []), |
| 55 | ...(port ? ["-P", port] : []), |
| 56 | ...(username ? ["-u", username] : []), |
| 57 | ...(password ? [`-p${Redacted.value(password)}`] : []), |
| 58 | ...(database ? [database] : []), |
| 59 | "--skip-comments", |
| 60 | "--compact", |
| 61 | ...args |
| 62 | ), |
| 63 | Command.env({ |
| 64 | PATH: (globalThis as any).process?.env.PATH |
| 65 | }), |
| 66 | Command.string |
| 67 | ) |
| 68 | |
| 69 | return dump.replace(/^\/\*.*$/gm, "") |
| 70 | .replace(/\n{2,}/gm, "\n\n") |
| 71 | .trim() |
| 72 | }).pipe( |
| 73 | Effect.mapError((error) => new Migrator.MigrationError({ reason: "failed", message: error.message })) |
| 74 | ) |
| 75 | |
| 76 | const dumpSchema = mysqlDump(["--no-data"]) |
| 77 | |