Skip to content

Commit dddb4d1

Browse files
authored
Merge pull request #28 from oslabs-beta/alex-test
pg dump sped up
2 parents af51be5 + 5dd6c62 commit dddb4d1

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

server/controllers/postgresData.controller.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,21 @@ function postgresDumpQuery(hostname, password, port, username, databaseName) {
2121
const command = [];
2222
const currentDateTime = new Date();
2323
const resultInSeconds = parseInt(currentDateTime.getTime() / 1000);
24-
const filename = path.join(
25-
__dirname,
26-
`../db_schemas/${username}${databaseName}${resultInSeconds.toString()}.sql`
27-
);
24+
// const filename = path.join(
25+
// __dirname,
26+
// `../db_schemas/${username}${databaseName}${resultInSeconds.toString()}.sql`
27+
// );
28+
// command.push(
29+
// `pg_dump -s postgres://${username}:${password}@${hostname}:${port}/${databaseName} > ${filename}`
30+
// );
31+
const dbDump = path.join(__dirname, `../db_schemas/${username}${databaseName}${resultInSeconds.toString()}.dump`);
32+
const dbSqlText = path.join(__dirname, `../db_schemas/${username}${databaseName}${resultInSeconds.toString()}.sql`);
2833
command.push(
29-
`pg_dump -s postgres://${username}:${password}@${hostname}:${port}/${databaseName} > ${filename}`
34+
`pg_dump -s -Fc -Z 9 postgres://${username}:${password}@${hostname}:${port}/${databaseName} > ${dbDump}`
35+
,`pg_restore -f ${dbSqlText} ${dbDump} `
3036
);
31-
command.push(filename);
37+
command.push(dbDump);
38+
command.push(dbSqlText);
3239
return command;
3340
}
3441

@@ -39,7 +46,11 @@ function postgresDumpQuery(hostname, password, port, username, databaseName) {
3946
*/
4047
const writeSchema = async (command) => {
4148
try {
42-
const { stdout, stderr } = await exec(command[0]);
49+
console.log('firing command 0')
50+
await exec(command[0])
51+
console.log('firing command 1')
52+
const { stdout, stderr } = await exec(command[1]);
53+
console.log('command 1 output', stdout)
4354
return stdout;
4455
} catch (error) {
4556
console.error(`error in WS: ${error.message}`);
@@ -62,17 +73,18 @@ export const getSchema = (req, res, next) => {
6273
const { hostname, password, port, username, database_name } = req.body;
6374

6475
const command = postgresDumpQuery(hostname, password, port, username, database_name);
65-
76+
6677
writeSchema(command).then((resq) => {
67-
fs.readFile(command[1], 'utf8', (error, data) => {
78+
fs.readFile(command[3], 'utf8', (error, data) => {
6879
if (error) {
6980
console.error(`error- in FS: ${error.message}`);
7081
return next({
7182
msg: 'Error reading database schema file',
7283
err: error,
7384
});
7485
}
75-
86+
console.log('reading file:', 'command[3]')
87+
console.log('file:', data)
7688
result = parseSql.default(data);
7789
res.locals.data = result;
7890
next();

0 commit comments

Comments
 (0)