Skip to content

Commit f9d4f96

Browse files
authored
Merge pull request #5 from topcoder-platform/dev
dev to master sync [skip ci]
2 parents 80f2811 + 413e163 commit f9d4f96

File tree

3 files changed

+142
-164
lines changed

3 files changed

+142
-164
lines changed

config/default.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ module.exports = {
77
NAME: 'db.ifxpgmigrate.sync',
88
PARTITION: 0
99
},
10-
RETRY_COUNTER: 3,
11-
KAFKA_REPOST_COUNT: 5,
10+
RETRY_COUNTER: parseInt(process.env.RETRY_COUNTER || 3, 10),
11+
KAFKA_REPOST_COUNT: parseInt(process.env.KAFKA_REPOST_COUNT || 5, 10),
1212
KAFKA_URL: process.env.KAFKA_URL,
1313
KAFKA_GROUP_ID: process.env.KAFKA_GROUP_ID || 'ifx-pg-consumer',
1414
KAFKA_CLIENT_CERT: process.env.KAFKA_CLIENT_CERT ? process.env.KAFKA_CLIENT_CERT.replace('\\n', '\n') : null,

src/api/migrateifxpg.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ async function migrateifxinsertdata(payload, client) {
7979
}
8080
//console.log(columns[colName])
8181
//conditionstr = conditionstr + tablename + "." + colName + "= '" + columns[colName] + "' "
82-
if ((datatypeobj[colName] == 'timestamp' || datatypeobj[colName] == 'numeric' || datatypeobj[colName] == 'date' ) && columns[colName].toUpperCase() == 'NULL') {
82+
if ((datatypeobj[colName] == 'timestamp' || datatypeobj[colName] == 'numeric' || datatypeobj[colName] == 'date') && columns[colName].toUpperCase() == 'NULL') {
8383
conditionstr = conditionstr + tablename + "." + colName + " is NULL "
8484
} else {
8585
conditionstr = conditionstr + tablename + "." + colName + "= '" + columns[colName] + "' "
@@ -94,7 +94,7 @@ async function migrateifxinsertdata(payload, client) {
9494
}
9595
//console.log(columns[colName])
9696
//conditionstr = conditionstr + tablename + "." + colName + "= '" + columns[colName] + "' "
97-
if ((datatypeobj[colName] == 'timestamp' || datatypeobj[colName] == 'numeric' || datatypeobj[colName] == 'date' ) && columns[colName].toUpperCase() == 'NULL') {
97+
if ((datatypeobj[colName] == 'timestamp' || datatypeobj[colName] == 'numeric' || datatypeobj[colName] == 'date') && columns[colName].toUpperCase() == 'NULL') {
9898
conditionstr = conditionstr + tablename + "." + colName + " is NULL "
9999
} else {
100100
conditionstr = conditionstr + tablename + "." + colName + "= '" + columns[colName] + "' "
@@ -125,7 +125,7 @@ async function migrateifxinsertdata(payload, client) {
125125
const values = [];
126126
columnNames.forEach((colName) => {
127127
if (row[colName]) {
128-
if (isUtf8(row[colName]) || datatypeobj[colName] == 'timestamp' || datatypeobj[colName] == 'date' ) {
128+
if (isUtf8(row[colName]) || datatypeobj[colName] == 'timestamp' || datatypeobj[colName] == 'date') {
129129
console.log(`utf8 or datetime format ${colName}`);
130130
// values.push(new Buffer.from(row[colName],'binary'));
131131
values.push(row[colName]);
@@ -138,7 +138,7 @@ async function migrateifxinsertdata(payload, client) {
138138
}
139139
//values.push(new Buffer.from(row[colName],'binary'));
140140
});
141-
let schemaname = (db_schema == pg_dbname) ? 'public' : db_schema;
141+
let schemaname = (db_schema == pg_dbname) ? 'public' : db_schema;
142142
sql = `SET search_path TO ${schemaname};`;
143143
console.log(sql);
144144
await client.query(sql);
@@ -220,7 +220,7 @@ async function migrateifxupdatedata(payload, client) {
220220
if (bufffernewcond == 1) {
221221
conditionstr = conditionstr + " and "
222222
}
223-
if ((datatypeobj[colName] == 'timestamp' || datatypeobj[colName] == 'numeric' || datatypeobj[colName] == 'date' ) && colobj['new'].toUpperCase() == 'NULL') {
223+
if ((datatypeobj[colName] == 'timestamp' || datatypeobj[colName] == 'numeric' || datatypeobj[colName] == 'date') && colobj['new'].toUpperCase() == 'NULL') {
224224
conditionstr = conditionstr + tablename + "." + colName + " is NULL "
225225
} else {
226226
conditionstr = conditionstr + tablename + "." + colName + "= '" + colobj.new + "' "
@@ -233,7 +233,7 @@ async function migrateifxupdatedata(payload, client) {
233233
}
234234
//console.log(colobj.old);
235235
//oldconditionstr = oldconditionstr + tablename + "." + colName + "= '" + colobj.old + "' "
236-
if ((datatypeobj[colName] == 'timestamp' || datatypeobj[colName] == 'numeric' || datatypeobj[colName] == 'date' ) && colobj['old'].toUpperCase() == 'NULL') {
236+
if ((datatypeobj[colName] == 'timestamp' || datatypeobj[colName] == 'numeric' || datatypeobj[colName] == 'date') && colobj['old'].toUpperCase() == 'NULL') {
237237
oldconditionstr = oldconditionstr + "\"" + colName + "\" is NULL "
238238
} else {
239239
oldconditionstr = oldconditionstr + "\"" + colName + "\"= '" + colobj.old + "' "
@@ -246,7 +246,7 @@ async function migrateifxupdatedata(payload, client) {
246246
if (bufffernewcond == 1) {
247247
conditionstr = conditionstr + " and "
248248
}
249-
if ((datatypeobj[colName] == 'timestamp' || datatypeobj[colName] == 'numeric' || datatypeobj[colName] == 'date' ) && colobj['new'].toUpperCase() == 'NULL') {
249+
if ((datatypeobj[colName] == 'timestamp' || datatypeobj[colName] == 'numeric' || datatypeobj[colName] == 'date') && colobj['new'].toUpperCase() == 'NULL') {
250250
conditionstr = conditionstr + tablename + "." + colName + " is NULL "
251251
} else {
252252
conditionstr = conditionstr + tablename + "." + colName + "= '" + colobj.new + "' "
@@ -259,7 +259,7 @@ async function migrateifxupdatedata(payload, client) {
259259
}
260260
//console.log(colobj.old);
261261
//oldconditionstr = oldconditionstr + tablename + "." + colName + "= '" + colobj.old + "' "
262-
if ((datatypeobj[colName] == 'timestamp' || datatypeobj[colName] == 'numeric' || datatypeobj[colName] == 'date' ) && colobj['old'].toUpperCase() == 'NULL') {
262+
if ((datatypeobj[colName] == 'timestamp' || datatypeobj[colName] == 'numeric' || datatypeobj[colName] == 'date') && colobj['old'].toUpperCase() == 'NULL') {
263263
oldconditionstr = oldconditionstr + "\"" + colName + "\" is NULL "
264264
} else {
265265
oldconditionstr = oldconditionstr + "\"" + colName + "\"= '" + colobj.old + "' "
@@ -293,7 +293,7 @@ async function migrateifxupdatedata(payload, client) {
293293
updatestr = updatestr + " , "
294294
}
295295
if (row[colName]) {
296-
if (isUtf8(row[colName]) || datatypeobj[colName] == 'timestamp' || datatypeobj[colName] == 'date' ) {
296+
if (isUtf8(row[colName]) || datatypeobj[colName] == 'timestamp' || datatypeobj[colName] == 'date') {
297297
//console.log(`utf8 format ${colName}`);
298298
values.push(row[colName]);
299299
updatestr = updatestr + "\"" + colName + "\"= \$" + counter + " "
@@ -339,8 +339,8 @@ async function migrateifxdeletedata(payload, client) {
339339
const table = payload.TABLENAME
340340
const tablename = payload.TABLENAME
341341
const dbname = payload.SCHEMANAME
342-
columns = payload.DATA
343-
payload = payload.DATA
342+
columns = payload.DATA
343+
payload = payload.DATA
344344
try {
345345

346346
//const client = await dbpool.connect();
@@ -379,13 +379,13 @@ async function migrateifxdeletedata(payload, client) {
379379
usepkforcond = usepkforcond + 1
380380
}
381381
}
382-
382+
383383
});
384384
}
385385
var conditionstr = ""
386386
//const paramSql = Array.from(Array(columnNames.length).keys(), x => `$${x + 1}`).join(',');
387387
//const insertSql = `insert into "${tablename}" (${columnNames.map(x => `"${x}"`).join(',')}) values(${paramSql})`;
388-
bufffercond = 0
388+
bufffercond = 0
389389
columnNames.forEach((colName) => {
390390
console.log(colName)
391391
//tempvar = columns[colName]
@@ -397,7 +397,7 @@ async function migrateifxdeletedata(payload, client) {
397397
}
398398
//console.log(columns[colName])
399399
//conditionstr = conditionstr + tablename + "." + colName + "= '" + columns[colName] + "' "
400-
if ((datatypeobj[colName] == 'timestamp' || datatypeobj[colName] == 'numeric' || datatypeobj[colName] == 'date' ) && columns[colName].toUpperCase() == 'NULL') {
400+
if ((datatypeobj[colName] == 'timestamp' || datatypeobj[colName] == 'numeric' || datatypeobj[colName] == 'date') && columns[colName].toUpperCase() == 'NULL') {
401401
conditionstr = conditionstr + tablename + "." + colName + " is NULL "
402402
} else {
403403
conditionstr = conditionstr + tablename + "." + colName + "= '" + columns[colName] + "' "
@@ -412,7 +412,7 @@ async function migrateifxdeletedata(payload, client) {
412412
}
413413
//console.log(columns[colName])
414414
//conditionstr = conditionstr + tablename + "." + colName + "= '" + columns[colName] + "' "
415-
if ((datatypeobj[colName] == 'timestamp' || datatypeobj[colName] == 'numeric' || datatypeobj[colName] == 'date' ) && columns[colName].toUpperCase() == 'NULL') {
415+
if ((datatypeobj[colName] == 'timestamp' || datatypeobj[colName] == 'numeric' || datatypeobj[colName] == 'date') && columns[colName].toUpperCase() == 'NULL') {
416416
conditionstr = conditionstr + tablename + "." + colName + " is NULL "
417417
} else {
418418
conditionstr = conditionstr + tablename + "." + colName + "= '" + columns[colName] + "' "
@@ -422,7 +422,7 @@ async function migrateifxdeletedata(payload, client) {
422422
}
423423
}
424424
});
425-
425+
426426
sql = `SET search_path TO ${schemaname};`;
427427
console.log(sql);
428428
await client.query(sql);
@@ -434,7 +434,7 @@ async function migrateifxdeletedata(payload, client) {
434434
console.log(`end connection of postgres for database`);
435435
} catch (e) {
436436
throw e;
437-
}
437+
}
438438
}
439439

440440
module.exports = {

0 commit comments

Comments
 (0)