@steedos/migrate 2.3.4 → 2.4.0-beta.10
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 +11 -9
- package/client.js +13 -0
- package/index.js +34 -36
- package/migrations/1673342303163-add-instance-tasks.js +74 -0
- package/{migrations → migrations-bak}/1568174204561-init.js +0 -0
- package/{migrations → migrations-bak}/1568180513980-organizations-parent.js +0 -0
- package/{migrations → migrations-bak}/1568180513989-company_id.js +0 -0
- package/{migrations → migrations-bak}/1568260766262-username.js +0 -0
- package/{migrations → migrations-bak}/1568261580246-flows-category.js +0 -0
- package/{migrations → migrations-bak}/1568266310023-saas-admin.js +0 -0
- package/{migrations → migrations-bak}/1568706515324-space_users-organizations_parents.js +0 -0
- package/{migrations → migrations-bak}/1568710159990-space_users-invite_state.js +0 -0
- package/{migrations → migrations-bak}/1582698229817-sync-users-to-spaceusers.js +0 -0
- package/{migrations → migrations-bak}/1583285089619-set-space-field-of-spaces.js +0 -0
- package/package.json +4 -3
- package/db.js +0 -10
package/README.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
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
|
+
-->
|
|
1
8
|
Steedos Migration Scripts
|
|
2
9
|
===
|
|
3
10
|
|
|
@@ -7,8 +14,9 @@ Migrate steedos database with [node-migrate](https://github.com/tj/node-migrate)
|
|
|
7
14
|
|
|
8
15
|
### DB Connection
|
|
9
16
|
|
|
10
|
-
|
|
17
|
+
项目根目录下执行 node 进入node控制台
|
|
11
18
|
|
|
19
|
+
在node控制台执行 `require('dotenv-flow').config(); ` 目的是为了读取.env.local设置 `process.env.MONGO_URL`
|
|
12
20
|
### Migrate up
|
|
13
21
|
|
|
14
22
|
open nodejs console.
|
|
@@ -27,15 +35,9 @@ var migrate = require("@steedos/migrate");
|
|
|
27
35
|
migrate.down();
|
|
28
36
|
```
|
|
29
37
|
|
|
30
|
-
###
|
|
38
|
+
### Default auto migrate for steedos
|
|
31
39
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
```yml
|
|
35
|
-
datasources:
|
|
36
|
-
default:
|
|
37
|
-
auto_migrate: true
|
|
38
|
-
```
|
|
40
|
+
config STEEDOS_DB_AUTO_MIGRATE=false in .env.local to disable auto migrate
|
|
39
41
|
|
|
40
42
|
### Add migration script
|
|
41
43
|
|
package/client.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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;
|
package/index.js
CHANGED
|
@@ -1,69 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/*
|
|
2
|
+
* @Author: sunhaolin@hotoa.com
|
|
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');
|
|
3
11
|
|
|
4
|
-
|
|
5
|
-
|
|
12
|
+
const stateStore = path.join(process.cwd(), '.steedos', '.migrate');
|
|
13
|
+
const migrationsDirectory = path.join(__dirname, 'migrations');
|
|
6
14
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const up = async function() {
|
|
15
|
+
const up = async function () {
|
|
10
16
|
|
|
11
17
|
migrate.load({
|
|
12
18
|
stateStore: stateStore,
|
|
13
19
|
migrationsDirectory: migrationsDirectory
|
|
14
20
|
}, function (err, set) {
|
|
15
21
|
if (err) {
|
|
16
|
-
|
|
22
|
+
throw err
|
|
17
23
|
}
|
|
18
24
|
set.up(function (err) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
if (err) {
|
|
26
|
+
throw err
|
|
27
|
+
}
|
|
28
|
+
|
|
23
29
|
})
|
|
24
30
|
})
|
|
25
31
|
}
|
|
26
32
|
|
|
27
|
-
const init = async function() {
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
const init = async function () {
|
|
34
|
+
if (process.env.STEEDOS_DB_AUTO_MIGRATE !== false && process.env.STEEDOS_DB_AUTO_MIGRATE !== 'false') {
|
|
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) {
|
|
30
42
|
up();
|
|
43
|
+
}
|
|
31
44
|
}
|
|
32
45
|
|
|
33
|
-
const down = async function() {
|
|
46
|
+
const down = async function () {
|
|
34
47
|
migrate.load({
|
|
35
48
|
stateStore: stateStore,
|
|
36
49
|
migrationsDirectory: migrationsDirectory
|
|
37
50
|
}, function (err, set) {
|
|
38
51
|
if (err) {
|
|
39
|
-
|
|
52
|
+
throw err
|
|
40
53
|
}
|
|
41
54
|
set.down(function (err) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
55
|
+
if (err) {
|
|
56
|
+
throw err
|
|
57
|
+
}
|
|
58
|
+
console.log('DB migrations down successfully.')
|
|
46
59
|
})
|
|
47
60
|
})
|
|
48
61
|
}
|
|
49
62
|
|
|
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
|
-
|
|
64
63
|
module.exports = {
|
|
65
64
|
init: init,
|
|
66
65
|
up: up,
|
|
67
|
-
// upSync: upSync,
|
|
68
66
|
down: down
|
|
69
67
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: sunhaolin@hotoa.com
|
|
3
|
+
* @Date: 2023-01-10 17:18:23
|
|
4
|
+
* @LastEditors: sunhaolin@hotoa.com
|
|
5
|
+
* @LastEditTime: 2023-01-14 10:29:56
|
|
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
|
+
insDoc.traces.forEach(function (tDoc) {
|
|
27
|
+
if (tDoc.approves) {
|
|
28
|
+
tDoc.approves.forEach(function (aDoc) {
|
|
29
|
+
if (aDoc.type == 'distribute' || aDoc.judge == 'relocated' || aDoc.judge == 'terminated' || aDoc.judge == 'reassigned') {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
aDoc['space'] = insDoc.space;
|
|
33
|
+
aDoc['instance_name'] = insDoc.name;
|
|
34
|
+
aDoc['submitter'] = insDoc.submitter;
|
|
35
|
+
aDoc['submitter_name'] = insDoc.submitter_name;
|
|
36
|
+
aDoc['applicant'] = insDoc.applicant;
|
|
37
|
+
aDoc['applicant_name'] = insDoc.applicant_name;
|
|
38
|
+
aDoc['applicant_organization_name'] = insDoc.applicant_organization_name;
|
|
39
|
+
aDoc['submit_date'] = insDoc.submit_date;
|
|
40
|
+
aDoc['flow'] = insDoc.flow;
|
|
41
|
+
aDoc['flow_name'] = insDoc.flow_name;
|
|
42
|
+
aDoc['form'] = insDoc.form;
|
|
43
|
+
aDoc['step'] = tDoc.step;
|
|
44
|
+
aDoc['step_name'] = tDoc.name;
|
|
45
|
+
aDoc['category_name'] = insDoc.category_name;
|
|
46
|
+
aDoc['instance_state'] = insDoc.state;
|
|
47
|
+
aDoc['distribute_from_instance'] = insDoc.distribute_from_instance;
|
|
48
|
+
aDoc['forward_from_instance'] = insDoc.forward_from_instance;
|
|
49
|
+
aDoc['keywords'] = insDoc.keywords;
|
|
50
|
+
aDoc['is_archived'] = insDoc.is_archived;
|
|
51
|
+
aDoc['category'] = insDoc.category;
|
|
52
|
+
docs.push(aDoc)
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
if (docs.length > 0) {
|
|
58
|
+
try {
|
|
59
|
+
await tasksColl.insertMany(docs);
|
|
60
|
+
} catch (e) {
|
|
61
|
+
print(e);
|
|
62
|
+
printjson(docs.length)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
const insCount = await instanceColl.find({}).count()
|
|
67
|
+
const insTasksCount = await tasksColl.find({}).count()
|
|
68
|
+
console.log('[migration] add-instance-tasks successfully ran.', 'instances:', insCount, ', instance_tasks:', insTasksCount)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
module.exports.down = async function (next) {
|
|
72
|
+
const tasksColl = db.collection('instance_tasks')
|
|
73
|
+
await tasksColl.remove({})
|
|
74
|
+
}
|
|
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
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/migrate",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0-beta.10",
|
|
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"
|
|
9
|
+
"migrate": "^1.6.2",
|
|
10
|
+
"mongodb": "^3.7.3"
|
|
10
11
|
},
|
|
11
12
|
"publishConfig": {
|
|
12
13
|
"access": "public"
|
|
13
14
|
},
|
|
14
|
-
"gitHead": "
|
|
15
|
+
"gitHead": "7f75a50d8d5ac875eb577d586981ba654a5180ff"
|
|
15
16
|
}
|
package/db.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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;
|