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', type: 'Seasonal', }, { name: 'Fair Trade', type: 'Seasonal', }, { name: 'Seasonal', type: 'FairTrade', }, ]; const CoffeeBlendsData = [ { name: 'Espresso Roast', price: 12.99, stock_level: 100, // type code here for "relation_many" field }, { name: 'Colombian Single-Origin', price: 14.99, stock_level: 50, // type code here for "relation_many" field }, { name: 'French Vanilla', price: 10.99, stock_level: 75, // type code here for "relation_many" 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 }, ]; 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: 'Pending', }, { // type code here for "relation_one" field // type code here for "relation_many" field order_date: new Date('2023-10-02T11:00:00Z'), status: 'Pending', }, { // type code here for "relation_one" field // type code here for "relation_many" field order_date: new Date('2023-10-03T12:00:00Z'), status: 'Shipped', }, ]; const PaymentsData = [ { // type code here for "relation_one" field amount: 25.98, status: 'Pending', payment_date: new Date('2023-10-01T15:00:00Z'), }, { // type code here for "relation_one" field amount: 14.99, status: 'Refunded', payment_date: new Date('2023-10-02T16:00:00Z'), }, { // type code here for "relation_one" field amount: 22.98, status: 'Completed', payment_date: new Date('2023-10-03T17:00:00Z'), }, ]; const ReportsData = [ { generated_at: new Date('2023-10-06T20:00:00Z'), // type code here for "relation_many" field }, { generated_at: new Date('2023-10-07T21:00:00Z'), // type code here for "relation_many" field }, { generated_at: new Date('2023-10-08T22:00:00Z'), // type code here for "relation_many" field }, ]; // Similar logic for "relation_many" // Similar logic for "relation_many" // 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); } } // 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); } } // Similar logic for "relation_many" 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" // Similar logic for "relation_many" // Similar logic for "relation_many" await associateOrderWithCustomer(), // Similar logic for "relation_many" await associatePaymentWithOrder(), // Similar logic for "relation_many" ]); }, 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, {}); }, };