Skip to content

Conversation

@Jovonni
Copy link
Contributor

@Jovonni Jovonni commented Jan 7, 2026

here we add pgpm dump

usage

dump a postgres database to a sql file

pgpm dump

target postgres database name

pgpm dump --database <db_name>

alias for --database

pgpm dump --db <db_name>

output file path

pgpm dump --database <db_name> --out <path/to/file.sql>

include a prune step that keeps only this database_id after restore

pgpm dump --database <db_name> --database-id <uuid>

working directory (default: current directory)

pgpm dump --cwd <path/to/dir>

show this help message

pgpm dump --help

cc @pyramation @Anmol1696

@Jovonni Jovonni requested a review from pyramation January 7, 2026 07:16
@Jovonni Jovonni self-assigned this Jan 7, 2026
@Jovonni Jovonni added the enhancement New feature or request label Jan 7, 2026
@Jovonni Jovonni requested a review from Anmol1696 January 7, 2026 07:26
Copy link
Contributor

@Anmol1696 Anmol1696 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean AF, lets go


function quoteIdent(s: string): string {
return `"${String(s).replace(/"/g, '""')}"`;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


function quoteIdent(s: string): string {
return `"${String(s).replace(/"/g, '""')}"`;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


function quoteIdent(s: string): string {
return `"${String(s).replace(/"/g, '""')}"`;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return `"${String(s).replace(/"/g, '""')}"`;
}

async function runPgDump(args: string[], env: Record<string, string>): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import {
getPgEnvOptions,
getSpawnEnvWithPg,
} from 'pg-env';

await new Promise<void>((resolve, reject) => {
const child = spawn('pg_dump', args, {
env: {
...process.env,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export const getPgEnvVars = (): Partial<PgConfig> => {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export function getSpawnEnvWithPg(


if (databaseIdInfo) {
const pruneSql = await buildPruneSql(dbname, databaseIdInfo.id);
fs.appendFileSync(outPath, pruneSql, 'utf8');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writeFileSync

@Jovonni Jovonni marked this pull request as draft January 7, 2026 11:46
}

async function runPgDump(args: string[], env: Record<string, string>): Promise<void> {
async function runPgDump(args: string[], env: NodeJS.ProcessEnv): Promise<void> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using the lib you said, much cleaner @pyramation

const table = String(row.table_name);
lines.push(`delete from ${quoteIdent(schema)}.${quoteIdent(table)} where database_id <> '${databaseId}';`);
// Use QuoteUtils for robust identifier quoting
const qualified = QuoteUtils.quoteQualifiedIdentifier(schema, table);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here @pyramation, much cleaner

const pruneSql = await buildPruneSql(dbname, databaseIdInfo.id);
fs.appendFileSync(outPath, pruneSql, 'utf8');
// Use writeFileSync with 'a' flag for explicit append as requested
fs.writeFileSync(outPath, pruneSql, { encoding: 'utf8', flag: 'a' });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write sync @pyramation , still works

@Jovonni Jovonni marked this pull request as ready for review January 7, 2026 13:08
@pyramation pyramation merged commit 7d31920 into main Jan 7, 2026
38 checks passed
@pyramation pyramation deleted the dev/pgpm-dump branch January 7, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants