Skip to content

Commit

Permalink
feat: allow no destination
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishi Raj Jain committed May 30, 2024
1 parent 5b41f29 commit 5ed1415
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ npx @neondatabase/pg-import@latest --silent false --accept-all false --source="p
- `--source <source>`: The connection string for the source PostgreSQL database. This is **optional**.
- Example: `--source "postgres://user:password@localhost:5432/source_db"`

- `--destination <destination>`: The connection string for the destination PostgreSQL database. This is a **required** option.
- `--destination <destination>`: The connection string for the destination PostgreSQL database. This is **optional**.
- Example: `--destination "postgres://user:password@localhost:5432/destination_db"`

- `--silent`: Suppresses console output if set to `true`. The default value is `false`.
Expand Down
9 changes: 6 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ async function setupPgDumpAndPgRestore(postgresVersion) {

async function dueDiligence() {
if (!process.env.SOURCE_CONNECTION_STRING) return await getPostgresVersion(process.env.DESTINATION_CONNECTION_STRING)
if (!process.env.DESTINATION_CONNECTION_STRING) return await getPostgresVersion(process.env.SOURCE_CONNECTION_STRING)
const [sourcePostgresVersion, destinationPostgresVersion] = await Promise.all([
getPostgresVersion(process.env.SOURCE_CONNECTION_STRING),
getPostgresVersion(process.env.DESTINATION_CONNECTION_STRING),
Expand All @@ -81,8 +82,10 @@ export async function migrateData() {
executeCommandSync('pg_dump', ['-Fc', '-v', '-d', process.env.SOURCE_CONNECTION_STRING, '-f', dumpName])
console.log(`[@neondatabase/pg-import] Created a backup file '${dumpName}' succesfully.`)
}
console.log(`[@neondatabase/pg-import] Initiating data import from backup file: '${dumpName}'`)
executeCommandSync('pg_restore', ['-v', '-d', process.env.DESTINATION_CONNECTION_STRING, dumpName])
console.log(`[@neondatabase/pg-import] Data import process succesfully completed.`)
if (process.env.DESTINATION_CONNECTION_STRING) {
console.log(`[@neondatabase/pg-import] Initiating data import from backup file: '${dumpName}'`)
executeCommandSync('pg_restore', ['-v', '-d', process.env.DESTINATION_CONNECTION_STRING, dumpName])
console.log(`[@neondatabase/pg-import] Data import process succesfully completed.`)
}
process.exit(0)
}

0 comments on commit 5ed1415

Please sign in to comment.