const db = require('../models'); const Users = db.users; const InventoryLevels = db.inventory_levels; const ProductMasterData = db.product_master_data; const PurchaseOrders = db.purchase_orders; const Transactions = db.transactions; const InventoryLevelsData = [ { part_number: 'P-1001', part_description: 'High-quality steel bolts', current_inventory_units: 500, }, { part_number: 'P-1002', part_description: 'Industrial-grade nuts', current_inventory_units: 300, }, { part_number: 'P-1003', part_description: 'Heavy-duty washers', current_inventory_units: 400, }, { part_number: 'P-1004', part_description: 'Precision screws', current_inventory_units: 250, }, { part_number: 'P-1005', part_description: 'Durable hinges', current_inventory_units: 150, }, ]; const ProductMasterDataData = [ { part_number: 'P-1001', part_description: 'High-quality steel bolts', stocked_status: 'NotStocked', lead_time: 10, required_service_level: 95, cost_of_product: 1.5, holding_cost: 0.1, ordering_cost: 5, }, { part_number: 'P-1002', part_description: 'Industrial-grade nuts', stocked_status: 'Stocked', lead_time: 15, required_service_level: 90, cost_of_product: 0.8, holding_cost: 0.05, ordering_cost: 4, }, { part_number: 'P-1003', part_description: 'Heavy-duty washers', stocked_status: 'Stocked', lead_time: 20, required_service_level: 92, cost_of_product: 0.5, holding_cost: 0.03, ordering_cost: 3, }, { part_number: 'P-1004', part_description: 'Precision screws', stocked_status: 'Stocked', lead_time: 12, required_service_level: 95, cost_of_product: 2, holding_cost: 0.15, ordering_cost: 6, }, { part_number: 'P-1005', part_description: 'Durable hinges', stocked_status: 'Stocked', lead_time: 18, required_service_level: 88, cost_of_product: 1.2, holding_cost: 0.08, ordering_cost: 4.5, }, ]; const PurchaseOrdersData = [ { part_number: 'P-1001', po_quantity: 200, // type code here for "relation_one" field }, { part_number: 'P-1002', po_quantity: 150, // type code here for "relation_one" field }, { part_number: 'P-1003', po_quantity: 100, // type code here for "relation_one" field }, { part_number: 'P-1004', po_quantity: 250, // type code here for "relation_one" field }, { part_number: 'P-1005', po_quantity: 300, // type code here for "relation_one" field }, ]; const TransactionsData = [ { part_number: 'P-1001', part_description: 'High-quality steel bolts', demand_date: new Date('2023-10-01T00:00:00Z'), demand_units: 150, }, { part_number: 'P-1002', part_description: 'Industrial-grade nuts', demand_date: new Date('2023-10-05T00:00:00Z'), demand_units: 200, }, { part_number: 'P-1003', part_description: 'Heavy-duty washers', demand_date: new Date('2023-10-10T00:00:00Z'), demand_units: 300, }, { part_number: 'P-1004', part_description: 'Precision screws', demand_date: new Date('2023-10-15T00:00:00Z'), demand_units: 250, }, { part_number: 'P-1005', part_description: 'Durable hinges', demand_date: new Date('2023-10-20T00:00:00Z'), demand_units: 100, }, ]; // Similar logic for "relation_many" async function associatePurchaseOrderWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const PurchaseOrder0 = await PurchaseOrders.findOne({ order: [['id', 'ASC']], offset: 0, }); if (PurchaseOrder0?.setUser) { await PurchaseOrder0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const PurchaseOrder1 = await PurchaseOrders.findOne({ order: [['id', 'ASC']], offset: 1, }); if (PurchaseOrder1?.setUser) { await PurchaseOrder1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const PurchaseOrder2 = await PurchaseOrders.findOne({ order: [['id', 'ASC']], offset: 2, }); if (PurchaseOrder2?.setUser) { await PurchaseOrder2.setUser(relatedUser2); } const relatedUser3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const PurchaseOrder3 = await PurchaseOrders.findOne({ order: [['id', 'ASC']], offset: 3, }); if (PurchaseOrder3?.setUser) { await PurchaseOrder3.setUser(relatedUser3); } const relatedUser4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const PurchaseOrder4 = await PurchaseOrders.findOne({ order: [['id', 'ASC']], offset: 4, }); if (PurchaseOrder4?.setUser) { await PurchaseOrder4.setUser(relatedUser4); } } module.exports = { up: async (queryInterface, Sequelize) => { await InventoryLevels.bulkCreate(InventoryLevelsData); await ProductMasterData.bulkCreate(ProductMasterDataData); await PurchaseOrders.bulkCreate(PurchaseOrdersData); await Transactions.bulkCreate(TransactionsData); await Promise.all([ // Similar logic for "relation_many" await associatePurchaseOrderWithUser(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('inventory_levels', null, {}); await queryInterface.bulkDelete('product_master_data', null, {}); await queryInterface.bulkDelete('purchase_orders', null, {}); await queryInterface.bulkDelete('transactions', null, {}); }, };