const db = require('../models'); const Users = db.users; const EcommerceSites = db.ecommerce_sites; const Notifications = db.notifications; const PriceComparisons = db.price_comparisons; const Products = db.products; const EcommerceSitesData = [ { site_name: 'Amazon', url: 'https://www.amazon.com', login_credentials: 'user:pass', // type code here for "relation_many" field }, { site_name: 'eBay', url: 'https://www.ebay.com', login_credentials: 'user:pass', // type code here for "relation_many" field }, { site_name: 'Walmart', url: 'https://www.walmart.com', login_credentials: 'user:pass', // type code here for "relation_many" field }, { site_name: 'Best Buy', url: 'https://www.bestbuy.com', login_credentials: 'user:pass', // type code here for "relation_many" field }, ]; const NotificationsData = [ { // type code here for "relation_one" field // type code here for "relation_one" field notification_date: new Date('2023-10-01T15:00:00Z'), message: 'Price drop detected for Apple iPhone 13', }, { // type code here for "relation_one" field // type code here for "relation_one" field notification_date: new Date('2023-10-02T16:00:00Z'), message: 'Price drop detected for Samsung Galaxy S21', }, { // type code here for "relation_one" field // type code here for "relation_one" field notification_date: new Date('2023-10-03T17:00:00Z'), message: 'Price drop detected for Sony WH-1000XM4', }, { // type code here for "relation_one" field // type code here for "relation_one" field notification_date: new Date('2023-10-04T18:00:00Z'), message: 'Price drop detected for Dell XPS 13', }, ]; const PriceComparisonsData = [ { // type code here for "relation_one" field current_price: 799.99, comparison_date: new Date('2023-10-01T10:00:00Z'), }, { // type code here for "relation_one" field current_price: 699.99, comparison_date: new Date('2023-10-02T11:00:00Z'), }, { // type code here for "relation_one" field current_price: 349.99, comparison_date: new Date('2023-10-03T12:00:00Z'), }, { // type code here for "relation_one" field current_price: 999.99, comparison_date: new Date('2023-10-04T13:00:00Z'), }, ]; const ProductsData = [ { product_name: 'Apple iPhone 13', product_url: 'https://www.amazon.com/iphone13', price_threshold: 799.99, // type code here for "relation_one" field }, { product_name: 'Samsung Galaxy S21', product_url: 'https://www.ebay.com/galaxys21', price_threshold: 699.99, // type code here for "relation_one" field }, { product_name: 'Sony WH-1000XM4', product_url: 'https://www.walmart.com/sonyheadphones', price_threshold: 349.99, // type code here for "relation_one" field }, { product_name: 'Dell XPS 13', product_url: 'https://www.bestbuy.com/dellxps13', price_threshold: 999.99, // type code here for "relation_one" field }, ]; // 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); } } async function associateNotificationWithProduct() { const relatedProduct0 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Notification0 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Notification0?.setProduct) { await Notification0.setProduct(relatedProduct0); } const relatedProduct1 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Notification1 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Notification1?.setProduct) { await Notification1.setProduct(relatedProduct1); } const relatedProduct2 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Notification2 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Notification2?.setProduct) { await Notification2.setProduct(relatedProduct2); } const relatedProduct3 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const Notification3 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Notification3?.setProduct) { await Notification3.setProduct(relatedProduct3); } } async function associatePriceComparisonWithProduct() { const relatedProduct0 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const PriceComparison0 = await PriceComparisons.findOne({ order: [['id', 'ASC']], offset: 0, }); if (PriceComparison0?.setProduct) { await PriceComparison0.setProduct(relatedProduct0); } const relatedProduct1 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const PriceComparison1 = await PriceComparisons.findOne({ order: [['id', 'ASC']], offset: 1, }); if (PriceComparison1?.setProduct) { await PriceComparison1.setProduct(relatedProduct1); } const relatedProduct2 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const PriceComparison2 = await PriceComparisons.findOne({ order: [['id', 'ASC']], offset: 2, }); if (PriceComparison2?.setProduct) { await PriceComparison2.setProduct(relatedProduct2); } const relatedProduct3 = await Products.findOne({ offset: Math.floor(Math.random() * (await Products.count())), }); const PriceComparison3 = await PriceComparisons.findOne({ order: [['id', 'ASC']], offset: 3, }); if (PriceComparison3?.setProduct) { await PriceComparison3.setProduct(relatedProduct3); } } async function associateProductWithEcommerce_site() { const relatedEcommerce_site0 = await EcommerceSites.findOne({ offset: Math.floor(Math.random() * (await EcommerceSites.count())), }); const Product0 = await Products.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Product0?.setEcommerce_site) { await Product0.setEcommerce_site(relatedEcommerce_site0); } const relatedEcommerce_site1 = await EcommerceSites.findOne({ offset: Math.floor(Math.random() * (await EcommerceSites.count())), }); const Product1 = await Products.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Product1?.setEcommerce_site) { await Product1.setEcommerce_site(relatedEcommerce_site1); } const relatedEcommerce_site2 = await EcommerceSites.findOne({ offset: Math.floor(Math.random() * (await EcommerceSites.count())), }); const Product2 = await Products.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Product2?.setEcommerce_site) { await Product2.setEcommerce_site(relatedEcommerce_site2); } const relatedEcommerce_site3 = await EcommerceSites.findOne({ offset: Math.floor(Math.random() * (await EcommerceSites.count())), }); const Product3 = await Products.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Product3?.setEcommerce_site) { await Product3.setEcommerce_site(relatedEcommerce_site3); } } module.exports = { up: async (queryInterface, Sequelize) => { await EcommerceSites.bulkCreate(EcommerceSitesData); await Notifications.bulkCreate(NotificationsData); await PriceComparisons.bulkCreate(PriceComparisonsData); await Products.bulkCreate(ProductsData); await Promise.all([ // Similar logic for "relation_many" // Similar logic for "relation_many" await associateNotificationWithUser(), await associateNotificationWithProduct(), await associatePriceComparisonWithProduct(), await associateProductWithEcommerce_site(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('ecommerce_sites', null, {}); await queryInterface.bulkDelete('notifications', null, {}); await queryInterface.bulkDelete('price_comparisons', null, {}); await queryInterface.bulkDelete('products', null, {}); }, };