-
Notifications
You must be signed in to change notification settings - Fork 5
added pgpm dump #573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added pgpm dump #573
Conversation
Anmol1696
left a comment
There was a problem hiding this 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
pgpm/cli/src/commands/dump.ts
Outdated
|
|
||
| function quoteIdent(s: string): string { | ||
| return `"${String(s).replace(/"/g, '""')}"`; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pgpm/cli/src/commands/dump.ts
Outdated
|
|
||
| function quoteIdent(s: string): string { | ||
| return `"${String(s).replace(/"/g, '""')}"`; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pgpm/cli/src/commands/dump.ts
Outdated
|
|
||
| function quoteIdent(s: string): string { | ||
| return `"${String(s).replace(/"/g, '""')}"`; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pgpm/cli/src/commands/dump.ts
Outdated
| return `"${String(s).replace(/"/g, '""')}"`; | ||
| } | ||
|
|
||
| async function runPgDump(args: string[], env: Record<string, string>): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constructive/pgpm/cli/src/commands/deploy.ts
Lines 7 to 10 in cb086f0
| import { | |
| getPgEnvOptions, | |
| getSpawnEnvWithPg, | |
| } from 'pg-env'; |
pgpm/cli/src/commands/dump.ts
Outdated
| await new Promise<void>((resolve, reject) => { | ||
| const child = spawn('pg_dump', args, { | ||
| env: { | ||
| ...process.env, |
There was a problem hiding this comment.
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> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constructive/postgres/pg-env/src/env.ts
Line 43 in cb086f0
| export function getSpawnEnvWithPg( |
pgpm/cli/src/commands/dump.ts
Outdated
|
|
||
| if (databaseIdInfo) { | ||
| const pruneSql = await buildPruneSql(dbname, databaseIdInfo.id); | ||
| fs.appendFileSync(outPath, pruneSql, 'utf8'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
writeFileSync
| } | ||
|
|
||
| async function runPgDump(args: string[], env: Record<string, string>): Promise<void> { | ||
| async function runPgDump(args: string[], env: NodeJS.ProcessEnv): Promise<void> { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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' }); |
There was a problem hiding this comment.
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
here we add
pgpm dumpusage
dump a postgres database to a sql file
pgpm dumptarget 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 --helpcc @pyramation @Anmol1696