@steedos/migrate 3.0.0-beta.99 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -7
- package/migrations/1673342303163-add-instance-tasks.js +66 -59
- package/package.json +3 -4
- package/steedos-config.yml +2 -2
package/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @Author: sunhaolin@hotoa.com
|
|
3
3
|
* @Date: 2021-05-24 12:32:57
|
|
4
4
|
* @LastEditors: 孙浩林 sunhaolin@steedos.com
|
|
5
|
-
* @LastEditTime:
|
|
5
|
+
* @LastEditTime: 2025-11-26 09:59:26
|
|
6
6
|
* @Description:
|
|
7
7
|
*/
|
|
8
8
|
const migrate = require('migrate')
|
|
@@ -32,13 +32,7 @@ const up = async function () {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const init = async function () {
|
|
35
|
-
if (process.env.STEEDOS_DB_AUTO_MIGRATE !== false && process.env.STEEDOS_DB_AUTO_MIGRATE !== 'false') {
|
|
36
|
-
// 如果未设置为不自动执行,则默认自动执行
|
|
37
|
-
process.env.STEEDOS_DB_AUTO_MIGRATE = 'true'
|
|
38
|
-
}
|
|
39
35
|
const autoMigrate = validator.toBoolean(process.env.STEEDOS_DB_AUTO_MIGRATE || '', true);
|
|
40
|
-
// console.log('process.env.STEEDOS_DB_AUTO_MIGRATE:', process.env.STEEDOS_DB_AUTO_MIGRATE)
|
|
41
|
-
// console.log('autoMigrate:', autoMigrate)
|
|
42
36
|
if (autoMigrate) {
|
|
43
37
|
up();
|
|
44
38
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* @Author: sunhaolin@hotoa.com
|
|
3
3
|
* @Date: 2023-01-10 17:18:23
|
|
4
|
-
* @LastEditors: sunhaolin@
|
|
5
|
-
* @LastEditTime:
|
|
4
|
+
* @LastEditors: 孙浩林 sunhaolin@steedos.com
|
|
5
|
+
* @LastEditTime: 2025-11-26 15:22:18
|
|
6
6
|
* @Description:
|
|
7
7
|
*/
|
|
8
8
|
'use strict'
|
|
@@ -19,72 +19,79 @@ module.exports.up = async function (next) {
|
|
|
19
19
|
// 若已有instance_tasks则不执行
|
|
20
20
|
const tasksCount = await tasksColl.find({}).count()
|
|
21
21
|
if (tasksCount > 0) {
|
|
22
|
-
|
|
22
|
+
console.log('[migration]', '库中已有instance_tasks,终止执行。')
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
25
|
console.log('[migration] add-instance-tasks is running...')
|
|
26
|
-
await instanceColl.find({}).
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
aDoc
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
26
|
+
const insCount = await instanceColl.find({}).count()
|
|
27
|
+
const loopCount = 1000;
|
|
28
|
+
const totalLoops = Math.ceil(insCount / loopCount);
|
|
29
|
+
for (let loopIdx = 0; loopIdx < totalLoops; loopIdx++) {
|
|
30
|
+
console.log(`[migration] add-instance-tasks processing ${loopIdx + 1}/${totalLoops} ...`)
|
|
31
|
+
const insDocs = await instanceColl.find({}).skip(loopIdx * loopCount).limit(loopCount).toArray()
|
|
32
|
+
for (const insDoc of insDocs) {
|
|
33
|
+
var docs = [];
|
|
34
|
+
var latestApproveIndexMap = {}
|
|
35
|
+
const formDoc = await formColl.findOne({ _id: insDoc.form })
|
|
36
|
+
const extras = caculateExtras(insDoc.values, formDoc, insDoc.form_version)
|
|
37
|
+
insDoc.traces.forEach(function (tDoc, tIdx) {
|
|
38
|
+
if (tIdx == 0 && (!insDoc.distribute_from_instance && !insDoc.forward_from_instance)) {
|
|
39
|
+
// 只有分发或转发的申请单,开始节点生成instance_tasks
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
if (tDoc.approves) {
|
|
43
|
+
tDoc.approves.forEach(function (aDoc) {
|
|
44
|
+
if (aDoc.type == 'distribute' || aDoc.judge == 'relocated' || aDoc.judge == 'terminated' || aDoc.judge == 'reassigned') {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
aDoc['space'] = insDoc.space;
|
|
48
|
+
aDoc['instance_name'] = insDoc.name;
|
|
49
|
+
aDoc['submitter'] = insDoc.submitter;
|
|
50
|
+
aDoc['submitter_name'] = insDoc.submitter_name;
|
|
51
|
+
aDoc['applicant'] = insDoc.applicant;
|
|
52
|
+
aDoc['applicant_name'] = insDoc.applicant_name;
|
|
53
|
+
aDoc['applicant_organization_name'] = insDoc.applicant_organization_name;
|
|
54
|
+
aDoc['submit_date'] = insDoc.submit_date;
|
|
55
|
+
aDoc['flow'] = insDoc.flow;
|
|
56
|
+
aDoc['flow_name'] = insDoc.flow_name;
|
|
57
|
+
aDoc['form'] = insDoc.form;
|
|
58
|
+
aDoc['step'] = tDoc.step;
|
|
59
|
+
aDoc['step_name'] = tDoc.name;
|
|
60
|
+
aDoc['category_name'] = insDoc.category_name;
|
|
61
|
+
aDoc['instance_state'] = insDoc.state;
|
|
62
|
+
aDoc['distribute_from_instance'] = insDoc.distribute_from_instance;
|
|
63
|
+
aDoc['forward_from_instance'] = insDoc.forward_from_instance;
|
|
64
|
+
aDoc['keywords'] = insDoc.keywords;
|
|
65
|
+
aDoc['is_archived'] = insDoc.is_archived;
|
|
66
|
+
aDoc['category'] = insDoc.category;
|
|
67
|
+
aDoc['extras'] = extras;
|
|
68
|
+
docs.push(aDoc)
|
|
69
|
+
if (aDoc.is_finished) { //记录下需要设置is_latest_approve的游标,如有重复审批则更新为最新的
|
|
70
|
+
latestApproveIndexMap[aDoc.handler] = docs.length - 1
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
})
|
|
69
75
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
76
|
+
for (const handler in latestApproveIndexMap) {
|
|
77
|
+
if (Object.hasOwnProperty.call(latestApproveIndexMap, handler)) {
|
|
78
|
+
docs[latestApproveIndexMap[handler]].is_latest_approve = true
|
|
79
|
+
}
|
|
73
80
|
}
|
|
74
|
-
}
|
|
75
81
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
if (docs.length > 0) {
|
|
83
|
+
try {
|
|
84
|
+
await tasksColl.insertMany(docs);
|
|
85
|
+
if (extras) {
|
|
86
|
+
await instanceColl.updateOne({ _id: insDoc._id }, { $set: { extras: extras } })
|
|
87
|
+
}
|
|
88
|
+
} catch (e) {
|
|
89
|
+
console.error(e);
|
|
81
90
|
}
|
|
82
|
-
} catch (e) {
|
|
83
|
-
console.error(e);
|
|
84
91
|
}
|
|
85
92
|
}
|
|
86
|
-
}
|
|
87
|
-
|
|
93
|
+
}
|
|
94
|
+
|
|
88
95
|
const insTasksCount = await tasksColl.find({}).count()
|
|
89
96
|
console.log('[migration] add-instance-tasks successfully ran.', 'instances:', insCount, ', instance_tasks:', insTasksCount)
|
|
90
97
|
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/migrate",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Migration scripts for steedos",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"private": false,
|
|
8
7
|
"dependencies": {
|
|
9
|
-
"@steedos/service-package-registry": "3.0.
|
|
8
|
+
"@steedos/service-package-registry": "3.0.1",
|
|
10
9
|
"migrate": "^1.6.2",
|
|
11
10
|
"mongodb": "^3.7.3"
|
|
12
11
|
},
|
|
13
12
|
"publishConfig": {
|
|
14
13
|
"access": "public"
|
|
15
14
|
},
|
|
16
|
-
"gitHead": "
|
|
15
|
+
"gitHead": "4bbcc1f1ba098d299f5c363e67679f001f715575"
|
|
17
16
|
}
|
package/steedos-config.yml
CHANGED