const db = require('../models'); const Users = db.users; const Briefs = db.briefs; const Campaigns = db.campaigns; const Creators = db.creators; const Merchants = db.merchants; const Notifications = db.notifications; const Payments = db.payments; const Organizations = db.organizations; const BriefsData = [ { content: 'Create a vibrant post showcasing our summer sale.', // type code here for "relation_one" field // type code here for "relation_one" field }, { content: 'Highlight the features of our new tech gadget.', // type code here for "relation_one" field // type code here for "relation_one" field }, { content: 'Capture the essence of our latest fashion line.', // type code here for "relation_one" field // type code here for "relation_one" field }, { content: 'Promote our fitness challenge with engaging visuals.', // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const CampaignsData = [ { title: 'Summer Sale', start_date: new Date('2023-06-01T00:00:00Z'), end_date: new Date('2023-06-30T23:59:59Z'), // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Tech Launch', start_date: new Date('2023-07-10T00:00:00Z'), end_date: new Date('2023-07-20T23:59:59Z'), // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Fashion Week', start_date: new Date('2023-08-15T00:00:00Z'), end_date: new Date('2023-08-25T23:59:59Z'), // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Fitness Challenge', start_date: new Date('2023-09-01T00:00:00Z'), end_date: new Date('2023-09-30T23:59:59Z'), // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const CreatorsData = [ { name: 'John Doe', location: 'New York', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Jane Smith', location: 'Los Angeles', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Emily Johnson', location: 'Chicago', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Michael Brown', location: 'Houston', // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const MerchantsData = [ { name: 'Local Bakery', industry: 'Food & Beverage', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Tech Gadgets', industry: 'Electronics', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Fashion Hub', industry: 'Apparel', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Fitness World', industry: 'Health & Fitness', // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const NotificationsData = [ { message: "Your campaign 'Summer Sale' has started.", channel: 'email', // type code here for "relation_one" field // type code here for "relation_one" field }, { message: "New brief available for 'Tech Launch'.", channel: 'in_app', // type code here for "relation_one" field // type code here for "relation_one" field }, { message: 'Payment of $150.00 has been processed.', channel: 'mobile_push', // type code here for "relation_one" field // type code here for "relation_one" field }, { message: "Your campaign 'Fashion Week' is ending soon.", channel: 'in_app', // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const PaymentsData = [ { amount: 150, payment_date: new Date('2023-06-15T00:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, { amount: 200, payment_date: new Date('2023-07-25T00:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, { amount: 175, payment_date: new Date('2023-08-30T00:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, { amount: 225, payment_date: new Date('2023-09-20T00:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const OrganizationsData = [ { name: 'Carl Gauss (Karl Friedrich Gauss)', }, { name: 'Frederick Sanger', }, { name: 'J. Robert Oppenheimer', }, { name: 'Claude Levi-Strauss', }, ]; // Similar logic for "relation_many" async function associateUserWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const User0 = await Users.findOne({ order: [['id', 'ASC']], offset: 0, }); if (User0?.setOrganization) { await User0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const User1 = await Users.findOne({ order: [['id', 'ASC']], offset: 1, }); if (User1?.setOrganization) { await User1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const User2 = await Users.findOne({ order: [['id', 'ASC']], offset: 2, }); if (User2?.setOrganization) { await User2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const User3 = await Users.findOne({ order: [['id', 'ASC']], offset: 3, }); if (User3?.setOrganization) { await User3.setOrganization(relatedOrganization3); } } async function associateBriefWithCampaign() { const relatedCampaign0 = await Campaigns.findOne({ offset: Math.floor(Math.random() * (await Campaigns.count())), }); const Brief0 = await Briefs.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Brief0?.setCampaign) { await Brief0.setCampaign(relatedCampaign0); } const relatedCampaign1 = await Campaigns.findOne({ offset: Math.floor(Math.random() * (await Campaigns.count())), }); const Brief1 = await Briefs.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Brief1?.setCampaign) { await Brief1.setCampaign(relatedCampaign1); } const relatedCampaign2 = await Campaigns.findOne({ offset: Math.floor(Math.random() * (await Campaigns.count())), }); const Brief2 = await Briefs.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Brief2?.setCampaign) { await Brief2.setCampaign(relatedCampaign2); } const relatedCampaign3 = await Campaigns.findOne({ offset: Math.floor(Math.random() * (await Campaigns.count())), }); const Brief3 = await Briefs.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Brief3?.setCampaign) { await Brief3.setCampaign(relatedCampaign3); } } async function associateBriefWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Brief0 = await Briefs.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Brief0?.setOrganization) { await Brief0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Brief1 = await Briefs.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Brief1?.setOrganization) { await Brief1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Brief2 = await Briefs.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Brief2?.setOrganization) { await Brief2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Brief3 = await Briefs.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Brief3?.setOrganization) { await Brief3.setOrganization(relatedOrganization3); } } async function associateCampaignWithMerchant() { const relatedMerchant0 = await Merchants.findOne({ offset: Math.floor(Math.random() * (await Merchants.count())), }); const Campaign0 = await Campaigns.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Campaign0?.setMerchant) { await Campaign0.setMerchant(relatedMerchant0); } const relatedMerchant1 = await Merchants.findOne({ offset: Math.floor(Math.random() * (await Merchants.count())), }); const Campaign1 = await Campaigns.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Campaign1?.setMerchant) { await Campaign1.setMerchant(relatedMerchant1); } const relatedMerchant2 = await Merchants.findOne({ offset: Math.floor(Math.random() * (await Merchants.count())), }); const Campaign2 = await Campaigns.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Campaign2?.setMerchant) { await Campaign2.setMerchant(relatedMerchant2); } const relatedMerchant3 = await Merchants.findOne({ offset: Math.floor(Math.random() * (await Merchants.count())), }); const Campaign3 = await Campaigns.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Campaign3?.setMerchant) { await Campaign3.setMerchant(relatedMerchant3); } } // Similar logic for "relation_many" async function associateCampaignWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Campaign0 = await Campaigns.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Campaign0?.setOrganization) { await Campaign0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Campaign1 = await Campaigns.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Campaign1?.setOrganization) { await Campaign1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Campaign2 = await Campaigns.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Campaign2?.setOrganization) { await Campaign2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Campaign3 = await Campaigns.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Campaign3?.setOrganization) { await Campaign3.setOrganization(relatedOrganization3); } } // Similar logic for "relation_many" async function associateCreatorWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Creator0 = await Creators.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Creator0?.setOrganization) { await Creator0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Creator1 = await Creators.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Creator1?.setOrganization) { await Creator1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Creator2 = await Creators.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Creator2?.setOrganization) { await Creator2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Creator3 = await Creators.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Creator3?.setOrganization) { await Creator3.setOrganization(relatedOrganization3); } } // Similar logic for "relation_many" async function associateMerchantWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Merchant0 = await Merchants.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Merchant0?.setOrganization) { await Merchant0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Merchant1 = await Merchants.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Merchant1?.setOrganization) { await Merchant1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Merchant2 = await Merchants.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Merchant2?.setOrganization) { await Merchant2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Merchant3 = await Merchants.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Merchant3?.setOrganization) { await Merchant3.setOrganization(relatedOrganization3); } } 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 associateNotificationWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Notification0 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Notification0?.setOrganization) { await Notification0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Notification1 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Notification1?.setOrganization) { await Notification1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Notification2 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Notification2?.setOrganization) { await Notification2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Notification3 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Notification3?.setOrganization) { await Notification3.setOrganization(relatedOrganization3); } } async function associatePaymentWithCreator() { const relatedCreator0 = await Creators.findOne({ offset: Math.floor(Math.random() * (await Creators.count())), }); const Payment0 = await Payments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Payment0?.setCreator) { await Payment0.setCreator(relatedCreator0); } const relatedCreator1 = await Creators.findOne({ offset: Math.floor(Math.random() * (await Creators.count())), }); const Payment1 = await Payments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Payment1?.setCreator) { await Payment1.setCreator(relatedCreator1); } const relatedCreator2 = await Creators.findOne({ offset: Math.floor(Math.random() * (await Creators.count())), }); const Payment2 = await Payments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Payment2?.setCreator) { await Payment2.setCreator(relatedCreator2); } const relatedCreator3 = await Creators.findOne({ offset: Math.floor(Math.random() * (await Creators.count())), }); const Payment3 = await Payments.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Payment3?.setCreator) { await Payment3.setCreator(relatedCreator3); } } async function associatePaymentWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Payment0 = await Payments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Payment0?.setOrganization) { await Payment0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Payment1 = await Payments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Payment1?.setOrganization) { await Payment1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Payment2 = await Payments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Payment2?.setOrganization) { await Payment2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Payment3 = await Payments.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Payment3?.setOrganization) { await Payment3.setOrganization(relatedOrganization3); } } module.exports = { up: async (queryInterface, Sequelize) => { await Briefs.bulkCreate(BriefsData); await Campaigns.bulkCreate(CampaignsData); await Creators.bulkCreate(CreatorsData); await Merchants.bulkCreate(MerchantsData); await Notifications.bulkCreate(NotificationsData); await Payments.bulkCreate(PaymentsData); await Organizations.bulkCreate(OrganizationsData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithOrganization(), await associateBriefWithCampaign(), await associateBriefWithOrganization(), await associateCampaignWithMerchant(), // Similar logic for "relation_many" await associateCampaignWithOrganization(), // Similar logic for "relation_many" await associateCreatorWithOrganization(), // Similar logic for "relation_many" await associateMerchantWithOrganization(), await associateNotificationWithUser(), await associateNotificationWithOrganization(), await associatePaymentWithCreator(), await associatePaymentWithOrganization(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('briefs', null, {}); await queryInterface.bulkDelete('campaigns', null, {}); await queryInterface.bulkDelete('creators', null, {}); await queryInterface.bulkDelete('merchants', null, {}); await queryInterface.bulkDelete('notifications', null, {}); await queryInterface.bulkDelete('payments', null, {}); await queryInterface.bulkDelete('organizations', null, {}); }, };