@@ -8,10 +8,12 @@ const config = require('./config.json');
8
8
args . option ( 'databaseName' , 'The database you want to act on' ) ;
9
9
10
10
( async ( ) => {
11
+ const postgratorConfig = await require ( './postgratorConfig' ) ;
11
12
const sqlService = new SqlService ( ) ;
12
13
const options = args . parse ( process . argv ) ;
14
+ const databaseName = options . databaseName ? options . databaseName : postgratorConfig . database ;
13
15
14
- //const sqlScripts = await sqlService.transformSqlScripts({ databaseName: options. databaseName }); //await require('./sqlScripts/sqlScriptService')({ databaseName: options. databaseName });
16
+ //const sqlScripts = await sqlService.transformSqlScripts({ databaseName: databaseName }); //await require('./sqlScripts/sqlScriptService')({ databaseName: databaseName });
15
17
16
18
let masterPool = { } ;
17
19
@@ -30,25 +32,25 @@ args.option('databaseName', 'The database you want to act on');
30
32
// }
31
33
// };
32
34
const sqlDbConnectionOptions = {
33
- connectionString : `Driver=SQL Server;Server=(local);Database=${ options . databaseName } ;Trusted_Connection=true;` ,
35
+ connectionString : `Driver=SQL Server;Server=(local);Database=${ databaseName } ;Trusted_Connection=true;` ,
34
36
} ;
35
37
36
38
masterPool = await new sql . ConnectionPool ( sqlMasterConnectionOptions ) . connect ( ) ;
37
39
masterPool . config . requestTimeout = 300000 ;
38
40
console . log ( 'connected to master...' ) ;
39
41
40
42
// nuke database
41
- await sqlService . nukeDb ( masterPool , sqlDbConnectionOptions , { databaseName : options . databaseName , username : config . username , password : config . password } ) ;
43
+ await sqlService . nukeDb ( masterPool , sqlDbConnectionOptions , { databaseName : databaseName , username : config . username , password : config . password } ) ;
42
44
43
45
// **** restore database
44
- console . log ( `attempting to restore database ${ options . databaseName } ...` ) ;
46
+ console . log ( `attempting to restore database ${ databaseName } ...` ) ;
45
47
//const sqlFilePathResult = await masterPool.request().query(sqlScripts.getSqlFilePath);
46
48
const sqlFilePathResult = await sqlService . runScript ( masterPool , sqlService . scriptNames . getSqlFilePath ) ;
47
49
const sqlFilePath = sqlFilePathResult . recordsets [ 0 ] && sqlFilePathResult . recordsets [ 0 ] [ 0 ] ? sqlFilePathResult . recordsets [ 0 ] [ 0 ] . sqlFilePath : null ;
48
50
49
- let result = await sqlService . restoreDatabase ( masterPool , { databaseName : options . databaseName , restoreFilePath : './sql/restore.bak' , sqlFilePath} ) ;
51
+ let result = await sqlService . restoreDatabase ( masterPool , { databaseName : databaseName , restoreFilePath : './sql/restore.bak' , sqlFilePath} ) ;
50
52
51
- console . log ( `${ options . databaseName } restored - DONE` ) ;
53
+ console . log ( `${ databaseName } restored - DONE` ) ;
52
54
masterPool . close ( ) ;
53
55
}
54
56
catch ( err ) {
0 commit comments