1 Star 0 Fork 83

luck8yjz / artipub

forked from BigBao / artipub 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
init.js 1.29 KB
一键复制 编辑 原始数据 按行查看 历史
Marvin Zhang 提交于 2019-09-15 09:31 . fixed update all bug
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
JavaScript
1
https://gitee.com/luck8yjz/artipub.git
git@gitee.com:luck8yjz/artipub.git
luck8yjz
artipub
artipub
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891