export to a temporary directory instead

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2024-09-23 20:54:09 +02:00
parent 105d5c6ad9
commit 5d35e61937
No known key found for this signature in database
3 changed files with 14 additions and 13 deletions

View file

@ -167,6 +167,7 @@
"sshpk": "1.17.0",
"swagger-ui-express": "5.0.0",
"syslog-client": "1.1.1",
"tmp-promise": "3.0.3",
"typedi": "catalog:",
"uuid": "catalog:",
"validator": "13.7.0",

View file

@ -3,6 +3,7 @@ import * as assert from 'assert/strict';
import fs from 'fs';
import { join } from 'path';
import Container from 'typedi';
import { dir as tmpDir } from 'tmp-promise';
import { jsonColumnType } from '@/databases/entities/abstract-entity';
import { BaseCommand } from '../base-command';
@ -34,8 +35,8 @@ export class ExportAllCommand extends BaseCommand {
columns: v.columns,
}));
const backupPath = '/tmp/backup';
await fs.promises.mkdir(backupPath, { recursive: true });
const { path: tempBackupDir } = await tmpDir({});
await fs.promises.mkdir(tempBackupDir, { recursive: true });
for (const { name: tableName, columns } of tables) {
const totalRowsCount = await connection
@ -43,7 +44,7 @@ export class ExportAllCommand extends BaseCommand {
.then((rows: Array<{ count: number }>) => rows[0].count);
if (totalRowsCount === 0) continue;
const stream = fs.createWriteStream(join(backupPath, `${tableName}.jsonl`));
const stream = fs.createWriteStream(join(tempBackupDir, `${tableName}.jsonl`));
let cursor = 0;
const batchSize = 10;
@ -87,10 +88,14 @@ export class ExportAllCommand extends BaseCommand {
assert.ok(lastExecutedMigration, 'should have been run by db.ts');
await fs.promises.writeFile(
join(backupPath, 'lastMigration'),
join(tempBackupDir, 'lastMigration'),
lastExecutedMigration.name,
'utf8',
);
console.log(`data exported to ${tempBackupDir}`);
// TODO: clean up temp dir
}
async catch(error: Error) {

View file

@ -929,6 +929,9 @@ importers:
syslog-client:
specifier: 1.1.1
version: 1.1.1
tmp-promise:
specifier: 3.0.3
version: 3.0.3
typedi:
specifier: 'catalog:'
version: 0.10.0(patch_hash=sk6omkefrosihg7lmqbzh7vfxe)
@ -11600,10 +11603,6 @@ packages:
resolution: {integrity: sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==}
engines: {node: '>=0.6.0'}
tmp@0.2.1:
resolution: {integrity: sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==}
engines: {node: '>=8.17.0'}
tmp@0.2.3:
resolution: {integrity: sha512-nZD7m9iCPC5g0pYmcaxogYKggSfLsdxl8of3Q/oIbqCqLLIO9IAF0GWjX1z9NZRHPiXv8Wex4yDCaZsgEw0Y8w==}
engines: {node: '>=14.14'}
@ -25348,16 +25347,12 @@ snapshots:
tmp-promise@3.0.3:
dependencies:
tmp: 0.2.1
tmp: 0.2.3
tmp@0.0.33:
dependencies:
os-tmpdir: 1.0.2
tmp@0.2.1:
dependencies:
rimraf: 3.0.2
tmp@0.2.3: {}
tmpl@1.0.5: {}