forked from pablodenadai/node-liquibase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (41 loc) · 1.05 KB
/
index.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
45
46
const childProcess = require('child_process');
class Liquibase {
constructor(params = {}) {
const defaultParams = {
liquibase: 'lib/liquibase-core-3.5.3.jar',
driver: 'org.postgresql.Driver',
classpath: 'lib/postgresql-9.4-1201.jdbc4.jar'
};
this.params = Object.assign({}, defaultParams, params);
}
get command() {
let cmd = `java -jar ${this.params.liquibase}`;
Object.keys(this.params).forEach(key => {
if (key === 'liquibase') {
return;
}
const value = this.params[key];
cmd = `${cmd} --${key}=${value}`;
});
return cmd;
}
exec(command, options = {}) {
let child;
let promise = new Promise((resolve, reject) => {
child = childProcess
.exec(command, options, (error, stdout, stderr) => {
if (error) {
error.stderr = stderr;
return reject(error);
}
resolve({stdout: stdout});
});
});
promise.child = child;
return promise;
}
run(action = 'update', params = '') {
return this.exec(`${this.command} ${action} ${params}`);
}
}
module.exports = params => new Liquibase(params);