const db = require('../models'); const Users = db.users; const Cart = db.cart; const Categories = db.categories; const Notifications = db.notifications; const Orders = db.orders; const Payments = db.payments; const Products = db.products; const Reviews = db.reviews; const Variants = db.variants; const Wishlist = db.wishlist; const CartData = [ { // type code here for "relation_one" field // type code here for "relation_many" field }, { // type code here for "relation_one" field // type code here for "relation_many" field }, { // type code here for "relation_one" field // type code here for "relation_many" field }, { // type code here for "relation_one" field // type code here for "relation_many" field }, { // type code here for "relation_one" field // type code here for "relation_many" field }, ]; const CategoriesData = [ { name: 'Electronics', // type code here for "relation_many" field }, { name: 'Audio', // type code here for "relation_many" field }, { name: 'Computers', // type code here for "relation_many" field }, { name: 'Accessories', // type code here for "relation_many" field }, { name: 'Chargers', // type code here for "relation_many" field }, ]; const NotificationsData = [ { // type code here for "relation_one" field message: 'Your order has been shipped.', type: 'whatsapp', }, { // type code here for "relation_one" field message: 'Your payment was successful.', type: 'sms', }, { // type code here for "relation_one" field message: 'New product available in your wishlist category.', type: 'whatsapp', }, { // type code here for "relation_one" field message: 'Your refund has been processed.', type: 'whatsapp', }, { // type code here for "relation_one" field message: 'Special promotion on your favorite items.', type: 'email', }, ]; const OrdersData = [ { // type code here for "relation_one" field // type code here for "relation_many" field quantity: 2, shipping_address: '123 Main St, Anytown, USA', payment_status: 'completed', shipment_tracking: 'TRACK123', }, { // type code here for "relation_one" field // type code here for "relation_many" field quantity: 1, shipping_address: '456 Elm St, Othertown, USA', payment_status: 'pending', shipment_tracking: 'TRACK456', }, { // type code here for "relation_one" field // type code here for "relation_many" field quantity: 3, shipping_address: '789 Oak St, Sometown, USA', payment_status: 'failed', shipment_tracking: 'TRACK789', }, { // type code here for "relation_one" field // type code here for "relation_many" field quantity: 1, shipping_address: '101 Pine St, Newtown, USA', payment_status: 'completed', shipment_tracking: 'TRACK101', }, { // type code here for "relation_one" field // type code here for "relation_many" field quantity: 2, shipping_address: '202 Maple St, Oldtown, USA', payment_status: 'pending', shipment_tracking: 'TRACK202', }, ]; const PaymentsData = [ { // type code here for "relation_one" field amount: 59.98, method: 'credit_card', refund: true, }, { // type code here for "relation_one" field amount: 99.99, method: 'wallet', refund: false, }, { // type code here for "relation_one" field amount: 239.97, method: 'wallet', refund: true, }, { // type code here for "relation_one" field amount: 19.99, method: 'credit_card', refund: false, }, { // type code here for "relation_one" field amount: 79.98, method: 'debit_card', refund: false, }, ]; const ProductsData = [ { name: 'Wireless Mouse', description: 'Ergonomic wireless mouse with adjustable DPI.', // type code here for "images" field sku: 'WM12345', stock_quantity: 150, price: 29.99, discount: 5, rating: 4.5, // type code here for "relation_one" field // type code here for "relation_many" field }, { name: 'Bluetooth Headphones', description: 'Noise-cancelling over-ear headphones with Bluetooth connectivity.', // type code here for "images" field sku: 'BH67890', stock_quantity: 75, price: 99.99, discount: 10, rating: 4.7, // type code here for "relation_one" field // type code here for "relation_many" field }, { name: 'Gaming Keyboard', description: 'Mechanical keyboard with RGB lighting and programmable keys.', // type code here for "images" field sku: 'GK11223', stock_quantity: 200, price: 79.99, discount: 15, rating: 4.8, // type code here for "relation_one" field // type code here for "relation_many" field }, { name: 'Smartphone Stand', description: 'Adjustable stand for smartphones and tablets.', // type code here for "images" field sku: 'SS44556', stock_quantity: 300, price: 19.99, discount: 2, rating: 4.3, // type code here for "relation_one" field // type code here for "relation_many" field }, { name: 'USB-C Charger', description: 'Fast charging USB-C charger with multiple ports.', // type code here for "images" field sku: 'UC77889', stock_quantity: 250, price: 39.99, discount: 5, rating: 4.6, // type code here for "relation_one" field // type code here for "relation_many" field }, ]; const ReviewsData = [ { // type code here for "relation_one" field // type code here for "relation_one" field rating: 4.5, review: 'Great product, very comfortable to use.', }, { // type code here for "relation_one" field // type code here for "relation_one" field rating: 4.7, review: 'Excellent sound quality and battery life.', }, { // type code here for "relation_one" field // type code here for "relation_one" field rating: 4.8, review: 'Love the RGB lighting and key response.', }, { // type code here for "relation_one" field // type code here for "relation_one" field rating: 4.3, review: 'Very handy and easy to adjust.', }, { // type code here for "relation_one" field // type code here for "relation_one" field rating: 4.6, review: 'Charges my devices super fast.', }, ]; const VariantsData = [ { name: 'Small', type: 'size', // type code here for "relation_one" field }, { name: 'Medium', type: 'size', // type code here for "relation_one" field }, { name: 'Large', type: 'color', // type code here for "relation_one" field }, { name: 'Red', type: 'size', // type code here for "relation_one" field }, { name: 'Blue', type: 'color', // type code here for "relation_one" field }, ]; const WishlistData = [ { // type code here for "relation_one" field // type code here for "relation_many" field }, { // type code here for "relation_one" field // type code here for "relation_many" field }, { // type code here for "relation_one" field // type code here for "relation_many" field }, { // type code here for "relation_one" field // type code here for "relation_many" field }, { // type code here for "relation_one" field // type code here for "relation_many" field }, ]; // Similar logic for "relation_many" async function associateCartWithCustomer() { const relatedCustomer0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Cart0 = await Cart.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Cart0?.setCustomer) { await Cart0.setCustomer(relatedCustomer0); } const relatedCustomer1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Cart1 = await Cart.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Cart1?.setCustomer) { await Cart1.setCustomer(relatedCustomer1); } const relatedCustomer2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Cart2 = await Cart.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Cart2?.setCustomer) { await Cart2.setCustomer(relatedCustomer2); } const relatedCustomer3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Cart3 = await Cart.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Cart3?.setCustomer) { await Cart3.setCustomer(relatedCustomer3); } const relatedCustomer4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Cart4 = await Cart.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Cart4?.setCustomer) { await Cart4.setCustomer(relatedCustomer4); } } // Similar logic for "relation_many" // Similar logic for "relation_many" async function associateNotificationWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Notification0 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Notification0?.setUser) { await Notification0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Notification1 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Notification1?.setUser) { await Notification1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Notification2 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Notification2?.setUser) { await Notification2.setUser(relatedUser2); } const relatedUser3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Notification3 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Notification3?.setUser) { await Notification3.setUser(relatedUser3); } const relatedUser4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Notification4 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Notification4?.setUser) { await Notification4.setUser(relatedUser4); } } async function associateOrderWithCustomer() { const relatedCustomer0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Order0 = await Orders.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Order0?.setCustomer) { await Order0.setCustomer(relatedCustomer0); } const relatedCustomer1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Order1 = await Orders.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Order1?.setCustomer) { await Order1.setCustomer(relatedCustomer1); } const relatedCustomer2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Order2 = await Orders.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Order2?.setCustomer) { await Order2.setCustomer(relatedCustomer2); } const relatedCustomer3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Order3 = await Orders.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Order3?.setCustomer) { await Order3.setCustomer(relatedCustomer3); } const relatedCustomer4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Order4 = await Orders.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Order4?.setCustomer) { await Order4.setCustomer(relatedCustomer4); } } // 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); } const relatedOrder3 = await Orders.findOne({ offset: Math.floor(Math.random() * (await Orders.count())), }); const Payment3 = await Payments.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Payment3?.setOrder) { await Payment3.setOrder(relatedOrder3); } const relatedOrder4 = await Orders.findOne({ offset: Math.floor(Math.random() * (await Orders.count())), }); const Payment4 = await Payments.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Payment4?.setOrder) { await Payment4.setOrder(relatedOrder4); } } 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); } } // Similar logic for "relation_many" async function associateReviewWithProduct() { const relatedProduct0 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Review0 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Review0?.setProduct) { await Review0.setProduct(relatedProduct0); } const relatedProduct1 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Review1 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Review1?.setProduct) { await Review1.setProduct(relatedProduct1); } const relatedProduct2 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Review2 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Review2?.setProduct) { await Review2.setProduct(relatedProduct2); } const relatedProduct3 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Review3 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Review3?.setProduct) { await Review3.setProduct(relatedProduct3); } const relatedProduct4 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Review4 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Review4?.setProduct) { await Review4.setProduct(relatedProduct4); } } async function associateReviewWithCustomer() { const relatedCustomer0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Review0 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Review0?.setCustomer) { await Review0.setCustomer(relatedCustomer0); } const relatedCustomer1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Review1 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Review1?.setCustomer) { await Review1.setCustomer(relatedCustomer1); } const relatedCustomer2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Review2 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Review2?.setCustomer) { await Review2.setCustomer(relatedCustomer2); } const relatedCustomer3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Review3 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Review3?.setCustomer) { await Review3.setCustomer(relatedCustomer3); } const relatedCustomer4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Review4 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Review4?.setCustomer) { await Review4.setCustomer(relatedCustomer4); } } async function associateVariantWithProduct() { const relatedProduct0 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Variant0 = await Variants.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Variant0?.setProduct) { await Variant0.setProduct(relatedProduct0); } const relatedProduct1 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Variant1 = await Variants.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Variant1?.setProduct) { await Variant1.setProduct(relatedProduct1); } const relatedProduct2 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Variant2 = await Variants.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Variant2?.setProduct) { await Variant2.setProduct(relatedProduct2); } const relatedProduct3 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Variant3 = await Variants.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Variant3?.setProduct) { await Variant3.setProduct(relatedProduct3); } const relatedProduct4 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Variant4 = await Variants.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Variant4?.setProduct) { await Variant4.setProduct(relatedProduct4); } } async function associateWishlistWithCustomer() { const relatedCustomer0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Wishlist0 = await Wishlist.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Wishlist0?.setCustomer) { await Wishlist0.setCustomer(relatedCustomer0); } const relatedCustomer1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Wishlist1 = await Wishlist.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Wishlist1?.setCustomer) { await Wishlist1.setCustomer(relatedCustomer1); } const relatedCustomer2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Wishlist2 = await Wishlist.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Wishlist2?.setCustomer) { await Wishlist2.setCustomer(relatedCustomer2); } const relatedCustomer3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Wishlist3 = await Wishlist.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Wishlist3?.setCustomer) { await Wishlist3.setCustomer(relatedCustomer3); } const relatedCustomer4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Wishlist4 = await Wishlist.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Wishlist4?.setCustomer) { await Wishlist4.setCustomer(relatedCustomer4); } } // Similar logic for "relation_many" module.exports = { up: async (queryInterface, Sequelize) => { await Cart.bulkCreate(CartData); await Categories.bulkCreate(CategoriesData); await Notifications.bulkCreate(NotificationsData); await Orders.bulkCreate(OrdersData); await Payments.bulkCreate(PaymentsData); await Products.bulkCreate(ProductsData); await Reviews.bulkCreate(ReviewsData); await Variants.bulkCreate(VariantsData); await Wishlist.bulkCreate(WishlistData); await Promise.all([ // Similar logic for "relation_many" await associateCartWithCustomer(), // Similar logic for "relation_many" // Similar logic for "relation_many" await associateNotificationWithUser(), await associateOrderWithCustomer(), // Similar logic for "relation_many" await associatePaymentWithOrder(), await associateProductWithCategory(), // Similar logic for "relation_many" await associateReviewWithProduct(), await associateReviewWithCustomer(), await associateVariantWithProduct(), await associateWishlistWithCustomer(), // Similar logic for "relation_many" ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('cart', null, {}); await queryInterface.bulkDelete('categories', null, {}); await queryInterface.bulkDelete('notifications', null, {}); await queryInterface.bulkDelete('orders', null, {}); await queryInterface.bulkDelete('payments', null, {}); await queryInterface.bulkDelete('products', null, {}); await queryInterface.bulkDelete('reviews', null, {}); await queryInterface.bulkDelete('variants', null, {}); await queryInterface.bulkDelete('wishlist', null, {}); }, };