forked from premierdesigns/pddev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpddev-migratedbdown.js
44 lines (36 loc) · 1.43 KB
/
pddev-migratedbdown.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env node
'use strict';
const args = require('args');
const sql = require('mssql/msnodesqlv8');
const SqlService = require('./sql/sqlService');
const SqlMigrationService = require('./sqlMigrationService');
(async () => {
const postgratorConfig = await require('./postgratorConfig');
const sqlService = new SqlService();
const sqlMigrationService = new SqlMigrationService();
const options = args.parse(process.argv);
// this is whatever is typed just after this subcommand: pddev-migratedbdown 5 u
const version = args.sub[0]; // would be 5 from above example
// this is whatever is typed as second parameter after this subcommand: pddev-migratedbdown 5 u
const migrateUp = args.sub[1]; // would be u from above example
let dbPool = {};
try {
const sqlDbConnectionOptions = {
connectionString: `Driver=SQL Server;Server=(local);Database=${postgratorConfig.database};Trusted_Connection=true;`,
};
dbPool = await new sql.ConnectionPool(sqlDbConnectionOptions).connect();
console.log(`connected to ${postgratorConfig.database}...`);
let result = await sqlService.runScript(dbPool, sqlService.scriptNames.migrateDown, `migrating down to version ${version}...`, {version: version});
if (migrateUp && migrateUp === 'u') {
sqlMigrationService.migrateSql();
}
}
catch (err) {
console.log(err);
}
finally {
if (dbPool && dbPool.close) {
dbPool.close();
}
}
})();