@@ -21,14 +21,21 @@ function postgresDumpQuery(hostname, password, port, username, databaseName) {
21
21
const command = [ ] ;
22
22
const currentDateTime = new Date ( ) ;
23
23
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` ) ;
28
33
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 } `
30
36
) ;
31
- command . push ( filename ) ;
37
+ command . push ( dbDump ) ;
38
+ command . push ( dbSqlText ) ;
32
39
return command ;
33
40
}
34
41
@@ -39,7 +46,11 @@ function postgresDumpQuery(hostname, password, port, username, databaseName) {
39
46
*/
40
47
const writeSchema = async ( command ) => {
41
48
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 )
43
54
return stdout ;
44
55
} catch ( error ) {
45
56
console . error ( `error in WS: ${ error . message } ` ) ;
@@ -62,17 +73,18 @@ export const getSchema = (req, res, next) => {
62
73
const { hostname, password, port, username, database_name } = req . body ;
63
74
64
75
const command = postgresDumpQuery ( hostname , password , port , username , database_name ) ;
65
-
76
+
66
77
writeSchema ( command ) . then ( ( resq ) => {
67
- fs . readFile ( command [ 1 ] , 'utf8' , ( error , data ) => {
78
+ fs . readFile ( command [ 3 ] , 'utf8' , ( error , data ) => {
68
79
if ( error ) {
69
80
console . error ( `error- in FS: ${ error . message } ` ) ;
70
81
return next ( {
71
82
msg : 'Error reading database schema file' ,
72
83
err : error ,
73
84
} ) ;
74
85
}
75
-
86
+ console . log ( 'reading file:' , 'command[3]' )
87
+ console . log ( 'file:' , data )
76
88
result = parseSql . default ( data ) ;
77
89
res . locals . data = result ;
78
90
next ( ) ;
0 commit comments