You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
2.7 KiB
103 lines
2.7 KiB
const sequelize = require("./dbConnect")
|
|
const userModel = require("./model/userModel")
|
|
const inventoryModel = require("./model/inventoryModel")
|
|
const md5 = require("md5")
|
|
|
|
const adminName = "root"
|
|
const adminPwd = "123456"
|
|
//将数据模型和表进行同步
|
|
async function test() {
|
|
await sequelize.sync({
|
|
alter: true
|
|
})
|
|
|
|
//将需要数据的表初始化
|
|
const userCount = await userModel.count()
|
|
if (!userCount) {
|
|
//需要初始化
|
|
await userModel.create({
|
|
username: adminName,
|
|
password: md5(adminPwd),
|
|
isAdmin: true
|
|
})
|
|
|
|
console.log("用户数据初始化完毕")
|
|
}
|
|
|
|
const inventoryCount = await inventoryModel.count()
|
|
if (!inventoryCount) {
|
|
//需要初始化
|
|
await inventoryModel.bulkCreate([{
|
|
"dishName": "茶叶蛋",
|
|
"quantity": 25,
|
|
"price": 1,
|
|
"description": null,
|
|
"imageUrl": null
|
|
},
|
|
{
|
|
"dishName": "豆浆",
|
|
"quantity": 15,
|
|
"price": 2,
|
|
"description": null,
|
|
"imageUrl": null
|
|
},
|
|
{
|
|
"dishName": "油条",
|
|
"quantity": 20,
|
|
"price": 1.5,
|
|
"description": null,
|
|
"imageUrl": null
|
|
},
|
|
{
|
|
"dishName": "煎饼",
|
|
"quantity": 18,
|
|
"price": 4,
|
|
"description": null,
|
|
"imageUrl": null
|
|
},
|
|
{
|
|
"dishName": "火腿肠",
|
|
"quantity": 30,
|
|
"price": 1.5,
|
|
"description": null,
|
|
"imageUrl": null
|
|
},
|
|
{
|
|
"dishName": "豆沙包",
|
|
"quantity": 50,
|
|
"price": 2,
|
|
"description": null,
|
|
"imageUrl": null
|
|
},
|
|
{
|
|
"dishName": "肉包",
|
|
"quantity": 50,
|
|
"price": 2,
|
|
"description": null,
|
|
"imageUrl": null
|
|
},
|
|
{
|
|
"dishName": "馒头",
|
|
"quantity": 100,
|
|
"price": 1,
|
|
"description": null,
|
|
"imageUrl": null
|
|
},
|
|
{
|
|
"dishName": "牛奶",
|
|
"quantity": 20,
|
|
"price": 3,
|
|
"description": null,
|
|
"imageUrl": null
|
|
},
|
|
])
|
|
|
|
console.log("库存数据初始化完毕")
|
|
}
|
|
|
|
// const expressCount = await expressModel.count()
|
|
|
|
|
|
console.log("数据库数据准备完成")
|
|
}
|
|
test() |