@steedos/migrate 2.3.6 → 2.3.8
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/README.md +9 -11
- package/db.js +10 -0
- package/index.js +36 -34
- package/package.json +3 -4
- package/client.js +0 -13
- package/migrations/1673342303163-add-instance-tasks.js +0 -88
- /package/{migrations-bak → migrations}/1568174204561-init.js +0 -0
- /package/{migrations-bak → migrations}/1568180513980-organizations-parent.js +0 -0
- /package/{migrations-bak → migrations}/1568180513989-company_id.js +0 -0
- /package/{migrations-bak → migrations}/1568260766262-username.js +0 -0
- /package/{migrations-bak → migrations}/1568261580246-flows-category.js +0 -0
- /package/{migrations-bak → migrations}/1568266310023-saas-admin.js +0 -0
- /package/{migrations-bak → migrations}/1568706515324-space_users-organizations_parents.js +0 -0
- /package/{migrations-bak → migrations}/1568710159990-space_users-invite_state.js +0 -0
- /package/{migrations-bak → migrations}/1582698229817-sync-users-to-spaceusers.js +0 -0
- /package/{migrations-bak → migrations}/1583285089619-set-space-field-of-spaces.js +0 -0
package/README.md
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
<!--
|
|
2
|
-
* @Author: sunhaolin@hotoa.com
|
|
3
|
-
* @Date: 2021-05-24 12:32:57
|
|
4
|
-
* @LastEditors: sunhaolin@hotoa.com
|
|
5
|
-
* @LastEditTime: 2023-01-11 16:54:20
|
|
6
|
-
* @Description:
|
|
7
|
-
-->
|
|
8
1
|
Steedos Migration Scripts
|
|
9
2
|
===
|
|
10
3
|
|
|
@@ -14,9 +7,8 @@ Migrate steedos database with [node-migrate](https://github.com/tj/node-migrate)
|
|
|
14
7
|
|
|
15
8
|
### DB Connection
|
|
16
9
|
|
|
17
|
-
|
|
10
|
+
set database connection in steedos-config.yml
|
|
18
11
|
|
|
19
|
-
在node控制台执行 `require('dotenv-flow').config(); ` 目的是为了读取.env.local设置 `process.env.MONGO_URL`
|
|
20
12
|
### Migrate up
|
|
21
13
|
|
|
22
14
|
open nodejs console.
|
|
@@ -35,9 +27,15 @@ var migrate = require("@steedos/migrate");
|
|
|
35
27
|
migrate.down();
|
|
36
28
|
```
|
|
37
29
|
|
|
38
|
-
###
|
|
30
|
+
### Enable auto migrate for steedos
|
|
39
31
|
|
|
40
|
-
config
|
|
32
|
+
steedos-config.yml
|
|
33
|
+
|
|
34
|
+
```yml
|
|
35
|
+
datasources:
|
|
36
|
+
default:
|
|
37
|
+
auto_migrate: true
|
|
38
|
+
```
|
|
41
39
|
|
|
42
40
|
### Add migration script
|
|
43
41
|
|
package/db.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
|
|
2
|
+
var objectql = require("@steedos/objectql");
|
|
3
|
+
|
|
4
|
+
var mongoUrl = objectql.getSteedosConfig().datasources.default.connection.url;
|
|
5
|
+
|
|
6
|
+
var SteedosMongoDriver = objectql.SteedosMongoDriver;
|
|
7
|
+
|
|
8
|
+
let driver = new SteedosMongoDriver({ url: process.env.MONGO_URL });
|
|
9
|
+
|
|
10
|
+
module.exports = driver;
|
package/index.js
CHANGED
|
@@ -1,67 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* @Date: 2021-05-24 12:32:57
|
|
4
|
-
* @LastEditors: sunhaolin@hotoa.com
|
|
5
|
-
* @LastEditTime: 2023-01-13 14:21:44
|
|
6
|
-
* @Description:
|
|
7
|
-
*/
|
|
8
|
-
const migrate = require('migrate')
|
|
9
|
-
const path = require('path');
|
|
10
|
-
const validator = require('validator');
|
|
1
|
+
var migrate = require('migrate')
|
|
2
|
+
var path = require('path');
|
|
11
3
|
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
var stateStore = path.join(process.cwd(), '.migrate');
|
|
5
|
+
var migrationsDirectory = path.join(__dirname, 'migrations');
|
|
14
6
|
|
|
15
|
-
|
|
7
|
+
// let Fiber = require('fibers');
|
|
8
|
+
|
|
9
|
+
const up = async function() {
|
|
16
10
|
|
|
17
11
|
migrate.load({
|
|
18
12
|
stateStore: stateStore,
|
|
19
13
|
migrationsDirectory: migrationsDirectory
|
|
20
14
|
}, function (err, set) {
|
|
21
15
|
if (err) {
|
|
22
|
-
|
|
16
|
+
throw err
|
|
23
17
|
}
|
|
24
18
|
set.up(function (err) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
if (err) {
|
|
20
|
+
throw err
|
|
21
|
+
}
|
|
22
|
+
console.log('DB migrations up successfully.')
|
|
29
23
|
})
|
|
30
24
|
})
|
|
31
25
|
}
|
|
32
26
|
|
|
33
|
-
const init = async function
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
process.env.STEEDOS_DB_AUTO_MIGRATE = 'true'
|
|
37
|
-
}
|
|
38
|
-
const autoMigrate = validator.toBoolean(process.env.STEEDOS_DB_AUTO_MIGRATE || '', true);
|
|
39
|
-
// console.log('process.env.STEEDOS_DB_AUTO_MIGRATE:', process.env.STEEDOS_DB_AUTO_MIGRATE)
|
|
40
|
-
// console.log('autoMigrate:', autoMigrate)
|
|
41
|
-
if (autoMigrate) {
|
|
27
|
+
const init = async function() {
|
|
28
|
+
var objectql = require("@steedos/objectql");
|
|
29
|
+
if (objectql.getSteedosConfig().datasources.default.auto_migrate)
|
|
42
30
|
up();
|
|
43
|
-
}
|
|
44
31
|
}
|
|
45
32
|
|
|
46
|
-
const down = async function
|
|
33
|
+
const down = async function() {
|
|
47
34
|
migrate.load({
|
|
48
35
|
stateStore: stateStore,
|
|
49
36
|
migrationsDirectory: migrationsDirectory
|
|
50
37
|
}, function (err, set) {
|
|
51
38
|
if (err) {
|
|
52
|
-
|
|
39
|
+
throw err
|
|
53
40
|
}
|
|
54
41
|
set.down(function (err) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
42
|
+
if (err) {
|
|
43
|
+
throw err
|
|
44
|
+
}
|
|
45
|
+
console.log('DB migrations down successfully.')
|
|
59
46
|
})
|
|
60
47
|
})
|
|
61
48
|
}
|
|
62
49
|
|
|
50
|
+
// const upSync = function(){
|
|
51
|
+
// Fiber(function(){
|
|
52
|
+
// let fiber = Fiber.current;
|
|
53
|
+
// up.then(result => {
|
|
54
|
+
// fiber.run();
|
|
55
|
+
// }).catch(result => {
|
|
56
|
+
// console.error(result)
|
|
57
|
+
// fiber.run();
|
|
58
|
+
// })
|
|
59
|
+
// Fiber.yield();
|
|
60
|
+
// }).run();
|
|
61
|
+
// }
|
|
62
|
+
|
|
63
|
+
|
|
63
64
|
module.exports = {
|
|
64
65
|
init: init,
|
|
65
66
|
up: up,
|
|
67
|
+
// upSync: upSync,
|
|
66
68
|
down: down
|
|
67
69
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/migrate",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.8",
|
|
4
4
|
"description": "Migration scripts for steedos",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"private": false,
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"migrate": "^1.6.2"
|
|
10
|
-
"mongodb": "^3.7.3"
|
|
9
|
+
"migrate": "^1.6.2"
|
|
11
10
|
},
|
|
12
11
|
"publishConfig": {
|
|
13
12
|
"access": "public"
|
|
14
13
|
},
|
|
15
|
-
"gitHead": "
|
|
14
|
+
"gitHead": "b2393877080bbb08d758ce883522d37bc0a12ba2"
|
|
16
15
|
}
|
package/client.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: sunhaolin@hotoa.com
|
|
3
|
-
* @Date: 2021-05-24 12:32:57
|
|
4
|
-
* @LastEditors: sunhaolin@hotoa.com
|
|
5
|
-
* @LastEditTime: 2023-01-11 11:51:05
|
|
6
|
-
* @Description:
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const { MongoClient } = require("mongodb");
|
|
10
|
-
|
|
11
|
-
const client = new MongoClient(process.env.MONGO_URL, { useNewUrlParser: true, useUnifiedTopology: true });
|
|
12
|
-
|
|
13
|
-
module.exports = client;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: sunhaolin@hotoa.com
|
|
3
|
-
* @Date: 2023-01-10 17:18:23
|
|
4
|
-
* @LastEditors: sunhaolin@hotoa.com
|
|
5
|
-
* @LastEditTime: 2023-02-11 10:49:47
|
|
6
|
-
* @Description:
|
|
7
|
-
*/
|
|
8
|
-
'use strict'
|
|
9
|
-
|
|
10
|
-
const client = require("../client");
|
|
11
|
-
|
|
12
|
-
module.exports.up = async function (next) {
|
|
13
|
-
await client.connect()
|
|
14
|
-
const db = client.db()
|
|
15
|
-
const instanceColl = db.collection('instances')
|
|
16
|
-
const tasksColl = db.collection('instance_tasks')
|
|
17
|
-
// 若已有instance_tasks则不执行
|
|
18
|
-
const tasksCount = await tasksColl.find({}).count()
|
|
19
|
-
if (tasksCount > 0) {
|
|
20
|
-
// console.log('[migration]', '库中已有instance_tasks,终止执行。')
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
console.log('[migration] add-instance-tasks is running...')
|
|
24
|
-
await instanceColl.find({}).forEach(async function (insDoc) {
|
|
25
|
-
var docs = [];
|
|
26
|
-
var latestApproveIndexMap = {}
|
|
27
|
-
insDoc.traces.forEach(function (tDoc, tIdx) {
|
|
28
|
-
if (tIdx == 0 && (!insDoc.distribute_from_instance && !insDoc.forward_from_instance)) {
|
|
29
|
-
// 只有分发或转发的申请单,开始节点生成instance_tasks
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
if (tDoc.approves) {
|
|
33
|
-
tDoc.approves.forEach(function (aDoc) {
|
|
34
|
-
if (aDoc.type == 'distribute' || aDoc.judge == 'relocated' || aDoc.judge == 'terminated' || aDoc.judge == 'reassigned') {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
aDoc['space'] = insDoc.space;
|
|
38
|
-
aDoc['instance_name'] = insDoc.name;
|
|
39
|
-
aDoc['submitter'] = insDoc.submitter;
|
|
40
|
-
aDoc['submitter_name'] = insDoc.submitter_name;
|
|
41
|
-
aDoc['applicant'] = insDoc.applicant;
|
|
42
|
-
aDoc['applicant_name'] = insDoc.applicant_name;
|
|
43
|
-
aDoc['applicant_organization_name'] = insDoc.applicant_organization_name;
|
|
44
|
-
aDoc['submit_date'] = insDoc.submit_date;
|
|
45
|
-
aDoc['flow'] = insDoc.flow;
|
|
46
|
-
aDoc['flow_name'] = insDoc.flow_name;
|
|
47
|
-
aDoc['form'] = insDoc.form;
|
|
48
|
-
aDoc['step'] = tDoc.step;
|
|
49
|
-
aDoc['step_name'] = tDoc.name;
|
|
50
|
-
aDoc['category_name'] = insDoc.category_name;
|
|
51
|
-
aDoc['instance_state'] = insDoc.state;
|
|
52
|
-
aDoc['distribute_from_instance'] = insDoc.distribute_from_instance;
|
|
53
|
-
aDoc['forward_from_instance'] = insDoc.forward_from_instance;
|
|
54
|
-
aDoc['keywords'] = insDoc.keywords;
|
|
55
|
-
aDoc['is_archived'] = insDoc.is_archived;
|
|
56
|
-
aDoc['category'] = insDoc.category;
|
|
57
|
-
docs.push(aDoc)
|
|
58
|
-
if (aDoc.is_finished) { //记录下需要设置is_latest_approve的游标,如有重复审批则更新为最新的
|
|
59
|
-
latestApproveIndexMap[aDoc.handler] = docs.length - 1
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
for (const handler in latestApproveIndexMap) {
|
|
66
|
-
if (Object.hasOwnProperty.call(latestApproveIndexMap, handler)) {
|
|
67
|
-
docs[latestApproveIndexMap[handler]].is_latest_approve = true
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (docs.length > 0) {
|
|
72
|
-
try {
|
|
73
|
-
await tasksColl.insertMany(docs);
|
|
74
|
-
} catch (e) {
|
|
75
|
-
print(e);
|
|
76
|
-
printjson(docs.length)
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
})
|
|
80
|
-
const insCount = await instanceColl.find({}).count()
|
|
81
|
-
const insTasksCount = await tasksColl.find({}).count()
|
|
82
|
-
console.log('[migration] add-instance-tasks successfully ran.', 'instances:', insCount, ', instance_tasks:', insTasksCount)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
module.exports.down = async function (next) {
|
|
86
|
-
const tasksColl = db.collection('instance_tasks')
|
|
87
|
-
await tasksColl.remove({})
|
|
88
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|