const db = require('../models'); const Users = db.users; const Customers = db.customers; const Products = db.products; const Suppliers = db.suppliers; const Tabs = db.tabs; const TabItems = db.tab_items; const Payments = db.payments; const Purchases = db.purchases; const CustomersData = [ { "name": "Oliver Hayes", "email": "oliver.hayes@example.com", "phone": "+1-303-555-0101", "notes": "Frequent weekend visitor", "preferred_payment": "Card", "total_tabs": 12, }, { "name": "Chloe Nguyen", "email": "chloe.nguyen@example.com", "phone": "+1-303-555-0102", "notes": "Allergic to nuts, prefers gin", "preferred_payment": "Tab", "total_tabs": 5, }, { "name": "Ethan Brooks", "email": "ethan.brooks@example.com", "phone": "+1-303-555-0103", "notes": "Prefers window seat", "preferred_payment": "Cash", "total_tabs": 3, }, ]; const ProductsData = [ { "name": "Hookar Pale Ale", "sku": "HP-0001", "description": "House pale ale with citrus notes", "price": 6.5, "cost": 2.2, "stock": 120, "low_stock_threshold": 20, // type code here for "images" field // type code here for "relation_one" field }, { "name": "Classic Gin", "sku": "CG-0100", "description": "Dry gin ideal for classic cocktails", "price": 8.5, "cost": 3.5, "stock": 40, "low_stock_threshold": 10, // type code here for "images" field // type code here for "relation_one" field }, { "name": "Lime Mixer 1L", "sku": "MX-2001", "description": "Premium lime mixer for cocktails", "price": 3.0, "cost": 0.8, "stock": 75, "low_stock_threshold": 15, // type code here for "images" field // type code here for "relation_one" field }, ]; const SuppliersData = [ { "name": "Coastal Spirits Co", "email": "sales@coastalspirits.com", "phone": "+1-800-555-1001", "address": "120 Harbor Drive, Suite 200, Portland, OR", "notes": "Primary craft spirits supplier", "lead_time_days": 3, }, { "name": "Evergreen Distributors", "email": "orders@evergreendist.com", "phone": "+1-800-555-1002", "address": "45 Industrial Way, Seattle, WA", "notes": "Bulk beer deliveries", "lead_time_days": 5, }, { "name": "Citrus Mixers Ltd", "email": "contact@citrusmixers.com", "phone": "+1-800-555-1003", "address": "9 Orchard Lane, Irvine, CA", "notes": "Mixers and garnishes", "lead_time_days": 2, }, ]; const TabsData = [ { "code": "TAB-1001", // type code here for "relation_one" field // type code here for "relation_one" field "opened_at": new Date('2025-11-20T19:20:00Z'), "closed_at": new Date(Date.now()), "status": "closed", "total": 18.5, "notes": "Group of three at corner table", }, { "code": "TAB-1002", // type code here for "relation_one" field // type code here for "relation_one" field "opened_at": new Date('2025-11-19T21:05:00Z'), "closed_at": new Date('2025-11-19T22:30:00Z'), "status": "closed", "total": 45.0, "notes": "Birthday celebration", }, { "code": "TAB-1003", // type code here for "relation_one" field // type code here for "relation_one" field "opened_at": new Date('2025-11-18T18:00:00Z'), "closed_at": new Date('2025-11-18T19:15:00Z'), "status": "open", "total": 12.0, "notes": "Solo customer", }, ]; const TabItemsData = [ { "product_name": "Hookar Pale Ale", // type code here for "relation_one" field // type code here for "relation_one" field "quantity": 2, "unit_price": 6.5, "total_price": 13.0, "notes": "", }, { "product_name": "Classic Gin", // type code here for "relation_one" field // type code here for "relation_one" field "quantity": 3, "unit_price": 8.5, "total_price": 25.5, "notes": "Two martinis, one neat", }, { "product_name": "Lime Mixer 1L", // type code here for "relation_one" field // type code here for "relation_one" field "quantity": 1, "unit_price": 3.0, "total_price": 3.0, "notes": "Mixer for cocktail", }, ]; const PaymentsData = [ { "reference": "PAY-2001", "amount": 18.5, "method": "Cash", "paid_at": new Date('2025-11-20T21:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, { "reference": "PAY-2002", "amount": 45.0, "method": "Card", "paid_at": new Date('2025-11-19T22:35:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, { "reference": "PAY-2003", "amount": 12.0, "method": "Card", "paid_at": new Date('2025-11-18T19:20:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const PurchasesData = [ { "reference": "PO-3001", // type code here for "relation_one" field "expected_at": new Date('2025-11-25T09:00:00Z'), "received_at": new Date('2025-11-25T12:30:00Z'), // type code here for "relation_one" field "total_cost": 420.0, "notes": "Monthly spirits restock", }, { "reference": "PO-3002", // type code here for "relation_one" field "expected_at": new Date('2025-11-23T08:00:00Z'), "received_at": new Date('2025-11-23T10:00:00Z'), // type code here for "relation_one" field "total_cost": 210.0, "notes": "Beer kegs delivery", }, { "reference": "PO-3003", // type code here for "relation_one" field "expected_at": new Date('2025-11-22T07:30:00Z'), "received_at": new Date('2025-11-22T09:00:00Z'), // type code here for "relation_one" field "total_cost": 65.0, "notes": "Mixers and garnishes", }, ]; // Similar logic for "relation_many" async function associateProductWithSupplier() { const relatedSupplier0 = await Suppliers.findOne({ offset: Math.floor(Math.random() * (await Suppliers.count())), }); const Product0 = await Products.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Product0?.setSupplier) { await Product0. setSupplier(relatedSupplier0); } const relatedSupplier1 = await Suppliers.findOne({ offset: Math.floor(Math.random() * (await Suppliers.count())), }); const Product1 = await Products.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Product1?.setSupplier) { await Product1. setSupplier(relatedSupplier1); } const relatedSupplier2 = await Suppliers.findOne({ offset: Math.floor(Math.random() * (await Suppliers.count())), }); const Product2 = await Products.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Product2?.setSupplier) { await Product2. setSupplier(relatedSupplier2); } } async function associateTabWithCustomer() { const relatedCustomer0 = await Customers.findOne({ offset: Math.floor(Math.random() * (await Customers.count())), }); const Tab0 = await Tabs.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Tab0?.setCustomer) { await Tab0. setCustomer(relatedCustomer0); } const relatedCustomer1 = await Customers.findOne({ offset: Math.floor(Math.random() * (await Customers.count())), }); const Tab1 = await Tabs.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Tab1?.setCustomer) { await Tab1. setCustomer(relatedCustomer1); } const relatedCustomer2 = await Customers.findOne({ offset: Math.floor(Math.random() * (await Customers.count())), }); const Tab2 = await Tabs.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Tab2?.setCustomer) { await Tab2. setCustomer(relatedCustomer2); } } async function associateTabWithOpened_by() { const relatedOpened_by0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Tab0 = await Tabs.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Tab0?.setOpened_by) { await Tab0. setOpened_by(relatedOpened_by0); } const relatedOpened_by1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Tab1 = await Tabs.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Tab1?.setOpened_by) { await Tab1. setOpened_by(relatedOpened_by1); } const relatedOpened_by2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Tab2 = await Tabs.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Tab2?.setOpened_by) { await Tab2. setOpened_by(relatedOpened_by2); } } async function associateTabItemWithProduct() { const relatedProduct0 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const TabItem0 = await TabItems.findOne({ order: [['id', 'ASC']], offset: 0 }); if (TabItem0?.setProduct) { await TabItem0. setProduct(relatedProduct0); } const relatedProduct1 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const TabItem1 = await TabItems.findOne({ order: [['id', 'ASC']], offset: 1 }); if (TabItem1?.setProduct) { await TabItem1. setProduct(relatedProduct1); } const relatedProduct2 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const TabItem2 = await TabItems.findOne({ order: [['id', 'ASC']], offset: 2 }); if (TabItem2?.setProduct) { await TabItem2. setProduct(relatedProduct2); } } async function associateTabItemWithTab() { const relatedTab0 = await Tabs.findOne({ offset: Math.floor(Math.random() * (await Tabs.count())), }); const TabItem0 = await TabItems.findOne({ order: [['id', 'ASC']], offset: 0 }); if (TabItem0?.setTab) { await TabItem0. setTab(relatedTab0); } const relatedTab1 = await Tabs.findOne({ offset: Math.floor(Math.random() * (await Tabs.count())), }); const TabItem1 = await TabItems.findOne({ order: [['id', 'ASC']], offset: 1 }); if (TabItem1?.setTab) { await TabItem1. setTab(relatedTab1); } const relatedTab2 = await Tabs.findOne({ offset: Math.floor(Math.random() * (await Tabs.count())), }); const TabItem2 = await TabItems.findOne({ order: [['id', 'ASC']], offset: 2 }); if (TabItem2?.setTab) { await TabItem2. setTab(relatedTab2); } } async function associatePaymentWithReceived_by() { const relatedReceived_by0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Payment0 = await Payments.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Payment0?.setReceived_by) { await Payment0. setReceived_by(relatedReceived_by0); } const relatedReceived_by1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Payment1 = await Payments.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Payment1?.setReceived_by) { await Payment1. setReceived_by(relatedReceived_by1); } const relatedReceived_by2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Payment2 = await Payments.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Payment2?.setReceived_by) { await Payment2. setReceived_by(relatedReceived_by2); } } async function associatePaymentWithTab() { const relatedTab0 = await Tabs.findOne({ offset: Math.floor(Math.random() * (await Tabs.count())), }); const Payment0 = await Payments.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Payment0?.setTab) { await Payment0. setTab(relatedTab0); } const relatedTab1 = await Tabs.findOne({ offset: Math.floor(Math.random() * (await Tabs.count())), }); const Payment1 = await Payments.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Payment1?.setTab) { await Payment1. setTab(relatedTab1); } const relatedTab2 = await Tabs.findOne({ offset: Math.floor(Math.random() * (await Tabs.count())), }); const Payment2 = await Payments.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Payment2?.setTab) { await Payment2. setTab(relatedTab2); } } async function associatePurchasWithSupplier() { const relatedSupplier0 = await Suppliers.findOne({ offset: Math.floor(Math.random() * (await Suppliers.count())), }); const Purchas0 = await Purchases.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Purchas0?.setSupplier) { await Purchas0. setSupplier(relatedSupplier0); } const relatedSupplier1 = await Suppliers.findOne({ offset: Math.floor(Math.random() * (await Suppliers.count())), }); const Purchas1 = await Purchases.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Purchas1?.setSupplier) { await Purchas1. setSupplier(relatedSupplier1); } const relatedSupplier2 = await Suppliers.findOne({ offset: Math.floor(Math.random() * (await Suppliers.count())), }); const Purchas2 = await Purchases.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Purchas2?.setSupplier) { await Purchas2. setSupplier(relatedSupplier2); } } async function associatePurchasWithReceived_by() { const relatedReceived_by0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Purchas0 = await Purchases.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Purchas0?.setReceived_by) { await Purchas0. setReceived_by(relatedReceived_by0); } const relatedReceived_by1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Purchas1 = await Purchases.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Purchas1?.setReceived_by) { await Purchas1. setReceived_by(relatedReceived_by1); } const relatedReceived_by2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Purchas2 = await Purchases.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Purchas2?.setReceived_by) { await Purchas2. setReceived_by(relatedReceived_by2); } } module.exports = { up: async (queryInterface, Sequelize) => { await Customers.bulkCreate(CustomersData); await Products.bulkCreate(ProductsData); await Suppliers.bulkCreate(SuppliersData); await Tabs.bulkCreate(TabsData); await TabItems.bulkCreate(TabItemsData); await Payments.bulkCreate(PaymentsData); await Purchases.bulkCreate(PurchasesData); await Promise.all([ // Similar logic for "relation_many" await associateProductWithSupplier(), await associateTabWithCustomer(), await associateTabWithOpened_by(), await associateTabItemWithProduct(), await associateTabItemWithTab(), await associatePaymentWithReceived_by(), await associatePaymentWithTab(), await associatePurchasWithSupplier(), await associatePurchasWithReceived_by(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('customers', null, {}); await queryInterface.bulkDelete('products', null, {}); await queryInterface.bulkDelete('suppliers', null, {}); await queryInterface.bulkDelete('tabs', null, {}); await queryInterface.bulkDelete('tab_items', null, {}); await queryInterface.bulkDelete('payments', null, {}); await queryInterface.bulkDelete('purchases', null, {}); }, };