update,
This commit is contained in:
38
tsc1877/task1/project/admin/db_seed/item.js
Normal file
38
tsc1877/task1/project/admin/db_seed/item.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('./model');
|
||||
|
||||
const Item = sequelize.define(
|
||||
'Items',
|
||||
{
|
||||
item_id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
pid: { type: DataTypes.INTEGER },
|
||||
description: { type: DataTypes.STRING, allowNull: false },
|
||||
sold: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
await Item.drop();
|
||||
|
||||
await sequelize.sync();
|
||||
for (var j = 1; j <= 25; j++) {
|
||||
for (var i = 0; i < 10; i++) {
|
||||
await Item.create({
|
||||
// get remainder of i divided by 3
|
||||
// pid: (i % 25) + 1,
|
||||
pid: j,
|
||||
description: `test item ${i}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
Reference in New Issue
Block a user