431 lines
8.6 KiB
JavaScript
431 lines
8.6 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Categories = db.categories;
|
|
|
|
const CoffeeBlends = db.coffee_blends;
|
|
|
|
const Customers = db.customers;
|
|
|
|
const Orders = db.orders;
|
|
|
|
const Payments = db.payments;
|
|
|
|
const Reports = db.reports;
|
|
|
|
const CategoriesData = [
|
|
{
|
|
name: 'Organic',
|
|
|
|
description: 'Certified organic coffee blends.',
|
|
},
|
|
|
|
{
|
|
name: 'Fair Trade',
|
|
|
|
description: 'Fair trade certified coffee blends.',
|
|
},
|
|
|
|
{
|
|
name: 'Seasonal',
|
|
|
|
description: 'Special seasonal coffee blends.',
|
|
},
|
|
|
|
{
|
|
name: 'Espresso',
|
|
|
|
description: 'Espresso coffee blends.',
|
|
},
|
|
];
|
|
|
|
const CoffeeBlendsData = [
|
|
{
|
|
name: 'Espresso Delight',
|
|
|
|
description: 'A rich and bold espresso blend.',
|
|
|
|
price: 12.99,
|
|
|
|
stock_level: 100,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Morning Bliss',
|
|
|
|
description: 'A smooth and aromatic morning blend.',
|
|
|
|
price: 10.99,
|
|
|
|
stock_level: 150,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Organic Harmony',
|
|
|
|
description: 'A certified organic coffee blend.',
|
|
|
|
price: 14.99,
|
|
|
|
stock_level: 80,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Fair Trade Fiesta',
|
|
|
|
description: 'A fair trade certified coffee blend.',
|
|
|
|
price: 13.99,
|
|
|
|
stock_level: 120,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const CustomersData = [
|
|
{
|
|
first_name: 'John',
|
|
|
|
last_name: 'Doe',
|
|
|
|
email: 'john.doe@example.com',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
first_name: 'Jane',
|
|
|
|
last_name: 'Smith',
|
|
|
|
email: 'jane.smith@example.com',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
first_name: 'Alice',
|
|
|
|
last_name: 'Johnson',
|
|
|
|
email: 'alice.johnson@example.com',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
first_name: 'Bob',
|
|
|
|
last_name: 'Brown',
|
|
|
|
email: 'bob.brown@example.com',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const OrdersData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
order_date: new Date('2023-10-01T10:00:00Z'),
|
|
|
|
status: 'Cancelled',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
order_date: new Date('2023-10-02T11:30:00Z'),
|
|
|
|
status: 'Shipped',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
order_date: new Date('2023-10-03T09:15:00Z'),
|
|
|
|
status: 'Cancelled',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
order_date: new Date('2023-10-04T14:45:00Z'),
|
|
|
|
status: 'Cancelled',
|
|
},
|
|
];
|
|
|
|
const PaymentsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 25.98,
|
|
|
|
status: 'Completed',
|
|
|
|
payment_date: new Date('2023-10-01T10:05:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 14.99,
|
|
|
|
status: 'Pending',
|
|
|
|
payment_date: new Date('2023-10-02T11:35:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 29.98,
|
|
|
|
status: 'Failed',
|
|
|
|
payment_date: new Date('2023-10-03T09:20:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 24.98,
|
|
|
|
status: 'Completed',
|
|
|
|
payment_date: new Date('2023-10-04T14:50:00Z'),
|
|
},
|
|
];
|
|
|
|
const ReportsData = [
|
|
{
|
|
report_date: new Date('2023-10-01T00:00:00Z'),
|
|
|
|
content: 'Sales increased by 10% this month.',
|
|
},
|
|
|
|
{
|
|
report_date: new Date('2023-10-02T00:00:00Z'),
|
|
|
|
content: 'Customer satisfaction is at 85%.',
|
|
},
|
|
|
|
{
|
|
report_date: new Date('2023-10-03T00:00:00Z'),
|
|
|
|
content: "New blend 'Espresso Delight' is a top seller.",
|
|
},
|
|
|
|
{
|
|
report_date: new Date('2023-10-04T00:00:00Z'),
|
|
|
|
content: 'Inventory levels are stable.',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateCoffeeBlendWithCategory() {
|
|
const relatedCategory0 = await Categories.findOne({
|
|
offset: Math.floor(Math.random() * (await Categories.count())),
|
|
});
|
|
const CoffeeBlend0 = await CoffeeBlends.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (CoffeeBlend0?.setCategory) {
|
|
await CoffeeBlend0.setCategory(relatedCategory0);
|
|
}
|
|
|
|
const relatedCategory1 = await Categories.findOne({
|
|
offset: Math.floor(Math.random() * (await Categories.count())),
|
|
});
|
|
const CoffeeBlend1 = await CoffeeBlends.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (CoffeeBlend1?.setCategory) {
|
|
await CoffeeBlend1.setCategory(relatedCategory1);
|
|
}
|
|
|
|
const relatedCategory2 = await Categories.findOne({
|
|
offset: Math.floor(Math.random() * (await Categories.count())),
|
|
});
|
|
const CoffeeBlend2 = await CoffeeBlends.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (CoffeeBlend2?.setCategory) {
|
|
await CoffeeBlend2.setCategory(relatedCategory2);
|
|
}
|
|
|
|
const relatedCategory3 = await Categories.findOne({
|
|
offset: Math.floor(Math.random() * (await Categories.count())),
|
|
});
|
|
const CoffeeBlend3 = await CoffeeBlends.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (CoffeeBlend3?.setCategory) {
|
|
await CoffeeBlend3.setCategory(relatedCategory3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateOrderWithCustomer() {
|
|
const relatedCustomer0 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Order0 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Order0?.setCustomer) {
|
|
await Order0.setCustomer(relatedCustomer0);
|
|
}
|
|
|
|
const relatedCustomer1 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Order1 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Order1?.setCustomer) {
|
|
await Order1.setCustomer(relatedCustomer1);
|
|
}
|
|
|
|
const relatedCustomer2 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Order2 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Order2?.setCustomer) {
|
|
await Order2.setCustomer(relatedCustomer2);
|
|
}
|
|
|
|
const relatedCustomer3 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Order3 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Order3?.setCustomer) {
|
|
await Order3.setCustomer(relatedCustomer3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associatePaymentWithOrder() {
|
|
const relatedOrder0 = await Orders.findOne({
|
|
offset: Math.floor(Math.random() * (await Orders.count())),
|
|
});
|
|
const Payment0 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Payment0?.setOrder) {
|
|
await Payment0.setOrder(relatedOrder0);
|
|
}
|
|
|
|
const relatedOrder1 = await Orders.findOne({
|
|
offset: Math.floor(Math.random() * (await Orders.count())),
|
|
});
|
|
const Payment1 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Payment1?.setOrder) {
|
|
await Payment1.setOrder(relatedOrder1);
|
|
}
|
|
|
|
const relatedOrder2 = await Orders.findOne({
|
|
offset: Math.floor(Math.random() * (await Orders.count())),
|
|
});
|
|
const Payment2 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Payment2?.setOrder) {
|
|
await Payment2.setOrder(relatedOrder2);
|
|
}
|
|
|
|
const relatedOrder3 = await Orders.findOne({
|
|
offset: Math.floor(Math.random() * (await Orders.count())),
|
|
});
|
|
const Payment3 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Payment3?.setOrder) {
|
|
await Payment3.setOrder(relatedOrder3);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Categories.bulkCreate(CategoriesData);
|
|
|
|
await CoffeeBlends.bulkCreate(CoffeeBlendsData);
|
|
|
|
await Customers.bulkCreate(CustomersData);
|
|
|
|
await Orders.bulkCreate(OrdersData);
|
|
|
|
await Payments.bulkCreate(PaymentsData);
|
|
|
|
await Reports.bulkCreate(ReportsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateCoffeeBlendWithCategory(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateOrderWithCustomer(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associatePaymentWithOrder(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('categories', null, {});
|
|
|
|
await queryInterface.bulkDelete('coffee_blends', null, {});
|
|
|
|
await queryInterface.bulkDelete('customers', null, {});
|
|
|
|
await queryInterface.bulkDelete('orders', null, {});
|
|
|
|
await queryInterface.bulkDelete('payments', null, {});
|
|
|
|
await queryInterface.bulkDelete('reports', null, {});
|
|
},
|
|
};
|