const db = require('../models'); const Users = db.users; const Accounts = db.accounts; const Contacts = db.contacts; const Leads = db.leads; const PipelineStages = db.pipeline_stages; const Deals = db.deals; const Activities = db.activities; const Notes = db.notes; const Audiences = db.audiences; const AudienceMemberships = db.audience_memberships; const Integrations = db.integrations; const Imports = db.imports; const AccountsData = [ { "account_name": "Northwind Logistics", "domain": "northwindlogistics.com", "industry": "Logistics", "company_size": "200-500", "phone": "+1-303-555-0105", "website": "https://northwindlogistics.com", "linkedin_url": "https://www.linkedin.com/company/northwind-logistics", "address": "1200 Blake St, Denver, CO", "notes": "Regional logistics provider exploring CRM modernization.", // type code here for "relation_one" field }, { "account_name": "HelioCloud Systems", "domain": "heliocloud.io", "industry": "Cloud Infrastructure", "company_size": "50-200", "phone": "+1-408-555-0144", "website": "https://heliocloud.io", "linkedin_url": "https://www.linkedin.com/company/heliocloud-systems", "address": "85 Market St, San Jose, CA", "notes": "Growth-stage cloud vendor evaluating sales enablement tools.", // type code here for "relation_one" field }, { "account_name": "Summit Health Partners", "domain": "summithealthpartners.org", "industry": "Healthcare", "company_size": "500-1000", "phone": "+1-617-555-0117", "website": "https://summithealthpartners.org", "linkedin_url": "https://www.linkedin.com/company/summit-health-partners", "address": "14 Cambridge Center, Cambridge, MA", "notes": "Multi-clinic group with strict compliance requirements.", // type code here for "relation_one" field }, { "account_name": "Cedar & Stone Construction", "domain": "cedarstonebuild.com", "industry": "Construction", "company_size": "100-200", "phone": "+1-702-555-0163", "website": "https://cedarstonebuild.com", "linkedin_url": "https://www.linkedin.com/company/cedar-stone-construction", "address": "3300 S Las Vegas Blvd, Las Vegas, NV", "notes": "Looking to improve bid tracking and pipeline reporting.", // type code here for "relation_one" field }, { "account_name": "BlueRiver Fintech", "domain": "blueriverfintech.com", "industry": "Financial Services", "company_size": "20-50", "phone": "+1-212-555-0156", "website": "https://blueriverfintech.com", "linkedin_url": "https://www.linkedin.com/company/blueriver-fintech", "address": "77 Wall St, New York, NY", "notes": "Interested in integrations and audience syncing for retargeting.", // type code here for "relation_one" field }, ]; const ContactsData = [ { "first_name": "Jordan", "last_name": "Miles", "full_name": "Jordan Miles", "job_title": "Operations Director", "email": "jordan.miles@northwindlogistics.com", "phone": "+1-303-555-0128", "linkedin_url": "https://www.linkedin.com/in/jordan-miles-ops", "lifecycle_stage": "contact", // type code here for "relation_one" field // type code here for "relation_one" field "notes": "Primary evaluator, cares about reporting and follow-ups.", }, { "first_name": "Priya", "last_name": "Shah", "full_name": "Priya Shah", "job_title": "VP Sales", "email": "priya.shah@heliocloud.io", "phone": "+1-408-555-0191", "linkedin_url": "https://www.linkedin.com/in/priyashah-sales", "lifecycle_stage": "lead", // type code here for "relation_one" field // type code here for "relation_one" field "notes": "Wants cleaner pipeline visibility and forecasting.", }, { "first_name": "Daniel", "last_name": "Cho", "full_name": "Daniel Cho", "job_title": "IT Manager", "email": "daniel.cho@summithealthpartners.org", "phone": "+1-617-555-0139", "linkedin_url": "https://www.linkedin.com/in/daniel-cho-it", "lifecycle_stage": "lead", // type code here for "relation_one" field // type code here for "relation_one" field "notes": "Focus on security, SSO roadmap, and audit logs.", }, { "first_name": "Hannah", "last_name": "Brooks", "full_name": "Hannah Brooks", "job_title": "Procurement Lead", "email": "hannah.brooks@cedarstonebuild.com", "phone": "+1-702-555-0180", "linkedin_url": "https://www.linkedin.com/in/hannah-brooks-procurement", "lifecycle_stage": "customer", // type code here for "relation_one" field // type code here for "relation_one" field "notes": "Needs clear pricing and implementation timeline.", }, { "first_name": "Luis", "last_name": "Garcia", "full_name": "Luis Garcia", "job_title": "Head of Growth", "email": "luis.garcia@blueriverfintech.com", "phone": "+1-212-555-0193", "linkedin_url": "https://www.linkedin.com/in/luis-garcia-growth", "lifecycle_stage": "inactive", // type code here for "relation_one" field // type code here for "relation_one" field "notes": "Interested in Meta and LinkedIn retargeting workflows.", }, ]; const LeadsData = [ { "lead_name": "Taylor Jenkins", "email": "taylor.jenkins@acmeb2b.com", "phone": "+1-917-555-0110", "company_name": "Acme B2B Services", "job_title": "Sales Ops Manager", "source": "import", "status": "converted", "score": 62, "last_contacted_at": new Date('2026-03-10T15:30:00Z'), "next_follow_up_at": new Date('2026-03-20T16:00:00Z'), // type code here for "relation_one" field "notes": "Requested demo after downloading pipeline guide.", // type code here for "files" field }, { "lead_name": "Mina Farouk", "email": "mina.farouk@greenfieldai.com", "phone": "+1-650-555-0140", "company_name": "Greenfield AI", "job_title": "Revenue Analyst", "source": "event", "status": "new", "score": 71, "last_contacted_at": new Date('2026-03-14T18:10:00Z'), "next_follow_up_at": new Date('2026-03-21T17:00:00Z'), // type code here for "relation_one" field "notes": "Met at SaaS Expo, asked about activity reminders.", // type code here for "files" field }, { "lead_name": "Chris Wallace", "email": "chris.wallace@ironridgeparts.com", "phone": "+1-216-555-0179", "company_name": "IronRidge Parts", "job_title": "General Manager", "source": "other", "status": "working", "score": 55, "last_contacted_at": new Date('2026-03-12T13:00:00Z'), "next_follow_up_at": new Date('2026-03-22T14:00:00Z'), // type code here for "relation_one" field "notes": "Referral from partner, wants simple CRM for small team.", // type code here for "files" field }, { "lead_name": "Elena Rossi", "email": "elena.rossi@harborretail.com", "phone": "+1-773-555-0168", "company_name": "Harbor Retail", "job_title": "Marketing Manager", "source": "inbound", "status": "working", "score": 78, "last_contacted_at": new Date('2026-03-16T10:45:00Z'), "next_follow_up_at": new Date('2026-03-19T19:00:00Z'), // type code here for "relation_one" field "notes": "Qualified for audience sync use case, asked about LinkedIn matching.", // type code here for "files" field }, { "lead_name": "Noah Bennett", "email": "noah.bennett@ridgewaysecurity.com", "phone": "+1-404-555-0129", "company_name": "Ridgeway Security", "job_title": "Director of Sales", "source": "referral", "status": "unqualified", "score": 34, "last_contacted_at": new Date('2026-03-09T09:00:00Z'), "next_follow_up_at": new Date('2026-03-25T15:00:00Z'), // type code here for "relation_one" field "notes": "Budget not available this quarter, revisit in 60 days.", // type code here for "files" field }, ]; const PipelineStagesData = [ { "stage_name": "Prospecting", "sort_order": 10, "is_closed_won": true, "is_closed_lost": false, "default_probability": 0.1, }, { "stage_name": "Qualified", "sort_order": 20, "is_closed_won": true, "is_closed_lost": true, "default_probability": 0.25, }, { "stage_name": "Proposal", "sort_order": 30, "is_closed_won": false, "is_closed_lost": false, "default_probability": 0.5, }, { "stage_name": "Negotiation", "sort_order": 40, "is_closed_won": true, "is_closed_lost": false, "default_probability": 0.75, }, { "stage_name": "Closed Won", "sort_order": 50, "is_closed_won": true, "is_closed_lost": false, "default_probability": 1, }, ]; const DealsData = [ { "deal_name": "Northwind Logistics Annual CRM", "amount": 42000, "currency": "other", "probability": 0.55, "expected_close_at": new Date('2026-04-12T17:00:00Z'), "closed_at": new Date('2026-01-15T00:00:00Z'), "status": "won", // 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_one" field "next_step_at": new Date('2026-03-21T16:00:00Z'), "next_step": "Send updated proposal with implementation timeline.", "description": "Replace spreadsheets with pipeline and activity tracking for 8 reps.", }, { "deal_name": "HelioCloud Seats Expansion", "amount": 18000, "currency": "USD", "probability": 0.7, "expected_close_at": new Date('2026-03-29T17:00:00Z'), "closed_at": new Date('2026-02-01T00:00:00Z'), "status": "open", // 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_one" field "next_step_at": new Date('2026-03-20T18:30:00Z'), "next_step": "Confirm security questionnaire answers and finalize terms.", "description": "Add 15 additional seats and advanced reporting.", }, { "deal_name": "Summit Health Pipeline Pilot", "amount": 65000, "currency": "JPY", "probability": 0.35, "expected_close_at": new Date('2026-05-03T17:00:00Z'), "closed_at": new Date('2026-01-20T00:00:00Z'), "status": "open", // 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_one" field "next_step_at": new Date('2026-03-26T15:00:00Z'), "next_step": "Schedule technical review with IT and compliance.", "description": "Pilot for 2 departments with strict compliance and audit needs.", }, { "deal_name": "Cedar & Stone Bid Tracking Setup", "amount": 24000, "currency": "JPY", "probability": 0.5, "expected_close_at": new Date('2026-04-18T17:00:00Z'), "closed_at": new Date('2026-01-10T00:00:00Z'), "status": "won", // 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_one" field "next_step_at": new Date('2026-03-22T19:00:00Z'), "next_step": "Run pricing call and review contract start date.", "description": "Standardize deal stages and follow-up tasks for estimators.", }, { "deal_name": "BlueRiver Retargeting and CRM Bundle", "amount": 52000, "currency": "AUD", "probability": 0.6, "expected_close_at": new Date('2026-04-05T17:00:00Z'), "closed_at": new Date('2026-01-05T00:00:00Z'), "status": "won", // 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_one" field "next_step_at": new Date('2026-03-19T20:00:00Z'), "next_step": "Share audience sync roadmap and integration plan.", "description": "Combine pipeline management with Meta and LinkedIn audience sync workflows.", }, ]; const ActivitiesData = [ { "activity_type": "meeting", "subject": "Discovery call with Northwind", "details": "Discussed team workflow, current tools, and reporting needs.", "scheduled_at": new Date('2026-03-13T16:00:00Z'), "due_at": new Date('2026-03-13T16:30:00Z'), "completed_at": new Date('2026-03-13T16:28:00Z'), "status": "planned", "reminder_enabled": true, "remind_at": new Date('2026-03-13T15:45:00Z'), // 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_one" field // type code here for "files" field }, { "activity_type": "call", "subject": "Send HelioCloud security responses", "details": "Emailed completed security questionnaire and SOC2 summary.", "scheduled_at": new Date('2026-03-17T19:00:00Z'), "due_at": new Date('2026-03-17T19:15:00Z'), "completed_at": new Date('2026-03-17T19:10:00Z'), "status": "in_progress", "reminder_enabled": true, "remind_at": new Date('2026-03-01T00:00:00Z'), // 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_one" field // type code here for "files" field }, { "activity_type": "meeting", "subject": "Summit Health technical review", "details": "Review SSO options, data retention, and audit requirements.", "scheduled_at": new Date('2026-03-26T15:00:00Z'), "due_at": new Date('2026-03-26T16:00:00Z'), "completed_at": new Date('2026-03-01T00:00:00Z'), "status": "planned", "reminder_enabled": true, "remind_at": new Date('2026-03-26T14:30:00Z'), // 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_one" field // type code here for "files" field }, { "activity_type": "email", "subject": "Prepare Cedar and Stone pricing options", "details": "Create 2 plan options and an implementation timeline summary.", "scheduled_at": new Date('2026-03-21T17:00:00Z'), "due_at": new Date('2026-03-22T17:00:00Z'), "completed_at": new Date('2026-03-01T00:00:00Z'), "status": "completed", "reminder_enabled": true, "remind_at": new Date('2026-03-22T12:00:00Z'), // 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_one" field // type code here for "files" field }, { "activity_type": "meeting", "subject": "BlueRiver integration notes", "details": "They want to start with LinkedIn matched audiences, then Meta. Need hashed email upload guidance.", "scheduled_at": new Date('2026-03-18T20:10:00Z'), "due_at": new Date('2026-03-18T20:15:00Z'), "completed_at": new Date('2026-03-18T20:15:00Z'), "status": "in_progress", "reminder_enabled": true, "remind_at": new Date('2026-03-01T00:00:00Z'), // 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_one" field // type code here for "files" field }, ]; const NotesData = [ { "title": "Northwind stakeholder map", "content": "Jordan is the day to day owner. CFO will approve budget. Need concise ROI summary.", // 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_one" field }, { "title": "HelioCloud contract redlines", "content": "Legal prefers annual prepay with 30-day out. Confirm renewal cap language.", // 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_one" field }, { "title": "Summit Health compliance highlights", "content": "Must document access controls and provide audit export. Ask about HIPAA BAA requirements.", // 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_one" field }, { "title": "Cedar and Stone implementation plan", "content": "Two week onboarding, migrate existing opportunities, train estimators on follow-ups.", // 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_one" field }, { "title": "BlueRiver audience sync requirements", "content": "Need guidance on hashing and match rates. Confirm which identifiers are supported first.", // 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_one" field }, ]; const AudiencesData = [ { "audience_name": "High intent leads 30 days", "platform": "meta", "status": "active", "platform_audience_key": "meta_aud_83421", "last_synced_at": new Date('2026-03-18T06:30:00Z'), "description": "Contacts and leads with recent activity and high score for retargeting.", // type code here for "relation_one" field }, { "audience_name": "Open deals retargeting", "platform": "linkedin", "status": "paused", "platform_audience_key": "li_aud_11209", "last_synced_at": new Date('2026-03-17T06:30:00Z'), "description": "Decision makers tied to open deals in Proposal and Negotiation stages.", // type code here for "relation_one" field }, { "audience_name": "Event attendees follow up", "platform": "linkedin", "status": "paused", "platform_audience_key": "meta_aud_99007", "last_synced_at": new Date('2026-03-01T00:00:00Z'), "description": "People met at the expo who have not booked a demo yet.", // type code here for "relation_one" field }, { "audience_name": "Dormant leads reactivation", "platform": "linkedin", "status": "active", "platform_audience_key": "li_aud_33450", "last_synced_at": new Date('2026-03-10T06:30:00Z'), "description": "Leads uncontacted for 45 days to re-engage with new content.", // type code here for "relation_one" field }, { "audience_name": "Customers upsell nurture", "platform": "meta", "status": "archived", "platform_audience_key": "meta_aud_12001", "last_synced_at": new Date('2025-12-20T06:30:00Z'), "description": "Past customers targeted with expansion messaging, currently archived.", // type code here for "relation_one" field }, ]; const AudienceMembershipsData = [ { // type code here for "relation_one" field // type code here for "relation_one" field "sync_status": "removed", "synced_at": new Date('2026-03-18T06:31:00Z'), "error_message": "OK", }, { // type code here for "relation_one" field // type code here for "relation_one" field "sync_status": "synced", "synced_at": new Date('2026-03-17T06:31:00Z'), "error_message": "OK", }, { // type code here for "relation_one" field // type code here for "relation_one" field "sync_status": "synced", "synced_at": new Date('2026-03-01T00:00:00Z'), "error_message": "Waiting for activation", }, { // type code here for "relation_one" field // type code here for "relation_one" field "sync_status": "pending", "synced_at": new Date('2026-03-10T06:31:00Z'), "error_message": "Provider rejected identifier format", }, { // type code here for "relation_one" field // type code here for "relation_one" field "sync_status": "failed", "synced_at": new Date('2026-03-16T06:31:00Z'), "error_message": "Removed per request", }, ]; const IntegrationsData = [ { "provider": "linkedin", "status": "disconnected", "account_label": "Brightwave Meta Ads", "connected_at": new Date('2026-02-20T10:00:00Z'), "token_expires_at": new Date('2026-05-20T10:00:00Z'), "last_error": "OK", // type code here for "relation_one" field }, { "provider": "linkedin", "status": "error", "account_label": "Brightwave LinkedIn Ads", "connected_at": new Date('2026-02-22T10:00:00Z'), "token_expires_at": new Date('2026-05-22T10:00:00Z'), "last_error": "OK", // type code here for "relation_one" field }, { "provider": "meta", "status": "connected", "account_label": "Sandbox Meta Account", "connected_at": new Date('2026-01-10T10:00:00Z'), "token_expires_at": new Date('2026-02-10T10:00:00Z'), "last_error": "Token expired, reconnect required", // type code here for "relation_one" field }, { "provider": "linkedin", "status": "connected", "account_label": "Legacy LinkedIn Workspace", "connected_at": new Date('2025-11-10T10:00:00Z'), "token_expires_at": new Date('2025-12-10T10:00:00Z'), "last_error": "Disconnected by user", // type code here for "relation_one" field }, { "provider": "meta", "status": "connected", "account_label": "Marketing Meta Account", "connected_at": new Date('2026-03-01T10:00:00Z'), "token_expires_at": new Date('2026-06-01T10:00:00Z'), "last_error": "OK", // type code here for "relation_one" field }, ]; const ImportsData = [ { "entity_type": "activities", "status": "completed", // type code here for "files" field "rows_total": 250, "rows_success": 245, "rows_failed": 5, "error_report": "5 rows failed due to missing email address", // type code here for "relation_one" field }, { "entity_type": "deals", "status": "failed", // type code here for "files" field "rows_total": 120, "rows_success": 120, "rows_failed": 0, "error_report": "OK", // type code here for "relation_one" field }, { "entity_type": "contacts", "status": "queued", // type code here for "files" field "rows_total": 40, "rows_success": 0, "rows_failed": 40, "error_report": "Invalid CSV headers, expected account_name and domain", // type code here for "relation_one" field }, { "entity_type": "activities", "status": "queued", // type code here for "files" field "rows_total": 60, "rows_success": 12, "rows_failed": 0, "error_report": "In progress", // type code here for "relation_one" field }, { "entity_type": "deals", "status": "completed", // type code here for "files" field "rows_total": 500, "rows_success": 0, "rows_failed": 0, "error_report": "Queued for processing", // type code here for "relation_one" field }, ]; // Similar logic for "relation_many" async function associateAccountWithOwner() { const relatedOwner0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Account0 = await Accounts.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Account0?.setOwner) { await Account0. setOwner(relatedOwner0); } const relatedOwner1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Account1 = await Accounts.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Account1?.setOwner) { await Account1. setOwner(relatedOwner1); } const relatedOwner2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Account2 = await Accounts.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Account2?.setOwner) { await Account2. setOwner(relatedOwner2); } const relatedOwner3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Account3 = await Accounts.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Account3?.setOwner) { await Account3. setOwner(relatedOwner3); } const relatedOwner4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Account4 = await Accounts.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Account4?.setOwner) { await Account4. setOwner(relatedOwner4); } } async function associateContactWithAccount() { const relatedAccount0 = await Accounts.findOne({ offset: Math.floor(Math.random() * (await Accounts.count())), }); const Contact0 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Contact0?.setAccount) { await Contact0. setAccount(relatedAccount0); } const relatedAccount1 = await Accounts.findOne({ offset: Math.floor(Math.random() * (await Accounts.count())), }); const Contact1 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Contact1?.setAccount) { await Contact1. setAccount(relatedAccount1); } const relatedAccount2 = await Accounts.findOne({ offset: Math.floor(Math.random() * (await Accounts.count())), }); const Contact2 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Contact2?.setAccount) { await Contact2. setAccount(relatedAccount2); } const relatedAccount3 = await Accounts.findOne({ offset: Math.floor(Math.random() * (await Accounts.count())), }); const Contact3 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Contact3?.setAccount) { await Contact3. setAccount(relatedAccount3); } const relatedAccount4 = await Accounts.findOne({ offset: Math.floor(Math.random() * (await Accounts.count())), }); const Contact4 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Contact4?.setAccount) { await Contact4. setAccount(relatedAccount4); } } async function associateContactWithOwner() { const relatedOwner0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Contact0 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Contact0?.setOwner) { await Contact0. setOwner(relatedOwner0); } const relatedOwner1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Contact1 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Contact1?.setOwner) { await Contact1. setOwner(relatedOwner1); } const relatedOwner2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Contact2 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Contact2?.setOwner) { await Contact2. setOwner(relatedOwner2); } const relatedOwner3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Contact3 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Contact3?.setOwner) { await Contact3. setOwner(relatedOwner3); } const relatedOwner4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Contact4 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Contact4?.setOwner) { await Contact4. setOwner(relatedOwner4); } } async function associateLeadWithOwner() { const relatedOwner0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lead0 = await Leads.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Lead0?.setOwner) { await Lead0. setOwner(relatedOwner0); } const relatedOwner1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lead1 = await Leads.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Lead1?.setOwner) { await Lead1. setOwner(relatedOwner1); } const relatedOwner2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lead2 = await Leads.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Lead2?.setOwner) { await Lead2. setOwner(relatedOwner2); } const relatedOwner3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lead3 = await Leads.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Lead3?.setOwner) { await Lead3. setOwner(relatedOwner3); } const relatedOwner4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lead4 = await Leads.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Lead4?.setOwner) { await Lead4. setOwner(relatedOwner4); } } async function associateDealWithStage() { const relatedStage0 = await PipelineStages.findOne({ offset: Math.floor(Math.random() * (await PipelineStages.count())), }); const Deal0 = await Deals.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Deal0?.setStage) { await Deal0. setStage(relatedStage0); } const relatedStage1 = await PipelineStages.findOne({ offset: Math.floor(Math.random() * (await PipelineStages.count())), }); const Deal1 = await Deals.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Deal1?.setStage) { await Deal1. setStage(relatedStage1); } const relatedStage2 = await PipelineStages.findOne({ offset: Math.floor(Math.random() * (await PipelineStages.count())), }); const Deal2 = await Deals.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Deal2?.setStage) { await Deal2. setStage(relatedStage2); } const relatedStage3 = await PipelineStages.findOne({ offset: Math.floor(Math.random() * (await PipelineStages.count())), }); const Deal3 = await Deals.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Deal3?.setStage) { await Deal3. setStage(relatedStage3); } const relatedStage4 = await PipelineStages.findOne({ offset: Math.floor(Math.random() * (await PipelineStages.count())), }); const Deal4 = await Deals.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Deal4?.setStage) { await Deal4. setStage(relatedStage4); } } async function associateDealWithAccount() { const relatedAccount0 = await Accounts.findOne({ offset: Math.floor(Math.random() * (await Accounts.count())), }); const Deal0 = await Deals.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Deal0?.setAccount) { await Deal0. setAccount(relatedAccount0); } const relatedAccount1 = await Accounts.findOne({ offset: Math.floor(Math.random() * (await Accounts.count())), }); const Deal1 = await Deals.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Deal1?.setAccount) { await Deal1. setAccount(relatedAccount1); } const relatedAccount2 = await Accounts.findOne({ offset: Math.floor(Math.random() * (await Accounts.count())), }); const Deal2 = await Deals.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Deal2?.setAccount) { await Deal2. setAccount(relatedAccount2); } const relatedAccount3 = await Accounts.findOne({ offset: Math.floor(Math.random() * (await Accounts.count())), }); const Deal3 = await Deals.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Deal3?.setAccount) { await Deal3. setAccount(relatedAccount3); } const relatedAccount4 = await Accounts.findOne({ offset: Math.floor(Math.random() * (await Accounts.count())), }); const Deal4 = await Deals.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Deal4?.setAccount) { await Deal4. setAccount(relatedAccount4); } } async function associateDealWithPrimary_contact() { const relatedPrimary_contact0 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const Deal0 = await Deals.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Deal0?.setPrimary_contact) { await Deal0. setPrimary_contact(relatedPrimary_contact0); } const relatedPrimary_contact1 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const Deal1 = await Deals.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Deal1?.setPrimary_contact) { await Deal1. setPrimary_contact(relatedPrimary_contact1); } const relatedPrimary_contact2 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const Deal2 = await Deals.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Deal2?.setPrimary_contact) { await Deal2. setPrimary_contact(relatedPrimary_contact2); } const relatedPrimary_contact3 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const Deal3 = await Deals.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Deal3?.setPrimary_contact) { await Deal3. setPrimary_contact(relatedPrimary_contact3); } const relatedPrimary_contact4 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const Deal4 = await Deals.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Deal4?.setPrimary_contact) { await Deal4. setPrimary_contact(relatedPrimary_contact4); } } async function associateDealWithOwner() { const relatedOwner0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Deal0 = await Deals.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Deal0?.setOwner) { await Deal0. setOwner(relatedOwner0); } const relatedOwner1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Deal1 = await Deals.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Deal1?.setOwner) { await Deal1. setOwner(relatedOwner1); } const relatedOwner2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Deal2 = await Deals.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Deal2?.setOwner) { await Deal2. setOwner(relatedOwner2); } const relatedOwner3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Deal3 = await Deals.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Deal3?.setOwner) { await Deal3. setOwner(relatedOwner3); } const relatedOwner4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Deal4 = await Deals.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Deal4?.setOwner) { await Deal4. setOwner(relatedOwner4); } } async function associateActivityWithAssignee() { const relatedAssignee0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Activity0 = await Activities.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Activity0?.setAssignee) { await Activity0. setAssignee(relatedAssignee0); } const relatedAssignee1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Activity1 = await Activities.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Activity1?.setAssignee) { await Activity1. setAssignee(relatedAssignee1); } const relatedAssignee2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Activity2 = await Activities.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Activity2?.setAssignee) { await Activity2. setAssignee(relatedAssignee2); } const relatedAssignee3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Activity3 = await Activities.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Activity3?.setAssignee) { await Activity3. setAssignee(relatedAssignee3); } const relatedAssignee4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Activity4 = await Activities.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Activity4?.setAssignee) { await Activity4. setAssignee(relatedAssignee4); } } async function associateActivityWithLead() { const relatedLead0 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Activity0 = await Activities.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Activity0?.setLead) { await Activity0. setLead(relatedLead0); } const relatedLead1 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Activity1 = await Activities.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Activity1?.setLead) { await Activity1. setLead(relatedLead1); } const relatedLead2 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Activity2 = await Activities.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Activity2?.setLead) { await Activity2. setLead(relatedLead2); } const relatedLead3 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Activity3 = await Activities.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Activity3?.setLead) { await Activity3. setLead(relatedLead3); } const relatedLead4 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Activity4 = await Activities.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Activity4?.setLead) { await Activity4. setLead(relatedLead4); } } async function associateActivityWithContact() { const relatedContact0 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const Activity0 = await Activities.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Activity0?.setContact) { await Activity0. setContact(relatedContact0); } const relatedContact1 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const Activity1 = await Activities.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Activity1?.setContact) { await Activity1. setContact(relatedContact1); } const relatedContact2 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const Activity2 = await Activities.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Activity2?.setContact) { await Activity2. setContact(relatedContact2); } const relatedContact3 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const Activity3 = await Activities.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Activity3?.setContact) { await Activity3. setContact(relatedContact3); } const relatedContact4 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const Activity4 = await Activities.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Activity4?.setContact) { await Activity4. setContact(relatedContact4); } } async function associateActivityWithDeal() { const relatedDeal0 = await Deals.findOne({ offset: Math.floor(Math.random() * (await Deals.count())), }); const Activity0 = await Activities.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Activity0?.setDeal) { await Activity0. setDeal(relatedDeal0); } const relatedDeal1 = await Deals.findOne({ offset: Math.floor(Math.random() * (await Deals.count())), }); const Activity1 = await Activities.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Activity1?.setDeal) { await Activity1. setDeal(relatedDeal1); } const relatedDeal2 = await Deals.findOne({ offset: Math.floor(Math.random() * (await Deals.count())), }); const Activity2 = await Activities.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Activity2?.setDeal) { await Activity2. setDeal(relatedDeal2); } const relatedDeal3 = await Deals.findOne({ offset: Math.floor(Math.random() * (await Deals.count())), }); const Activity3 = await Activities.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Activity3?.setDeal) { await Activity3. setDeal(relatedDeal3); } const relatedDeal4 = await Deals.findOne({ offset: Math.floor(Math.random() * (await Deals.count())), }); const Activity4 = await Activities.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Activity4?.setDeal) { await Activity4. setDeal(relatedDeal4); } } async function associateNoteWithAuthor() { const relatedAuthor0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Note0 = await Notes.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Note0?.setAuthor) { await Note0. setAuthor(relatedAuthor0); } const relatedAuthor1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Note1 = await Notes.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Note1?.setAuthor) { await Note1. setAuthor(relatedAuthor1); } const relatedAuthor2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Note2 = await Notes.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Note2?.setAuthor) { await Note2. setAuthor(relatedAuthor2); } const relatedAuthor3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Note3 = await Notes.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Note3?.setAuthor) { await Note3. setAuthor(relatedAuthor3); } const relatedAuthor4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Note4 = await Notes.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Note4?.setAuthor) { await Note4. setAuthor(relatedAuthor4); } } async function associateNoteWithLead() { const relatedLead0 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Note0 = await Notes.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Note0?.setLead) { await Note0. setLead(relatedLead0); } const relatedLead1 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Note1 = await Notes.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Note1?.setLead) { await Note1. setLead(relatedLead1); } const relatedLead2 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Note2 = await Notes.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Note2?.setLead) { await Note2. setLead(relatedLead2); } const relatedLead3 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Note3 = await Notes.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Note3?.setLead) { await Note3. setLead(relatedLead3); } const relatedLead4 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Note4 = await Notes.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Note4?.setLead) { await Note4. setLead(relatedLead4); } } async function associateNoteWithContact() { const relatedContact0 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const Note0 = await Notes.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Note0?.setContact) { await Note0. setContact(relatedContact0); } const relatedContact1 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const Note1 = await Notes.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Note1?.setContact) { await Note1. setContact(relatedContact1); } const relatedContact2 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const Note2 = await Notes.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Note2?.setContact) { await Note2. setContact(relatedContact2); } const relatedContact3 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const Note3 = await Notes.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Note3?.setContact) { await Note3. setContact(relatedContact3); } const relatedContact4 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const Note4 = await Notes.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Note4?.setContact) { await Note4. setContact(relatedContact4); } } async function associateNoteWithDeal() { const relatedDeal0 = await Deals.findOne({ offset: Math.floor(Math.random() * (await Deals.count())), }); const Note0 = await Notes.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Note0?.setDeal) { await Note0. setDeal(relatedDeal0); } const relatedDeal1 = await Deals.findOne({ offset: Math.floor(Math.random() * (await Deals.count())), }); const Note1 = await Notes.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Note1?.setDeal) { await Note1. setDeal(relatedDeal1); } const relatedDeal2 = await Deals.findOne({ offset: Math.floor(Math.random() * (await Deals.count())), }); const Note2 = await Notes.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Note2?.setDeal) { await Note2. setDeal(relatedDeal2); } const relatedDeal3 = await Deals.findOne({ offset: Math.floor(Math.random() * (await Deals.count())), }); const Note3 = await Notes.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Note3?.setDeal) { await Note3. setDeal(relatedDeal3); } const relatedDeal4 = await Deals.findOne({ offset: Math.floor(Math.random() * (await Deals.count())), }); const Note4 = await Notes.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Note4?.setDeal) { await Note4. setDeal(relatedDeal4); } } async function associateAudienceWithOwner() { const relatedOwner0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Audience0 = await Audiences.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Audience0?.setOwner) { await Audience0. setOwner(relatedOwner0); } const relatedOwner1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Audience1 = await Audiences.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Audience1?.setOwner) { await Audience1. setOwner(relatedOwner1); } const relatedOwner2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Audience2 = await Audiences.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Audience2?.setOwner) { await Audience2. setOwner(relatedOwner2); } const relatedOwner3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Audience3 = await Audiences.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Audience3?.setOwner) { await Audience3. setOwner(relatedOwner3); } const relatedOwner4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Audience4 = await Audiences.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Audience4?.setOwner) { await Audience4. setOwner(relatedOwner4); } } async function associateAudienceMembershipWithAudience() { const relatedAudience0 = await Audiences.findOne({ offset: Math.floor(Math.random() * (await Audiences.count())), }); const AudienceMembership0 = await AudienceMemberships.findOne({ order: [['id', 'ASC']], offset: 0 }); if (AudienceMembership0?.setAudience) { await AudienceMembership0. setAudience(relatedAudience0); } const relatedAudience1 = await Audiences.findOne({ offset: Math.floor(Math.random() * (await Audiences.count())), }); const AudienceMembership1 = await AudienceMemberships.findOne({ order: [['id', 'ASC']], offset: 1 }); if (AudienceMembership1?.setAudience) { await AudienceMembership1. setAudience(relatedAudience1); } const relatedAudience2 = await Audiences.findOne({ offset: Math.floor(Math.random() * (await Audiences.count())), }); const AudienceMembership2 = await AudienceMemberships.findOne({ order: [['id', 'ASC']], offset: 2 }); if (AudienceMembership2?.setAudience) { await AudienceMembership2. setAudience(relatedAudience2); } const relatedAudience3 = await Audiences.findOne({ offset: Math.floor(Math.random() * (await Audiences.count())), }); const AudienceMembership3 = await AudienceMemberships.findOne({ order: [['id', 'ASC']], offset: 3 }); if (AudienceMembership3?.setAudience) { await AudienceMembership3. setAudience(relatedAudience3); } const relatedAudience4 = await Audiences.findOne({ offset: Math.floor(Math.random() * (await Audiences.count())), }); const AudienceMembership4 = await AudienceMemberships.findOne({ order: [['id', 'ASC']], offset: 4 }); if (AudienceMembership4?.setAudience) { await AudienceMembership4. setAudience(relatedAudience4); } } async function associateAudienceMembershipWithContact() { const relatedContact0 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const AudienceMembership0 = await AudienceMemberships.findOne({ order: [['id', 'ASC']], offset: 0 }); if (AudienceMembership0?.setContact) { await AudienceMembership0. setContact(relatedContact0); } const relatedContact1 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const AudienceMembership1 = await AudienceMemberships.findOne({ order: [['id', 'ASC']], offset: 1 }); if (AudienceMembership1?.setContact) { await AudienceMembership1. setContact(relatedContact1); } const relatedContact2 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const AudienceMembership2 = await AudienceMemberships.findOne({ order: [['id', 'ASC']], offset: 2 }); if (AudienceMembership2?.setContact) { await AudienceMembership2. setContact(relatedContact2); } const relatedContact3 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const AudienceMembership3 = await AudienceMemberships.findOne({ order: [['id', 'ASC']], offset: 3 }); if (AudienceMembership3?.setContact) { await AudienceMembership3. setContact(relatedContact3); } const relatedContact4 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const AudienceMembership4 = await AudienceMemberships.findOne({ order: [['id', 'ASC']], offset: 4 }); if (AudienceMembership4?.setContact) { await AudienceMembership4. setContact(relatedContact4); } } async function associateIntegrationWithConnected_by() { const relatedConnected_by0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Integration0 = await Integrations.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Integration0?.setConnected_by) { await Integration0. setConnected_by(relatedConnected_by0); } const relatedConnected_by1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Integration1 = await Integrations.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Integration1?.setConnected_by) { await Integration1. setConnected_by(relatedConnected_by1); } const relatedConnected_by2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Integration2 = await Integrations.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Integration2?.setConnected_by) { await Integration2. setConnected_by(relatedConnected_by2); } const relatedConnected_by3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Integration3 = await Integrations.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Integration3?.setConnected_by) { await Integration3. setConnected_by(relatedConnected_by3); } const relatedConnected_by4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Integration4 = await Integrations.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Integration4?.setConnected_by) { await Integration4. setConnected_by(relatedConnected_by4); } } async function associateImportWithRequested_by() { const relatedRequested_by0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Import0 = await Imports.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Import0?.setRequested_by) { await Import0. setRequested_by(relatedRequested_by0); } const relatedRequested_by1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Import1 = await Imports.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Import1?.setRequested_by) { await Import1. setRequested_by(relatedRequested_by1); } const relatedRequested_by2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Import2 = await Imports.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Import2?.setRequested_by) { await Import2. setRequested_by(relatedRequested_by2); } const relatedRequested_by3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Import3 = await Imports.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Import3?.setRequested_by) { await Import3. setRequested_by(relatedRequested_by3); } const relatedRequested_by4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Import4 = await Imports.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Import4?.setRequested_by) { await Import4. setRequested_by(relatedRequested_by4); } } module.exports = { up: async (queryInterface, Sequelize) => { await Accounts.bulkCreate(AccountsData); await Contacts.bulkCreate(ContactsData); await Leads.bulkCreate(LeadsData); await PipelineStages.bulkCreate(PipelineStagesData); await Deals.bulkCreate(DealsData); await Activities.bulkCreate(ActivitiesData); await Notes.bulkCreate(NotesData); await Audiences.bulkCreate(AudiencesData); await AudienceMemberships.bulkCreate(AudienceMembershipsData); await Integrations.bulkCreate(IntegrationsData); await Imports.bulkCreate(ImportsData); await Promise.all([ // Similar logic for "relation_many" await associateAccountWithOwner(), await associateContactWithAccount(), await associateContactWithOwner(), await associateLeadWithOwner(), await associateDealWithStage(), await associateDealWithAccount(), await associateDealWithPrimary_contact(), await associateDealWithOwner(), await associateActivityWithAssignee(), await associateActivityWithLead(), await associateActivityWithContact(), await associateActivityWithDeal(), await associateNoteWithAuthor(), await associateNoteWithLead(), await associateNoteWithContact(), await associateNoteWithDeal(), await associateAudienceWithOwner(), await associateAudienceMembershipWithAudience(), await associateAudienceMembershipWithContact(), await associateIntegrationWithConnected_by(), await associateImportWithRequested_by(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('accounts', null, {}); await queryInterface.bulkDelete('contacts', null, {}); await queryInterface.bulkDelete('leads', null, {}); await queryInterface.bulkDelete('pipeline_stages', null, {}); await queryInterface.bulkDelete('deals', null, {}); await queryInterface.bulkDelete('activities', null, {}); await queryInterface.bulkDelete('notes', null, {}); await queryInterface.bulkDelete('audiences', null, {}); await queryInterface.bulkDelete('audience_memberships', null, {}); await queryInterface.bulkDelete('integrations', null, {}); await queryInterface.bulkDelete('imports', null, {}); }, };