forked from crawlab-team/artipub
/
init.js
46 lines (43 loc) · 1.29 KB
/
init.js
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
const models = require('./models')
const data = require('./data')
// 数据库初始化
const init = async () => {
// 初始化平台数据
for (let i = 0; i < data.platforms.length; i++) {
const platform = data.platforms[i]
let platformDb = await models.Platform.findOne({ name: platform.name })
if (!platformDb) {
platformDb = new models.Platform(platform)
await platformDb.save()
} else {
for (let key in platform) {
if (platform.hasOwnProperty(key)) {
if (platform[key] !== undefined) {
platformDb[key] = platform[key]
}
}
}
await platformDb.save()
}
}
// 初始化环境变量数据
for (let i = 0; i < data.environments.length; i++) {
const environment = data.environments[i]
let environmentDb = await models.Environment.findOne({ _id: environment._id })
if (!environmentDb) {
environmentDb = new models.Environment(environment)
await environmentDb.save()
} else {
// do nothing
// for (let key in environment) {
// if (environment.hasOwnProperty(key)) {
// if (environment[key]) {
// environmentDb[key] = environment[key]
// }
// }
// }
// await environmentDb.save()
}
}
}
module.exports = init