478 lines
9.5 KiB
JavaScript
478 lines
9.5 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',
|
|
},
|
|
|
|
{
|
|
name: 'Fair Trade',
|
|
},
|
|
|
|
{
|
|
name: 'Seasonal',
|
|
},
|
|
|
|
{
|
|
name: 'Single Origin',
|
|
},
|
|
|
|
{
|
|
name: 'Espresso',
|
|
},
|
|
];
|
|
|
|
const CoffeeBlendsData = [
|
|
{
|
|
name: 'Ethiopian Yirgacheffe',
|
|
|
|
price: 12.99,
|
|
|
|
stock_level: 100,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Colombian Supremo',
|
|
|
|
price: 10.99,
|
|
|
|
stock_level: 150,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Espresso Roast',
|
|
|
|
price: 14.99,
|
|
|
|
stock_level: 200,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Guatemalan Antigua',
|
|
|
|
price: 11.99,
|
|
|
|
stock_level: 120,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Sumatra Mandheling',
|
|
|
|
price: 13.99,
|
|
|
|
stock_level: 80,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const CustomersData = [
|
|
{
|
|
full_name: 'John Doe',
|
|
|
|
email: 'john.doe@example.com',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
full_name: 'Jane Smith',
|
|
|
|
email: 'jane.smith@example.com',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
full_name: 'Alice Johnson',
|
|
|
|
email: 'alice.johnson@example.com',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
full_name: 'Bob Brown',
|
|
|
|
email: 'bob.brown@example.com',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
full_name: 'Charlie Davis',
|
|
|
|
email: 'charlie.davis@example.com',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const OrdersData = [
|
|
{
|
|
order_date: new Date('2023-10-01T10:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
order_date: new Date('2023-10-02T11:30:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
order_date: new Date('2023-10-03T14:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
order_date: new Date('2023-10-04T09:15:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
order_date: new Date('2023-10-05T16:45:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const PaymentsData = [
|
|
{
|
|
amount: 25.98,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
status: 'Refunded',
|
|
},
|
|
|
|
{
|
|
amount: 10.99,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
status: 'Refunded',
|
|
},
|
|
|
|
{
|
|
amount: 25.98,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
status: 'Pending',
|
|
},
|
|
|
|
{
|
|
amount: 14.99,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
status: 'Refunded',
|
|
},
|
|
|
|
{
|
|
amount: 23.98,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
status: 'Pending',
|
|
},
|
|
];
|
|
|
|
const ReportsData = [
|
|
{
|
|
generated_at: new Date('2023-10-06T08:00:00Z'),
|
|
|
|
report_type: 'Sales Report',
|
|
|
|
// type code here for "files" field
|
|
},
|
|
|
|
{
|
|
generated_at: new Date('2023-10-06T08:00:00Z'),
|
|
|
|
report_type: 'Customer Analysis',
|
|
|
|
// type code here for "files" field
|
|
},
|
|
|
|
{
|
|
generated_at: new Date('2023-10-06T08:00:00Z'),
|
|
|
|
report_type: 'Inventory Report',
|
|
|
|
// type code here for "files" field
|
|
},
|
|
|
|
{
|
|
generated_at: new Date('2023-10-06T08:00:00Z'),
|
|
|
|
report_type: 'Order Summary',
|
|
|
|
// type code here for "files" field
|
|
},
|
|
|
|
{
|
|
generated_at: new Date('2023-10-06T08:00:00Z'),
|
|
|
|
report_type: 'Payment Overview',
|
|
|
|
// type code here for "files" field
|
|
},
|
|
];
|
|
|
|
// 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);
|
|
}
|
|
|
|
const relatedCategory4 = await Categories.findOne({
|
|
offset: Math.floor(Math.random() * (await Categories.count())),
|
|
});
|
|
const CoffeeBlend4 = await CoffeeBlends.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (CoffeeBlend4?.setCategory) {
|
|
await CoffeeBlend4.setCategory(relatedCategory4);
|
|
}
|
|
}
|
|
|
|
// 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);
|
|
}
|
|
|
|
const relatedCustomer4 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Order4 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Order4?.setCustomer) {
|
|
await Order4.setCustomer(relatedCustomer4);
|
|
}
|
|
}
|
|
|
|
// 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);
|
|
}
|
|
|
|
const relatedOrder4 = await Orders.findOne({
|
|
offset: Math.floor(Math.random() * (await Orders.count())),
|
|
});
|
|
const Payment4 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Payment4?.setOrder) {
|
|
await Payment4.setOrder(relatedOrder4);
|
|
}
|
|
}
|
|
|
|
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, {});
|
|
},
|
|
};
|