Skip to content

Commit

Permalink
feat: add backup file path
Browse files Browse the repository at this point in the history
  • Loading branch information
rishi-raj-jain committed May 29, 2024
1 parent 5addab0 commit 3a1631f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bin/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
8 changes: 5 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('"'))}`
}
}
}

Expand All @@ -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])
Expand Down

0 comments on commit 3a1631f

Please sign in to comment.