Compare commits
16 Commits
dev
...
91de6df04d
| Author | SHA1 | Date | |
|---|---|---|---|
| 91de6df04d | |||
| a5d97d65e1 | |||
| f0128f66b0 | |||
| b33c68feb0 | |||
| 15655e3987 | |||
| d8b3864411 | |||
| 194cbd6ca8 | |||
| d5445c2282 | |||
| dcfefc8371 | |||
| b5f14335c4 | |||
| d44ac949b5 | |||
| a5e939221d | |||
| 833e3e5a9c | |||
| ba1975dd6d | |||
| 3025ef3d21 | |||
| 8564f8af83 |
@@ -1,5 +1,5 @@
|
|||||||
import 'dotenv/config';
|
import 'dotenv/config';
|
||||||
import { closeSync, existsSync, mkdirSync, openSync } from 'fs';
|
import { existsSync, mkdirSync, writeFileSync } from 'fs';
|
||||||
import { dirname, resolve } from 'path';
|
import { dirname, resolve } from 'path';
|
||||||
import { spawnSync } from 'child_process';
|
import { spawnSync } from 'child_process';
|
||||||
import Database from 'better-sqlite3';
|
import Database from 'better-sqlite3';
|
||||||
@@ -43,13 +43,11 @@ function exportSqlite(outputPath: string): void {
|
|||||||
|
|
||||||
function exportPostgres(outputPath: string): void {
|
function exportPostgres(outputPath: string): void {
|
||||||
const connString = process.env.DATABASE_URL || 'postgresql://localhost:5432/spanglish';
|
const connString = process.env.DATABASE_URL || 'postgresql://localhost:5432/spanglish';
|
||||||
const outFd = openSync(outputPath, 'w');
|
|
||||||
try {
|
|
||||||
const result = spawnSync(
|
const result = spawnSync(
|
||||||
'pg_dump',
|
'pg_dump',
|
||||||
['--clean', '--if-exists', connString],
|
['--clean', '--if-exists', connString],
|
||||||
{
|
{
|
||||||
stdio: ['ignore', outFd, 'pipe'],
|
stdio: ['ignore', 'pipe', 'pipe'],
|
||||||
encoding: 'utf-8',
|
encoding: 'utf-8',
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -65,10 +63,8 @@ function exportPostgres(outputPath: string): void {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
writeFileSync(outputPath, result.stdout);
|
||||||
console.log(`Exported to ${outputPath}`);
|
console.log(`Exported to ${outputPath}`);
|
||||||
} finally {
|
|
||||||
closeSync(outFd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
|||||||
Reference in New Issue
Block a user