diff --git a/bin/migrate.js b/bin/migrate.js index c37938c..268eaa5 100755 --- a/bin/migrate.js +++ b/bin/migrate.js @@ -18,6 +18,6 @@ process.env.SILENT = options.silent process.env.ACCEPT_ALL = options.acceptAll process.env.SOURCE_CONNECTION_STRING = options.source process.env.DESTINATION_CONNECTION_STRING = options.destination -process.env.BACKUP_FILE_PATH = options.backupFilePath +if (options.backupFilePath) process.env.BACKUP_FILE_PATH = options.backupFilePath migrateData() diff --git a/src/index.js b/src/index.js index 3bf97d7..e35abf8 100644 --- a/src/index.js +++ b/src/index.js @@ -50,8 +50,10 @@ async function setupPgDumpAndPgRestore(postgresVersion) { if (installOutput.length > 0) { installOutput = installOutput.split('\n') const index = installOutput.indexOf('If you need to have this software first in your PATH instead consider running:') - const tmp = installOutput[index + 1].trim() - if (tmp?.includes('PATH')) process.env.PATH = `${tmp.substring(tmp.indexOf('"') + 1, tmp.lastIndexOf('"'))}` + if (index !== -1) { + const tmp = installOutput[index + 1].trim() + if (tmp?.includes('PATH')) process.env.PATH = `${tmp.substring(tmp.indexOf('"') + 1, tmp.lastIndexOf('"'))}` + } } } @@ -72,7 +74,7 @@ export async function migrateData() { console.log(`[@neondatabase/pg-import] Setting pg_dump and pg_restore for Postgres ${postgresVersion}`) await setupPgDumpAndPgRestore(postgresVersion) console.log('[@neondatabase/pg-import] pg_dump and pg_restore setup complete.') - const dumpName = process.env.BACKUP_FILE_PATH ?? `dump_restore_${uuidv4()}.bak` + const dumpName = process.env.BACKUP_FILE_PATH || `dump_restore_${uuidv4()}.bak` executeCommandSync('pg_dump', ['-Fc', '-v', '-d', process.env.SOURCE_CONNECTION_STRING, '-f', dumpName]) console.log(`[@neondatabase/pg-import] Created a backup file '${dumpName}' succesfully.`) executeCommandSync('pg_restore', ['-v', '-d', process.env.DESTINATION_CONNECTION_STRING, dumpName])