diff --git a/README.md b/README.md index 81c32a2..0c5c19f 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ npx @neondatabase/pg-import@latest --silent false --accept-all false --source="p - `--source `: The connection string for the source PostgreSQL database. This is **optional**. - Example: `--source "postgres://user:password@localhost:5432/source_db"` -- `--destination `: The connection string for the destination PostgreSQL database. This is a **required** option. +- `--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`. diff --git a/src/index.js b/src/index.js index 127df97..d8be315 100644 --- a/src/index.js +++ b/src/index.js @@ -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), @@ -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) }