-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpatch_inserts.js
More file actions
65 lines (57 loc) · 1.57 KB
/
patch_inserts.js
File metadata and controls
65 lines (57 loc) · 1.57 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* ### Пример групповой замены реквизита
*
* Created 24.02.2018
*/
/**
* ### Переменные окружения
* DEBUG "wb:*,-not_this"
* ZONE 92
* DBPWD admin
* DBUSER admin
* COUCHPATH http://cou221:5984/wb_
*/
'use strict';
process.env.DEBUG = "wb:*,-not_this";
const debug = require('debug')('wb:patch');
const PouchDB = require('pouchdb').plugin(require('pouchdb-find'));
debug('required');
// инициализируем параметры сеанса и метаданные
const {DBUSER, DBPWD, COUCHPATH='http://alutech2.oknosoft.ru:5980/wb_', ZONE=92} = process.env;
// будем заменять 10000 на 7000
const lmaxOld = 10000;
const lmax = 7000;
const limit = 100000;
const db = new PouchDB(`${COUCHPATH}${ZONE}_ram`, {
auth: {username: DBUSER, password: DBPWD},
skip_setup: true,
ajax: {timeout: 100000}
});
db.info()
.then((info) => {
debug(`connected to ${info.host}, doc count: ${info.doc_count}`);
})
.then(execute)
.then(() => debug(`ok`));
function execute() {
// получаем все вставки типа профиль с ограничением длины по умолчанию
return db.find({
selector: {
class_name: 'cat.inserts',
insert_type: 'Профиль',
lmax: lmaxOld,
},
limit,
})
.then(({docs}) => {
debug(`received ${docs.length} rows`);
for(const doc of docs) {
doc.lmax = lmax;
}
return db.bulkDocs(docs);
})
.then((res) => {
debug(`updated ${res.length} rows`);
})
.catch(debug);
}