const db = require('../models'); const Users = db.users; const InventoryAdjustments = db.inventory_adjustments; const Products = db.products; const Sales = db.sales; const InventoryAdjustmentsData = [ { // type code here for "relation_one" field // type code here for "relation_one" field adjustment_quantity: 10, reason: 'New stock arrival', }, { // type code here for "relation_one" field // type code here for "relation_one" field adjustment_quantity: -5, reason: 'Damaged items', }, { // type code here for "relation_one" field // type code here for "relation_one" field adjustment_quantity: 15, reason: 'Stock correction', }, { // type code here for "relation_one" field // type code here for "relation_one" field adjustment_quantity: -2, reason: 'Customer return', }, { // type code here for "relation_one" field // type code here for "relation_one" field adjustment_quantity: 5, reason: 'New stock arrival', }, ]; const ProductsData = [ { name: 'Running Shoes', price: 59.99, stock_quantity: 100, }, { name: 'Basketball Sneakers', price: 89.99, stock_quantity: 50, }, { name: 'Casual Loafers', price: 39.99, stock_quantity: 75, }, { name: 'Formal Oxfords', price: 99.99, stock_quantity: 30, }, { name: 'Hiking Boots', price: 129.99, stock_quantity: 20, }, ]; const SalesData = [ { // type code here for "relation_one" field // type code here for "relation_one" field quantity: 2, total_price: 119.98, sale_date: new Date('2023-10-01T10:00:00Z'), }, { // type code here for "relation_one" field // type code here for "relation_one" field quantity: 1, total_price: 89.99, sale_date: new Date('2023-10-02T11:30:00Z'), }, { // type code here for "relation_one" field // type code here for "relation_one" field quantity: 3, total_price: 119.97, sale_date: new Date('2023-10-03T14:00:00Z'), }, { // type code here for "relation_one" field // type code here for "relation_one" field quantity: 1, total_price: 99.99, sale_date: new Date('2023-10-04T15:45:00Z'), }, { // type code here for "relation_one" field // type code here for "relation_one" field quantity: 2, total_price: 259.98, sale_date: new Date('2023-10-05T09:15:00Z'), }, ]; // Similar logic for "relation_many" async function associateInventoryAdjustmentWithProduct() { const relatedProduct0 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const InventoryAdjustment0 = await InventoryAdjustments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (InventoryAdjustment0?.setProduct) { await InventoryAdjustment0.setProduct(relatedProduct0); } const relatedProduct1 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const InventoryAdjustment1 = await InventoryAdjustments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (InventoryAdjustment1?.setProduct) { await InventoryAdjustment1.setProduct(relatedProduct1); } const relatedProduct2 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const InventoryAdjustment2 = await InventoryAdjustments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (InventoryAdjustment2?.setProduct) { await InventoryAdjustment2.setProduct(relatedProduct2); } const relatedProduct3 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const InventoryAdjustment3 = await InventoryAdjustments.findOne({ order: [['id', 'ASC']], offset: 3, }); if (InventoryAdjustment3?.setProduct) { await InventoryAdjustment3.setProduct(relatedProduct3); } const relatedProduct4 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const InventoryAdjustment4 = await InventoryAdjustments.findOne({ order: [['id', 'ASC']], offset: 4, }); if (InventoryAdjustment4?.setProduct) { await InventoryAdjustment4.setProduct(relatedProduct4); } } async function associateInventoryAdjustmentWithInventory_manager() { const relatedInventory_manager0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const InventoryAdjustment0 = await InventoryAdjustments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (InventoryAdjustment0?.setInventory_manager) { await InventoryAdjustment0.setInventory_manager(relatedInventory_manager0); } const relatedInventory_manager1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const InventoryAdjustment1 = await InventoryAdjustments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (InventoryAdjustment1?.setInventory_manager) { await InventoryAdjustment1.setInventory_manager(relatedInventory_manager1); } const relatedInventory_manager2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const InventoryAdjustment2 = await InventoryAdjustments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (InventoryAdjustment2?.setInventory_manager) { await InventoryAdjustment2.setInventory_manager(relatedInventory_manager2); } const relatedInventory_manager3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const InventoryAdjustment3 = await InventoryAdjustments.findOne({ order: [['id', 'ASC']], offset: 3, }); if (InventoryAdjustment3?.setInventory_manager) { await InventoryAdjustment3.setInventory_manager(relatedInventory_manager3); } const relatedInventory_manager4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const InventoryAdjustment4 = await InventoryAdjustments.findOne({ order: [['id', 'ASC']], offset: 4, }); if (InventoryAdjustment4?.setInventory_manager) { await InventoryAdjustment4.setInventory_manager(relatedInventory_manager4); } } async function associateSaleWithProduct() { const relatedProduct0 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Sale0 = await Sales.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Sale0?.setProduct) { await Sale0.setProduct(relatedProduct0); } const relatedProduct1 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Sale1 = await Sales.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Sale1?.setProduct) { await Sale1.setProduct(relatedProduct1); } const relatedProduct2 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Sale2 = await Sales.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Sale2?.setProduct) { await Sale2.setProduct(relatedProduct2); } const relatedProduct3 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Sale3 = await Sales.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Sale3?.setProduct) { await Sale3.setProduct(relatedProduct3); } const relatedProduct4 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Sale4 = await Sales.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Sale4?.setProduct) { await Sale4.setProduct(relatedProduct4); } } async function associateSaleWithCashier() { const relatedCashier0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Sale0 = await Sales.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Sale0?.setCashier) { await Sale0.setCashier(relatedCashier0); } const relatedCashier1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Sale1 = await Sales.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Sale1?.setCashier) { await Sale1.setCashier(relatedCashier1); } const relatedCashier2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Sale2 = await Sales.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Sale2?.setCashier) { await Sale2.setCashier(relatedCashier2); } const relatedCashier3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Sale3 = await Sales.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Sale3?.setCashier) { await Sale3.setCashier(relatedCashier3); } const relatedCashier4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Sale4 = await Sales.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Sale4?.setCashier) { await Sale4.setCashier(relatedCashier4); } } module.exports = { up: async (queryInterface, Sequelize) => { await InventoryAdjustments.bulkCreate(InventoryAdjustmentsData); await Products.bulkCreate(ProductsData); await Sales.bulkCreate(SalesData); await Promise.all([ // Similar logic for "relation_many" await associateInventoryAdjustmentWithProduct(), await associateInventoryAdjustmentWithInventory_manager(), await associateSaleWithProduct(), await associateSaleWithCashier(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('inventory_adjustments', null, {}); await queryInterface.bulkDelete('products', null, {}); await queryInterface.bulkDelete('sales', null, {}); }, };