const db = require('../models'); const Users = db.users; const Categories = db.categories; const OrderItems = db.order_items; const Orders = db.orders; const Products = db.products; const Locations = db.locations; const CategoriesData = [ { name: 'Cold Drinks', // type code here for "relation_many" field // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Hot Drinks', // type code here for "relation_many" field // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Pastries', // type code here for "relation_many" field // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Food', // type code here for "relation_many" field // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Desserts', // type code here for "relation_many" field // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const OrderItemsData = [ { // type code here for "relation_one" field quantity: 2, total_price: 9, // type code here for "relation_one" field }, { // type code here for "relation_one" field quantity: 1, total_price: 3.5, // type code here for "relation_one" field }, { // type code here for "relation_one" field quantity: 3, total_price: 6, // type code here for "relation_one" field }, { // type code here for "relation_one" field quantity: 1, total_price: 5, // type code here for "relation_one" field }, { // type code here for "relation_one" field quantity: 2, total_price: 6, // type code here for "relation_one" field }, ]; const OrdersData = [ { // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_many" field order_date: new Date('2023-10-01T10:00:00Z'), status: 'inpreparation', // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_many" field order_date: new Date('2023-10-01T11:00:00Z'), status: 'inpreparation', // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_many" field order_date: new Date('2023-10-01T12:00:00Z'), status: 'ready', // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_many" field order_date: new Date('2023-10-01T13:00:00Z'), status: 'served', // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_many" field order_date: new Date('2023-10-01T14:00:00Z'), status: 'served', // type code here for "relation_one" field }, ]; const ProductsData = [ { name: 'Iced Latte', price: 4.5, description: 'Chilled espresso with milk', // type code here for "images" field // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Cappuccino', price: 3.5, description: 'Espresso with steamed milk foam', // type code here for "images" field // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Croissant', price: 2, description: 'Buttery flaky pastry', // type code here for "images" field // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Grilled Cheese Sandwich', price: 5, description: 'Cheese melted between toasted bread', // type code here for "images" field // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Chocolate Cake', price: 3, description: 'Rich chocolate layered cake', // type code here for "images" field // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const LocationsData = [ { name: 'Downtown Cafe', }, { name: 'Uptown Bistro', }, { name: 'Seaside Diner', }, { name: 'Mountain Retreat', }, { name: 'City Central Eatery', }, ]; // Similar logic for "relation_many" async function associateUserWithLocation() { const relatedLocation0 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const User0 = await Users.findOne({ order: [['id', 'ASC']], offset: 0, }); if (User0?.setLocation) { await User0.setLocation(relatedLocation0); } const relatedLocation1 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const User1 = await Users.findOne({ order: [['id', 'ASC']], offset: 1, }); if (User1?.setLocation) { await User1.setLocation(relatedLocation1); } const relatedLocation2 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const User2 = await Users.findOne({ order: [['id', 'ASC']], offset: 2, }); if (User2?.setLocation) { await User2.setLocation(relatedLocation2); } const relatedLocation3 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const User3 = await Users.findOne({ order: [['id', 'ASC']], offset: 3, }); if (User3?.setLocation) { await User3.setLocation(relatedLocation3); } const relatedLocation4 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const User4 = await Users.findOne({ order: [['id', 'ASC']], offset: 4, }); if (User4?.setLocation) { await User4.setLocation(relatedLocation4); } } // Similar logic for "relation_many" async function associateCategoryWithLocation() { const relatedLocation0 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Category0 = await Categories.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Category0?.setLocation) { await Category0.setLocation(relatedLocation0); } const relatedLocation1 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Category1 = await Categories.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Category1?.setLocation) { await Category1.setLocation(relatedLocation1); } const relatedLocation2 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Category2 = await Categories.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Category2?.setLocation) { await Category2.setLocation(relatedLocation2); } const relatedLocation3 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Category3 = await Categories.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Category3?.setLocation) { await Category3.setLocation(relatedLocation3); } const relatedLocation4 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Category4 = await Categories.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Category4?.setLocation) { await Category4.setLocation(relatedLocation4); } } async function associateCategoryWithLocation() { const relatedLocation0 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Category0 = await Categories.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Category0?.setLocation) { await Category0.setLocation(relatedLocation0); } const relatedLocation1 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Category1 = await Categories.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Category1?.setLocation) { await Category1.setLocation(relatedLocation1); } const relatedLocation2 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Category2 = await Categories.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Category2?.setLocation) { await Category2.setLocation(relatedLocation2); } const relatedLocation3 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Category3 = await Categories.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Category3?.setLocation) { await Category3.setLocation(relatedLocation3); } const relatedLocation4 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Category4 = await Categories.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Category4?.setLocation) { await Category4.setLocation(relatedLocation4); } } async function associateOrderItemWithProduct() { const relatedProduct0 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const OrderItem0 = await OrderItems.findOne({ order: [['id', 'ASC']], offset: 0, }); if (OrderItem0?.setProduct) { await OrderItem0.setProduct(relatedProduct0); } const relatedProduct1 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const OrderItem1 = await OrderItems.findOne({ order: [['id', 'ASC']], offset: 1, }); if (OrderItem1?.setProduct) { await OrderItem1.setProduct(relatedProduct1); } const relatedProduct2 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const OrderItem2 = await OrderItems.findOne({ order: [['id', 'ASC']], offset: 2, }); if (OrderItem2?.setProduct) { await OrderItem2.setProduct(relatedProduct2); } const relatedProduct3 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const OrderItem3 = await OrderItems.findOne({ order: [['id', 'ASC']], offset: 3, }); if (OrderItem3?.setProduct) { await OrderItem3.setProduct(relatedProduct3); } const relatedProduct4 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const OrderItem4 = await OrderItems.findOne({ order: [['id', 'ASC']], offset: 4, }); if (OrderItem4?.setProduct) { await OrderItem4.setProduct(relatedProduct4); } } async function associateOrderItemWithLocation() { const relatedLocation0 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const OrderItem0 = await OrderItems.findOne({ order: [['id', 'ASC']], offset: 0, }); if (OrderItem0?.setLocation) { await OrderItem0.setLocation(relatedLocation0); } const relatedLocation1 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const OrderItem1 = await OrderItems.findOne({ order: [['id', 'ASC']], offset: 1, }); if (OrderItem1?.setLocation) { await OrderItem1.setLocation(relatedLocation1); } const relatedLocation2 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const OrderItem2 = await OrderItems.findOne({ order: [['id', 'ASC']], offset: 2, }); if (OrderItem2?.setLocation) { await OrderItem2.setLocation(relatedLocation2); } const relatedLocation3 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const OrderItem3 = await OrderItems.findOne({ order: [['id', 'ASC']], offset: 3, }); if (OrderItem3?.setLocation) { await OrderItem3.setLocation(relatedLocation3); } const relatedLocation4 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const OrderItem4 = await OrderItems.findOne({ order: [['id', 'ASC']], offset: 4, }); if (OrderItem4?.setLocation) { await OrderItem4.setLocation(relatedLocation4); } } async function associateOrderWithClient() { const relatedClient0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Order0 = await Orders.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Order0?.setClient) { await Order0.setClient(relatedClient0); } const relatedClient1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Order1 = await Orders.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Order1?.setClient) { await Order1.setClient(relatedClient1); } const relatedClient2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Order2 = await Orders.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Order2?.setClient) { await Order2.setClient(relatedClient2); } const relatedClient3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Order3 = await Orders.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Order3?.setClient) { await Order3.setClient(relatedClient3); } const relatedClient4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Order4 = await Orders.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Order4?.setClient) { await Order4.setClient(relatedClient4); } } async function associateOrderWithLocation() { const relatedLocation0 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Order0 = await Orders.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Order0?.setLocation) { await Order0.setLocation(relatedLocation0); } const relatedLocation1 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Order1 = await Orders.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Order1?.setLocation) { await Order1.setLocation(relatedLocation1); } const relatedLocation2 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Order2 = await Orders.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Order2?.setLocation) { await Order2.setLocation(relatedLocation2); } const relatedLocation3 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Order3 = await Orders.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Order3?.setLocation) { await Order3.setLocation(relatedLocation3); } const relatedLocation4 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Order4 = await Orders.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Order4?.setLocation) { await Order4.setLocation(relatedLocation4); } } // Similar logic for "relation_many" async function associateOrderWithLocation() { const relatedLocation0 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Order0 = await Orders.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Order0?.setLocation) { await Order0.setLocation(relatedLocation0); } const relatedLocation1 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Order1 = await Orders.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Order1?.setLocation) { await Order1.setLocation(relatedLocation1); } const relatedLocation2 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Order2 = await Orders.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Order2?.setLocation) { await Order2.setLocation(relatedLocation2); } const relatedLocation3 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Order3 = await Orders.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Order3?.setLocation) { await Order3.setLocation(relatedLocation3); } const relatedLocation4 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Order4 = await Orders.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Order4?.setLocation) { await Order4.setLocation(relatedLocation4); } } async function associateProductWithCategory() { const relatedCategory0 = await Categories.findOne({ offset: Math.floor(Math.random() * (await Categories.count())), }); const Product0 = await Products.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Product0?.setCategory) { await Product0.setCategory(relatedCategory0); } const relatedCategory1 = await Categories.findOne({ offset: Math.floor(Math.random() * (await Categories.count())), }); const Product1 = await Products.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Product1?.setCategory) { await Product1.setCategory(relatedCategory1); } const relatedCategory2 = await Categories.findOne({ offset: Math.floor(Math.random() * (await Categories.count())), }); const Product2 = await Products.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Product2?.setCategory) { await Product2.setCategory(relatedCategory2); } const relatedCategory3 = await Categories.findOne({ offset: Math.floor(Math.random() * (await Categories.count())), }); const Product3 = await Products.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Product3?.setCategory) { await Product3.setCategory(relatedCategory3); } const relatedCategory4 = await Categories.findOne({ offset: Math.floor(Math.random() * (await Categories.count())), }); const Product4 = await Products.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Product4?.setCategory) { await Product4.setCategory(relatedCategory4); } } async function associateProductWithLocation() { const relatedLocation0 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Product0 = await Products.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Product0?.setLocation) { await Product0.setLocation(relatedLocation0); } const relatedLocation1 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Product1 = await Products.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Product1?.setLocation) { await Product1.setLocation(relatedLocation1); } const relatedLocation2 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Product2 = await Products.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Product2?.setLocation) { await Product2.setLocation(relatedLocation2); } const relatedLocation3 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Product3 = await Products.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Product3?.setLocation) { await Product3.setLocation(relatedLocation3); } const relatedLocation4 = await Locations.findOne({ offset: Math.floor(Math.random() * (await Locations.count())), }); const Product4 = await Products.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Product4?.setLocation) { await Product4.setLocation(relatedLocation4); } } module.exports = { up: async (queryInterface, Sequelize) => { await Categories.bulkCreate(CategoriesData); await OrderItems.bulkCreate(OrderItemsData); await Orders.bulkCreate(OrdersData); await Products.bulkCreate(ProductsData); await Locations.bulkCreate(LocationsData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithLocation(), // Similar logic for "relation_many" await associateCategoryWithLocation(), await associateCategoryWithLocation(), await associateOrderItemWithProduct(), await associateOrderItemWithLocation(), await associateOrderWithClient(), await associateOrderWithLocation(), // Similar logic for "relation_many" await associateOrderWithLocation(), await associateProductWithCategory(), await associateProductWithLocation(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('categories', null, {}); await queryInterface.bulkDelete('order_items', null, {}); await queryInterface.bulkDelete('orders', null, {}); await queryInterface.bulkDelete('products', null, {}); await queryInterface.bulkDelete('locations', null, {}); }, };