Compare commits
2 Commits
91de6df04d
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 1ed62b0d3f | |||
|
|
f8ebc3760d |
@@ -1,5 +1,5 @@
|
||||
import 'dotenv/config';
|
||||
import { existsSync, mkdirSync, writeFileSync } from 'fs';
|
||||
import { closeSync, existsSync, mkdirSync, openSync } from 'fs';
|
||||
import { dirname, resolve } from 'path';
|
||||
import { spawnSync } from 'child_process';
|
||||
import Database from 'better-sqlite3';
|
||||
@@ -43,28 +43,32 @@ function exportSqlite(outputPath: string): void {
|
||||
|
||||
function exportPostgres(outputPath: string): void {
|
||||
const connString = process.env.DATABASE_URL || 'postgresql://localhost:5432/spanglish';
|
||||
const result = spawnSync(
|
||||
'pg_dump',
|
||||
['--clean', '--if-exists', connString],
|
||||
{
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
encoding: 'utf-8',
|
||||
const outFd = openSync(outputPath, 'w');
|
||||
try {
|
||||
const result = spawnSync(
|
||||
'pg_dump',
|
||||
['--clean', '--if-exists', connString],
|
||||
{
|
||||
stdio: ['ignore', outFd, 'pipe'],
|
||||
encoding: 'utf-8',
|
||||
}
|
||||
);
|
||||
|
||||
if (result.error) {
|
||||
console.error('pg_dump failed. Ensure pg_dump is installed and in PATH.');
|
||||
console.error(result.error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
);
|
||||
|
||||
if (result.error) {
|
||||
console.error('pg_dump failed. Ensure pg_dump is installed and in PATH.');
|
||||
console.error(result.error.message);
|
||||
process.exit(1);
|
||||
if (result.status !== 0) {
|
||||
console.error('pg_dump failed:', result.stderr);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`Exported to ${outputPath}`);
|
||||
} finally {
|
||||
closeSync(outFd);
|
||||
}
|
||||
|
||||
if (result.status !== 0) {
|
||||
console.error('pg_dump failed:', result.stderr);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
writeFileSync(outputPath, result.stdout);
|
||||
console.log(`Exported to ${outputPath}`);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
|
||||
Reference in New Issue
Block a user