-
Notifications
You must be signed in to change notification settings - Fork 36
/
_resetDatabase.js
executable file
·37 lines (34 loc) · 1.15 KB
/
_resetDatabase.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
const Client = require('ssh2').Client
const path = require('path')
require('dotenv').config()
const resetDB = `docker stop podverse_db_stage; docker rm podverse_db_stage; docker-compose -f ./podverse-ops/docker-compose.stage.yml up -d podverse_db; sleep 10; PGPASSWORD='${process.env.STAGE_DATABASE_PASSWORD}' psql -h localhost -U postgres -d postgres -f ./podverse-ops/sample-database/qa-database.sql;`
const conn = new Client()
conn
.on('ready', function () {
console.log('Client :: ready')
conn.exec(resetDB, function (err, stream) {
if (err) {
console.log('resetDatabase exec error:', err)
return
}
stream
.on('close', function (code) {
if (code) {
console.log('resetDatabase close error code:', code)
} else {
console.log('Success')
}
conn.end()
})
.on('data', () => { })
.stderr.on('data', function (data) {
console.log(data)
})
})
})
.connect({
host: process.env.STAGE_SSH_HOST,
port: process.env.STAGE_SSH_PORT,
username: process.env.STAGE_SSH_USERNAME,
privateKey: require('fs').readFileSync(path.resolve(__dirname, '../stage_ssh_key'))
})