forked from 1Crazymoney/yield-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdatePool.js
30 lines (24 loc) · 857 Bytes
/
updatePool.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
const fs = require('fs');
const { confirm } = require('./confirm');
const { pgp, connect } = require('../src/utils/dbConnection');
const {
tableName: configTableName,
} = require('../src/controllers/configController');
(async () => {
await confirm(
`Confirm with 'yes' if you want to start the ${process.argv[1]
.split('/')
.slice(-1)} script: `
);
const payload = JSON.parse(fs.readFileSync('./old_new_mapping.json'));
const X = payload.map((p) => ({ poolOld: p.pool, pool: p.poolNew }));
// ? -> only used in where clause
const cs = new pgp.helpers.ColumnSet(['?poolOld', 'pool'], {
table: configTableName,
});
const query = pgp.helpers.update(X, cs) + ' WHERE v."poolOld" = t.pool';
const conn = await connect();
const response = await conn.result(query);
console.log(response);
process.exit(0);
})();