





















const db = require('../models');
const Users = db.users;






const Companies = db.companies;

const Contacts = db.contacts;

const Pipelines = db.pipelines;

const PipelineStages = db.pipeline_stages;

const Leads = db.leads;

const Deals = db.deals;

const Activities = db.activities;

const ActivityFiles = db.activity_files;

const DealProducts = db.deal_products;

const Tags = db.tags;

const LeadTags = db.lead_tags;

const DealTags = db.deal_tags;







const CompaniesData = [
    
    {
    
        
        
            
                "name": "Northwind Traders",
            
        
    
        
        
            
                "website": "https://northwind.example.com",
            
        
    
        
        
            
                "industry": "Wholesale Distribution",
            
        
    
        
        
            
                "domain": "northwind.example.com",
            
        
    
        
        
            
                "phone": "+1 312 555 0130",
            
        
    
        
        
            
                "address": "233 W Lake St, Chicago, IL",
            
        
    
        
        
            
                "notes": "Long-term distributor exploring a new CRM rollout.",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Bluebird Logistics",
            
        
    
        
        
            
                "website": "https://bluebirdlogistics.example.com",
            
        
    
        
        
            
                "industry": "Logistics",
            
        
    
        
        
            
                "domain": "bluebirdlogistics.example.com",
            
        
    
        
        
            
                "phone": "+1 617 555 0144",
            
        
    
        
        
            
                "address": "18 Seaport Blvd, Boston, MA",
            
        
    
        
        
            
                "notes": "Interested in pipeline visibility and forecasting improvements.",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Helio Health Systems",
            
        
    
        
        
            
                "website": "https://heliohealth.example.com",
            
        
    
        
        
            
                "industry": "Healthcare Technology",
            
        
    
        
        
            
                "domain": "heliohealth.example.com",
            
        
    
        
        
            
                "phone": "+1 206 555 0188",
            
        
    
        
        
            
                "address": "900 5th Ave, Seattle, WA",
            
        
    
        
        
            
                "notes": "Evaluating vendor options for sales process standardization.",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Cedar & Co Finance",
            
        
    
        
        
            
                "website": "https://cedarfinance.example.com",
            
        
    
        
        
            
                "industry": "Financial Services",
            
        
    
        
        
            
                "domain": "cedarfinance.example.com",
            
        
    
        
        
            
                "phone": "+1 212 555 0199",
            
        
    
        
        
            
                "address": "77 Wall St, New York, NY",
            
        
    
        
        
            
                "notes": "Looking for activity tracking and compliance-friendly notes.",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const ContactsData = [
    
    {
    
        
        
            
                "first_name": "Olivia",
            
        
    
        
        
            
                "last_name": "Grant",
            
        
    
        
        
            
                "email": "olivia.grant@northwind.example.com",
            
        
    
        
        
            
                "phone": "+1 312 555 0210",
            
        
    
        
        
            
                "job_title": "Procurement Manager",
            
        
    
        
        
            
                "lifecycle_stage": "customer",
            
        
    
        
        
            
                "linkedin_url": "https://linkedin.example.com/in/oliviagrant",
            
        
    
        
        
            
                "notes": "Prefers email follow-ups, available Tuesdays and Thursdays.",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "first_name": "Daniel",
            
        
    
        
        
            
                "last_name": "Reyes",
            
        
    
        
        
            
                "email": "daniel.reyes@bluebirdlogistics.example.com",
            
        
    
        
        
            
                "phone": "+1 617 555 0222",
            
        
    
        
        
            
                "job_title": "VP Operations",
            
        
    
        
        
            
                "lifecycle_stage": "customer",
            
        
    
        
        
            
                "linkedin_url": "https://linkedin.example.com/in/danielreyes",
            
        
    
        
        
            
                "notes": "Wants a short demo focused on reporting and automation.",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "first_name": "Sophia",
            
        
    
        
        
            
                "last_name": "Kim",
            
        
    
        
        
            
                "email": "sophia.kim@heliohealth.example.com",
            
        
    
        
        
            
                "phone": "+1 206 555 0233",
            
        
    
        
        
            
                "job_title": "Director of Sales Enablement",
            
        
    
        
        
            
                "lifecycle_stage": "customer",
            
        
    
        
        
            
                "linkedin_url": "https://linkedin.example.com/in/sophiakim",
            
        
    
        
        
            
                "notes": "Comparing tools; asked about integrations and data import.",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "first_name": "Liam",
            
        
    
        
        
            
                "last_name": "OConnor",
            
        
    
        
        
            
                "email": "liam.oconnor@cedarfinance.example.com",
            
        
    
        
        
            
                "phone": "+1 212 555 0244",
            
        
    
        
        
            
                "job_title": "Head of Business Development",
            
        
    
        
        
            
                "lifecycle_stage": "inactive",
            
        
    
        
        
            
                "linkedin_url": "https://linkedin.example.com/in/liamoconnor",
            
        
    
        
        
            
                "notes": "Interested in secure access controls and auditability.",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const PipelinesData = [
    
    {
    
        
        
            
                "name": "New Business",
            
        
    
        
        
            
                "description": "Standard pipeline for net-new customers.",
            
        
    
        
        
            
                "is_default": true,
            
        
    
    },
    
    {
    
        
        
            
                "name": "Expansion",
            
        
    
        
        
            
                "description": "Pipeline for upsell and cross-sell opportunities.",
            
        
    
        
        
            
                "is_default": true,
            
        
    
    },
    
    {
    
        
        
            
                "name": "Partnerships",
            
        
    
        
        
            
                "description": "Pipeline for channel and partner deals.",
            
        
    
        
        
            
                "is_default": true,
            
        
    
    },
    
    {
    
        
        
            
                "name": "Renewals",
            
        
    
        
        
            
                "description": "Pipeline for renewal opportunities and retention.",
            
        
    
        
        
            
                "is_default": true,
            
        
    
    },
    
];



const PipelineStagesData = [
    
    {
    
        
        
            
                "name": "Prospecting",
            
        
    
        
        
            
                "sort_order": 1,
            
        
    
        
        
            
                "win_probability": 0.1,
            
        
    
        
        
            
                "is_closed_won": false,
            
        
    
        
        
            
                "is_closed_lost": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Qualified",
            
        
    
        
        
            
                "sort_order": 2,
            
        
    
        
        
            
                "win_probability": 0.25,
            
        
    
        
        
            
                "is_closed_won": false,
            
        
    
        
        
            
                "is_closed_lost": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Proposal",
            
        
    
        
        
            
                "sort_order": 3,
            
        
    
        
        
            
                "win_probability": 0.5,
            
        
    
        
        
            
                "is_closed_won": false,
            
        
    
        
        
            
                "is_closed_lost": false,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Negotiation",
            
        
    
        
        
            
                "sort_order": 4,
            
        
    
        
        
            
                "win_probability": 0.7,
            
        
    
        
        
            
                "is_closed_won": true,
            
        
    
        
        
            
                "is_closed_lost": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const LeadsData = [
    
    {
    
        
        
            
                "lead_name": "Northwind Traders - CRM Refresh",
            
        
    
        
        
            
                "status": "new",
            
        
    
        
        
            
                "source": "event",
            
        
    
        
        
            
                "estimated_value": 45000,
            
        
    
        
        
            
                "next_follow_up_at": new Date('2026-06-03T15:00:00Z'),
            
        
    
        
        
            
                "last_contacted_at": new Date('2026-05-20T16:30:00Z'),
            
        
    
        
        
            
                "notes": "Referred by existing customer. Needs timeline and migration plan.",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "lead_name": "Bluebird Logistics - Pipeline Visibility",
            
        
    
        
        
            
                "status": "unqualified",
            
        
    
        
        
            
                "source": "other",
            
        
    
        
        
            
                "estimated_value": 28000,
            
        
    
        
        
            
                "next_follow_up_at": new Date('2026-06-01T14:00:00Z'),
            
        
    
        
        
            
                "last_contacted_at": new Date('2026-05-26T13:00:00Z'),
            
        
    
        
        
            
                "notes": "Inbound form submission requesting a product overview.",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "lead_name": "Helio Health Systems - Sales Enablement",
            
        
    
        
        
            
                "status": "converted",
            
        
    
        
        
            
                "source": "partner",
            
        
    
        
        
            
                "estimated_value": 72000,
            
        
    
        
        
            
                "next_follow_up_at": new Date('2026-06-05T17:00:00Z'),
            
        
    
        
        
            
                "last_contacted_at": new Date('2026-05-22T18:00:00Z'),
            
        
    
        
        
            
                "notes": "Met at industry conference. Interested in activity tracking and reminders.",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "lead_name": "Cedar & Co Finance - Secure CRM",
            
        
    
        
        
            
                "status": "new",
            
        
    
        
        
            
                "source": "partner",
            
        
    
        
        
            
                "estimated_value": 60000,
            
        
    
        
        
            
                "next_follow_up_at": new Date('2026-06-04T16:00:00Z'),
            
        
    
        
        
            
                "last_contacted_at": new Date('2026-05-21T15:15:00Z'),
            
        
    
        
        
            
                "notes": "Security and role-based access are key decision factors.",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const DealsData = [
    
    {
    
        
        
            
                "name": "Northwind Traders - New Business FY26",
            
        
    
        
        
            
                "amount": 52000,
            
        
    
        
        
            
                "forecast_category": "best_case",
            
        
    
        
        
            
                "expected_close_at": new Date('2026-07-15T00:00:00Z'),
            
        
    
        
        
            
                "next_follow_up_at": new Date('2026-06-03T15:00:00Z'),
            
        
    
        
        
            
                "closed_at": new Date('2026-07-20T00:00:00Z'),
            
        
    
        
        
            
                "priority": "urgent",
            
        
    
        
        
            
                "description": "Core CRM rollout for sales team, includes onboarding and data import.",
            
        
    
        
        
            
                // 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 "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Bluebird Logistics - Inbound Starter",
            
        
    
        
        
            
                "amount": 25000,
            
        
    
        
        
            
                "forecast_category": "commit",
            
        
    
        
        
            
                "expected_close_at": new Date('2026-06-30T00:00:00Z'),
            
        
    
        
        
            
                "next_follow_up_at": new Date('2026-06-01T14:00:00Z'),
            
        
    
        
        
            
                "closed_at": new Date('2026-07-02T00:00:00Z'),
            
        
    
        
        
            
                "priority": "low",
            
        
    
        
        
            
                "description": "Starter package plus activity tracking training.",
            
        
    
        
        
            
                // 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 "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Helio Health Systems - Enablement Suite",
            
        
    
        
        
            
                "amount": 78000,
            
        
    
        
        
            
                "forecast_category": "closed_lost",
            
        
    
        
        
            
                "expected_close_at": new Date('2026-08-05T00:00:00Z'),
            
        
    
        
        
            
                "next_follow_up_at": new Date('2026-06-05T17:00:00Z'),
            
        
    
        
        
            
                "closed_at": new Date('2026-08-07T00:00:00Z'),
            
        
    
        
        
            
                "priority": "high",
            
        
    
        
        
            
                "description": "Full enablement and reporting, with custom pipeline stages.",
            
        
    
        
        
            
                // 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 "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Cedar & Co Finance - Compliance Rollout",
            
        
    
        
        
            
                "amount": 64000,
            
        
    
        
        
            
                "forecast_category": "pipeline",
            
        
    
        
        
            
                "expected_close_at": new Date('2026-07-25T00:00:00Z'),
            
        
    
        
        
            
                "next_follow_up_at": new Date('2026-06-04T16:00:00Z'),
            
        
    
        
        
            
                "closed_at": new Date('2026-07-28T00:00:00Z'),
            
        
    
        
        
            
                "priority": "medium",
            
        
    
        
        
            
                "description": "RBAC-focused deployment, includes audit-friendly activity logging.",
            
        
    
        
        
            
                // 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 "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const ActivitiesData = [
    
    {
    
        
        
            
                "activity_type": "call",
            
        
    
        
        
            
                "subject": "Discovery call with Northwind",
            
        
    
        
        
            
                "details": "Discussed current CRM pain points and data migration needs.",
            
        
    
        
        
            
                "scheduled_at": new Date('2026-05-20T16:00:00Z'),
            
        
    
        
        
            
                "due_at": new Date('2026-05-20T17:00:00Z'),
            
        
    
        
        
            
                "completed_at": new Date('2026-05-20T16:45:00Z'),
            
        
    
        
        
            
                "status": "completed",
            
        
    
        
        
            
                "is_reminder_enabled": true,
            
        
    
        
        
            
                "reminder_at": new Date('2026-05-20T15: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
            
        
    
    },
    
    {
    
        
        
            
                "activity_type": "demo",
            
        
    
        
        
            
                "subject": "Send demo recap to Bluebird",
            
        
    
        
        
            
                "details": "Follow up with recap, next steps, and pricing overview.",
            
        
    
        
        
            
                "scheduled_at": new Date('2026-05-26T13:00:00Z'),
            
        
    
        
        
            
                "due_at": new Date('2026-05-27T17:00:00Z'),
            
        
    
        
        
            
                "completed_at": new Date('2026-05-26T13:20:00Z'),
            
        
    
        
        
            
                "status": "canceled",
            
        
    
        
        
            
                "is_reminder_enabled": true,
            
        
    
        
        
            
                "reminder_at": new Date('2026-05-27T16: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
            
        
    
    },
    
    {
    
        
        
            
                "activity_type": "meeting",
            
        
    
        
        
            
                "subject": "Solution demo for Helio",
            
        
    
        
        
            
                "details": "Demo focused on pipeline stages, ownership, and activity reminders.",
            
        
    
        
        
            
                "scheduled_at": new Date('2026-06-05T17:00:00Z'),
            
        
    
        
        
            
                "due_at": new Date('2026-06-05T18:00:00Z'),
            
        
    
        
        
            
                "completed_at": new Date('2026-06-05T18:05:00Z'),
            
        
    
        
        
            
                "status": "completed",
            
        
    
        
        
            
                "is_reminder_enabled": true,
            
        
    
        
        
            
                "reminder_at": new Date('2026-06-05T16: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
            
        
    
    },
    
    {
    
        
        
            
                "activity_type": "call",
            
        
    
        
        
            
                "subject": "Prepare security questionnaire for Cedar",
            
        
    
        
        
            
                "details": "Compile answers for RBAC, data retention, and access logging.",
            
        
    
        
        
            
                "scheduled_at": new Date('2026-05-28T15:00:00Z'),
            
        
    
        
        
            
                "due_at": new Date('2026-06-04T16:00:00Z'),
            
        
    
        
        
            
                "completed_at": new Date('2026-06-02T14:30:00Z'),
            
        
    
        
        
            
                "status": "planned",
            
        
    
        
        
            
                "is_reminder_enabled": true,
            
        
    
        
        
            
                "reminder_at": new Date('2026-06-03T16: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
            
        
    
    },
    
];



const ActivityFilesData = [
    
    {
    
        
        
            
                "title": "Northwind Discovery Notes PDF",
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "title": "Bluebird Demo Recap Attachment",
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "title": "Helio Demo Agenda",
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "title": "Cedar Security Questionnaire Draft",
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const DealProductsData = [
    
    {
    
        
        
            
                "name": "CRM Core Subscription",
            
        
    
        
        
            
                "unit_price": 1800,
            
        
    
        
        
            
                "quantity": 12,
            
        
    
        
        
            
                "discount_amount": 1200,
            
        
    
        
        
            
                "notes": "Annual subscription billed yearly.",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Onboarding and Training",
            
        
    
        
        
            
                "unit_price": 5000,
            
        
    
        
        
            
                "quantity": 1,
            
        
    
        
        
            
                "discount_amount": 0,
            
        
    
        
        
            
                "notes": "Remote onboarding sessions included.",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Advanced Reporting Add-on",
            
        
    
        
        
            
                "unit_price": 600,
            
        
    
        
        
            
                "quantity": 12,
            
        
    
        
        
            
                "discount_amount": 0,
            
        
    
        
        
            
                "notes": "Includes forecasting dashboards.",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Security and RBAC Package",
            
        
    
        
        
            
                "unit_price": 4000,
            
        
    
        
        
            
                "quantity": 1,
            
        
    
        
        
            
                "discount_amount": 500,
            
        
    
        
        
            
                "notes": "Includes security review support.",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const TagsData = [
    
    {
    
        
        
            
                "name": "High Priority",
            
        
    
        
        
            
                "color": "#EF4444",
            
        
    
    },
    
    {
    
        
        
            
                "name": "Inbound",
            
        
    
        
        
            
                "color": "#3B82F6",
            
        
    
    },
    
    {
    
        
        
            
                "name": "Outbound",
            
        
    
        
        
            
                "color": "#F59E0B",
            
        
    
    },
    
    {
    
        
        
            
                "name": "Partner",
            
        
    
        
        
            
                "color": "#8B5CF6",
            
        
    
    },
    
];



const LeadTagsData = [
    
    {
    
        
        
            
                // 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 "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 DealTagsData = [
    
    {
    
        
        
            
                // 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 "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];




    
    
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            // Similar logic for "relation_many"
        
    

    
    
    
    
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            
            async function associateCompanyWithOwner() {
            
                const relatedOwner0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Company0 = await Companies.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Company0?.setOwner)
                {
                    await
                    Company0.
                    setOwner(relatedOwner0);
                }
            
                const relatedOwner1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Company1 = await Companies.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Company1?.setOwner)
                {
                    await
                    Company1.
                    setOwner(relatedOwner1);
                }
            
                const relatedOwner2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Company2 = await Companies.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Company2?.setOwner)
                {
                    await
                    Company2.
                    setOwner(relatedOwner2);
                }
            
                const relatedOwner3 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Company3 = await Companies.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (Company3?.setOwner)
                {
                    await
                    Company3.
                    setOwner(relatedOwner3);
                }
            
        }
        
    

    
    
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            
            async function associateContactWithCompany() {
            
                const relatedCompany0 = await Companies.findOne({
                    offset: Math.floor(Math.random() * (await Companies.count())),
                });
                const Contact0 = await Contacts.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Contact0?.setCompany)
                {
                    await
                    Contact0.
                    setCompany(relatedCompany0);
                }
            
                const relatedCompany1 = await Companies.findOne({
                    offset: Math.floor(Math.random() * (await Companies.count())),
                });
                const Contact1 = await Contacts.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Contact1?.setCompany)
                {
                    await
                    Contact1.
                    setCompany(relatedCompany1);
                }
            
                const relatedCompany2 = await Companies.findOne({
                    offset: Math.floor(Math.random() * (await Companies.count())),
                });
                const Contact2 = await Contacts.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Contact2?.setCompany)
                {
                    await
                    Contact2.
                    setCompany(relatedCompany2);
                }
            
                const relatedCompany3 = await Companies.findOne({
                    offset: Math.floor(Math.random() * (await Companies.count())),
                });
                const Contact3 = await Contacts.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (Contact3?.setCompany)
                {
                    await
                    Contact3.
                    setCompany(relatedCompany3);
                }
            
        }
        
    
        
            
            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);
                }
            
        }
        
    

    
    
    
        
    
        
    
        
    

    
    
    
        
    
        
    
        
    
        
    
        
    
        
            
            async function associatePipelineStageWithPipeline() {
            
                const relatedPipeline0 = await Pipelines.findOne({
                    offset: Math.floor(Math.random() * (await Pipelines.count())),
                });
                const PipelineStage0 = await PipelineStages.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (PipelineStage0?.setPipeline)
                {
                    await
                    PipelineStage0.
                    setPipeline(relatedPipeline0);
                }
            
                const relatedPipeline1 = await Pipelines.findOne({
                    offset: Math.floor(Math.random() * (await Pipelines.count())),
                });
                const PipelineStage1 = await PipelineStages.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (PipelineStage1?.setPipeline)
                {
                    await
                    PipelineStage1.
                    setPipeline(relatedPipeline1);
                }
            
                const relatedPipeline2 = await Pipelines.findOne({
                    offset: Math.floor(Math.random() * (await Pipelines.count())),
                });
                const PipelineStage2 = await PipelineStages.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (PipelineStage2?.setPipeline)
                {
                    await
                    PipelineStage2.
                    setPipeline(relatedPipeline2);
                }
            
                const relatedPipeline3 = await Pipelines.findOne({
                    offset: Math.floor(Math.random() * (await Pipelines.count())),
                });
                const PipelineStage3 = await PipelineStages.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (PipelineStage3?.setPipeline)
                {
                    await
                    PipelineStage3.
                    setPipeline(relatedPipeline3);
                }
            
        }
        
    

    
    
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            
            async function associateLeadWithPrimary_contact() {
            
                const relatedPrimary_contact0 = await Contacts.findOne({
                    offset: Math.floor(Math.random() * (await Contacts.count())),
                });
                const Lead0 = await Leads.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Lead0?.setPrimary_contact)
                {
                    await
                    Lead0.
                    setPrimary_contact(relatedPrimary_contact0);
                }
            
                const relatedPrimary_contact1 = await Contacts.findOne({
                    offset: Math.floor(Math.random() * (await Contacts.count())),
                });
                const Lead1 = await Leads.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Lead1?.setPrimary_contact)
                {
                    await
                    Lead1.
                    setPrimary_contact(relatedPrimary_contact1);
                }
            
                const relatedPrimary_contact2 = await Contacts.findOne({
                    offset: Math.floor(Math.random() * (await Contacts.count())),
                });
                const Lead2 = await Leads.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Lead2?.setPrimary_contact)
                {
                    await
                    Lead2.
                    setPrimary_contact(relatedPrimary_contact2);
                }
            
                const relatedPrimary_contact3 = await Contacts.findOne({
                    offset: Math.floor(Math.random() * (await Contacts.count())),
                });
                const Lead3 = await Leads.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (Lead3?.setPrimary_contact)
                {
                    await
                    Lead3.
                    setPrimary_contact(relatedPrimary_contact3);
                }
            
        }
        
    
        
            
            async function associateLeadWithCompany() {
            
                const relatedCompany0 = await Companies.findOne({
                    offset: Math.floor(Math.random() * (await Companies.count())),
                });
                const Lead0 = await Leads.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Lead0?.setCompany)
                {
                    await
                    Lead0.
                    setCompany(relatedCompany0);
                }
            
                const relatedCompany1 = await Companies.findOne({
                    offset: Math.floor(Math.random() * (await Companies.count())),
                });
                const Lead1 = await Leads.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Lead1?.setCompany)
                {
                    await
                    Lead1.
                    setCompany(relatedCompany1);
                }
            
                const relatedCompany2 = await Companies.findOne({
                    offset: Math.floor(Math.random() * (await Companies.count())),
                });
                const Lead2 = await Leads.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Lead2?.setCompany)
                {
                    await
                    Lead2.
                    setCompany(relatedCompany2);
                }
            
                const relatedCompany3 = await Companies.findOne({
                    offset: Math.floor(Math.random() * (await Companies.count())),
                });
                const Lead3 = await Leads.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (Lead3?.setCompany)
                {
                    await
                    Lead3.
                    setCompany(relatedCompany3);
                }
            
        }
        
    
        
            
            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);
                }
            
        }
        
    

    
    
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            
            async function associateDealWithPipeline() {
            
                const relatedPipeline0 = await Pipelines.findOne({
                    offset: Math.floor(Math.random() * (await Pipelines.count())),
                });
                const Deal0 = await Deals.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Deal0?.setPipeline)
                {
                    await
                    Deal0.
                    setPipeline(relatedPipeline0);
                }
            
                const relatedPipeline1 = await Pipelines.findOne({
                    offset: Math.floor(Math.random() * (await Pipelines.count())),
                });
                const Deal1 = await Deals.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Deal1?.setPipeline)
                {
                    await
                    Deal1.
                    setPipeline(relatedPipeline1);
                }
            
                const relatedPipeline2 = await Pipelines.findOne({
                    offset: Math.floor(Math.random() * (await Pipelines.count())),
                });
                const Deal2 = await Deals.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Deal2?.setPipeline)
                {
                    await
                    Deal2.
                    setPipeline(relatedPipeline2);
                }
            
                const relatedPipeline3 = await Pipelines.findOne({
                    offset: Math.floor(Math.random() * (await Pipelines.count())),
                });
                const Deal3 = await Deals.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (Deal3?.setPipeline)
                {
                    await
                    Deal3.
                    setPipeline(relatedPipeline3);
                }
            
        }
        
    
        
            
            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);
                }
            
        }
        
    
        
            
            async function associateDealWithCompany() {
            
                const relatedCompany0 = await Companies.findOne({
                    offset: Math.floor(Math.random() * (await Companies.count())),
                });
                const Deal0 = await Deals.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Deal0?.setCompany)
                {
                    await
                    Deal0.
                    setCompany(relatedCompany0);
                }
            
                const relatedCompany1 = await Companies.findOne({
                    offset: Math.floor(Math.random() * (await Companies.count())),
                });
                const Deal1 = await Deals.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Deal1?.setCompany)
                {
                    await
                    Deal1.
                    setCompany(relatedCompany1);
                }
            
                const relatedCompany2 = await Companies.findOne({
                    offset: Math.floor(Math.random() * (await Companies.count())),
                });
                const Deal2 = await Deals.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Deal2?.setCompany)
                {
                    await
                    Deal2.
                    setCompany(relatedCompany2);
                }
            
                const relatedCompany3 = await Companies.findOne({
                    offset: Math.floor(Math.random() * (await Companies.count())),
                });
                const Deal3 = await Deals.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (Deal3?.setCompany)
                {
                    await
                    Deal3.
                    setCompany(relatedCompany3);
                }
            
        }
        
    
        
            
            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);
                }
            
        }
        
    
        
            
            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);
                }
            
        }
        
    
        
            
            async function associateDealWithLead() {
            
                const relatedLead0 = await Leads.findOne({
                    offset: Math.floor(Math.random() * (await Leads.count())),
                });
                const Deal0 = await Deals.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Deal0?.setLead)
                {
                    await
                    Deal0.
                    setLead(relatedLead0);
                }
            
                const relatedLead1 = await Leads.findOne({
                    offset: Math.floor(Math.random() * (await Leads.count())),
                });
                const Deal1 = await Deals.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Deal1?.setLead)
                {
                    await
                    Deal1.
                    setLead(relatedLead1);
                }
            
                const relatedLead2 = await Leads.findOne({
                    offset: Math.floor(Math.random() * (await Leads.count())),
                });
                const Deal2 = await Deals.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Deal2?.setLead)
                {
                    await
                    Deal2.
                    setLead(relatedLead2);
                }
            
                const relatedLead3 = await Leads.findOne({
                    offset: Math.floor(Math.random() * (await Leads.count())),
                });
                const Deal3 = await Deals.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (Deal3?.setLead)
                {
                    await
                    Deal3.
                    setLead(relatedLead3);
                }
            
        }
        
    

    
    
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            
            async function associateActivityWithAssigned_to() {
            
                const relatedAssigned_to0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Activity0 = await Activities.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Activity0?.setAssigned_to)
                {
                    await
                    Activity0.
                    setAssigned_to(relatedAssigned_to0);
                }
            
                const relatedAssigned_to1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Activity1 = await Activities.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Activity1?.setAssigned_to)
                {
                    await
                    Activity1.
                    setAssigned_to(relatedAssigned_to1);
                }
            
                const relatedAssigned_to2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Activity2 = await Activities.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Activity2?.setAssigned_to)
                {
                    await
                    Activity2.
                    setAssigned_to(relatedAssigned_to2);
                }
            
                const relatedAssigned_to3 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Activity3 = await Activities.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (Activity3?.setAssigned_to)
                {
                    await
                    Activity3.
                    setAssigned_to(relatedAssigned_to3);
                }
            
        }
        
    
        
            
            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);
                }
            
        }
        
    
        
            
            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);
                }
            
        }
        
    
        
            
            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);
                }
            
        }
        
    

    
    
    
        
    
        
    
        
            
            async function associateActivityFileWithActivity() {
            
                const relatedActivity0 = await Activities.findOne({
                    offset: Math.floor(Math.random() * (await Activities.count())),
                });
                const ActivityFile0 = await ActivityFiles.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ActivityFile0?.setActivity)
                {
                    await
                    ActivityFile0.
                    setActivity(relatedActivity0);
                }
            
                const relatedActivity1 = await Activities.findOne({
                    offset: Math.floor(Math.random() * (await Activities.count())),
                });
                const ActivityFile1 = await ActivityFiles.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ActivityFile1?.setActivity)
                {
                    await
                    ActivityFile1.
                    setActivity(relatedActivity1);
                }
            
                const relatedActivity2 = await Activities.findOne({
                    offset: Math.floor(Math.random() * (await Activities.count())),
                });
                const ActivityFile2 = await ActivityFiles.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ActivityFile2?.setActivity)
                {
                    await
                    ActivityFile2.
                    setActivity(relatedActivity2);
                }
            
                const relatedActivity3 = await Activities.findOne({
                    offset: Math.floor(Math.random() * (await Activities.count())),
                });
                const ActivityFile3 = await ActivityFiles.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ActivityFile3?.setActivity)
                {
                    await
                    ActivityFile3.
                    setActivity(relatedActivity3);
                }
            
        }
        
    

    
    
    
        
    
        
    
        
    
        
    
        
    
        
            
            async function associateDealProductWithDeal() {
            
                const relatedDeal0 = await Deals.findOne({
                    offset: Math.floor(Math.random() * (await Deals.count())),
                });
                const DealProduct0 = await DealProducts.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (DealProduct0?.setDeal)
                {
                    await
                    DealProduct0.
                    setDeal(relatedDeal0);
                }
            
                const relatedDeal1 = await Deals.findOne({
                    offset: Math.floor(Math.random() * (await Deals.count())),
                });
                const DealProduct1 = await DealProducts.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (DealProduct1?.setDeal)
                {
                    await
                    DealProduct1.
                    setDeal(relatedDeal1);
                }
            
                const relatedDeal2 = await Deals.findOne({
                    offset: Math.floor(Math.random() * (await Deals.count())),
                });
                const DealProduct2 = await DealProducts.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (DealProduct2?.setDeal)
                {
                    await
                    DealProduct2.
                    setDeal(relatedDeal2);
                }
            
                const relatedDeal3 = await Deals.findOne({
                    offset: Math.floor(Math.random() * (await Deals.count())),
                });
                const DealProduct3 = await DealProducts.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (DealProduct3?.setDeal)
                {
                    await
                    DealProduct3.
                    setDeal(relatedDeal3);
                }
            
        }
        
    

    
    
    
        
    
        
    

    
    
    
        
            
            async function associateLeadTagWithLead() {
            
                const relatedLead0 = await Leads.findOne({
                    offset: Math.floor(Math.random() * (await Leads.count())),
                });
                const LeadTag0 = await LeadTags.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (LeadTag0?.setLead)
                {
                    await
                    LeadTag0.
                    setLead(relatedLead0);
                }
            
                const relatedLead1 = await Leads.findOne({
                    offset: Math.floor(Math.random() * (await Leads.count())),
                });
                const LeadTag1 = await LeadTags.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (LeadTag1?.setLead)
                {
                    await
                    LeadTag1.
                    setLead(relatedLead1);
                }
            
                const relatedLead2 = await Leads.findOne({
                    offset: Math.floor(Math.random() * (await Leads.count())),
                });
                const LeadTag2 = await LeadTags.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (LeadTag2?.setLead)
                {
                    await
                    LeadTag2.
                    setLead(relatedLead2);
                }
            
                const relatedLead3 = await Leads.findOne({
                    offset: Math.floor(Math.random() * (await Leads.count())),
                });
                const LeadTag3 = await LeadTags.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (LeadTag3?.setLead)
                {
                    await
                    LeadTag3.
                    setLead(relatedLead3);
                }
            
        }
        
    
        
            
            async function associateLeadTagWithTag() {
            
                const relatedTag0 = await Tags.findOne({
                    offset: Math.floor(Math.random() * (await Tags.count())),
                });
                const LeadTag0 = await LeadTags.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (LeadTag0?.setTag)
                {
                    await
                    LeadTag0.
                    setTag(relatedTag0);
                }
            
                const relatedTag1 = await Tags.findOne({
                    offset: Math.floor(Math.random() * (await Tags.count())),
                });
                const LeadTag1 = await LeadTags.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (LeadTag1?.setTag)
                {
                    await
                    LeadTag1.
                    setTag(relatedTag1);
                }
            
                const relatedTag2 = await Tags.findOne({
                    offset: Math.floor(Math.random() * (await Tags.count())),
                });
                const LeadTag2 = await LeadTags.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (LeadTag2?.setTag)
                {
                    await
                    LeadTag2.
                    setTag(relatedTag2);
                }
            
                const relatedTag3 = await Tags.findOne({
                    offset: Math.floor(Math.random() * (await Tags.count())),
                });
                const LeadTag3 = await LeadTags.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (LeadTag3?.setTag)
                {
                    await
                    LeadTag3.
                    setTag(relatedTag3);
                }
            
        }
        
    

    
    
    
        
            
            async function associateDealTagWithDeal() {
            
                const relatedDeal0 = await Deals.findOne({
                    offset: Math.floor(Math.random() * (await Deals.count())),
                });
                const DealTag0 = await DealTags.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (DealTag0?.setDeal)
                {
                    await
                    DealTag0.
                    setDeal(relatedDeal0);
                }
            
                const relatedDeal1 = await Deals.findOne({
                    offset: Math.floor(Math.random() * (await Deals.count())),
                });
                const DealTag1 = await DealTags.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (DealTag1?.setDeal)
                {
                    await
                    DealTag1.
                    setDeal(relatedDeal1);
                }
            
                const relatedDeal2 = await Deals.findOne({
                    offset: Math.floor(Math.random() * (await Deals.count())),
                });
                const DealTag2 = await DealTags.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (DealTag2?.setDeal)
                {
                    await
                    DealTag2.
                    setDeal(relatedDeal2);
                }
            
                const relatedDeal3 = await Deals.findOne({
                    offset: Math.floor(Math.random() * (await Deals.count())),
                });
                const DealTag3 = await DealTags.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (DealTag3?.setDeal)
                {
                    await
                    DealTag3.
                    setDeal(relatedDeal3);
                }
            
        }
        
    
        
            
            async function associateDealTagWithTag() {
            
                const relatedTag0 = await Tags.findOne({
                    offset: Math.floor(Math.random() * (await Tags.count())),
                });
                const DealTag0 = await DealTags.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (DealTag0?.setTag)
                {
                    await
                    DealTag0.
                    setTag(relatedTag0);
                }
            
                const relatedTag1 = await Tags.findOne({
                    offset: Math.floor(Math.random() * (await Tags.count())),
                });
                const DealTag1 = await DealTags.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (DealTag1?.setTag)
                {
                    await
                    DealTag1.
                    setTag(relatedTag1);
                }
            
                const relatedTag2 = await Tags.findOne({
                    offset: Math.floor(Math.random() * (await Tags.count())),
                });
                const DealTag2 = await DealTags.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (DealTag2?.setTag)
                {
                    await
                    DealTag2.
                    setTag(relatedTag2);
                }
            
                const relatedTag3 = await Tags.findOne({
                    offset: Math.floor(Math.random() * (await Tags.count())),
                });
                const DealTag3 = await DealTags.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (DealTag3?.setTag)
                {
                    await
                    DealTag3.
                    setTag(relatedTag3);
                }
            
        }
        
    


module.exports = {
    up: async (queryInterface, Sequelize) => {
        
            
            
            
            
            
                
                await Companies.bulkCreate(CompaniesData);
                
            
            
                
                await Contacts.bulkCreate(ContactsData);
                
            
            
                
                await Pipelines.bulkCreate(PipelinesData);
                
            
            
                
                await PipelineStages.bulkCreate(PipelineStagesData);
                
            
            
                
                await Leads.bulkCreate(LeadsData);
                
            
            
                
                await Deals.bulkCreate(DealsData);
                
            
            
                
                await Activities.bulkCreate(ActivitiesData);
                
            
            
                
                await ActivityFiles.bulkCreate(ActivityFilesData);
                
            
            
                
                await DealProducts.bulkCreate(DealProductsData);
                
            
            
                
                await Tags.bulkCreate(TagsData);
                
            
            
                
                await LeadTags.bulkCreate(LeadTagsData);
                
            
            
                
                await DealTags.bulkCreate(DealTagsData);
                
            
            await Promise.all([
            
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        // Similar logic for "relation_many"
                    
                
            
                
                
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateCompanyWithOwner(),
                    
                
            
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateContactWithCompany(),
                    
                
                    
                        
                        await associateContactWithOwner(),
                    
                
            
                
                
                    
                
                    
                
                    
                
            
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associatePipelineStageWithPipeline(),
                    
                
            
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateLeadWithPrimary_contact(),
                    
                
                    
                        
                        await associateLeadWithCompany(),
                    
                
                    
                        
                        await associateLeadWithOwner(),
                    
                
            
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateDealWithPipeline(),
                    
                
                    
                        
                        await associateDealWithStage(),
                    
                
                    
                        
                        await associateDealWithCompany(),
                    
                
                    
                        
                        await associateDealWithPrimary_contact(),
                    
                
                    
                        
                        await associateDealWithOwner(),
                    
                
                    
                        
                        await associateDealWithLead(),
                    
                
            
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateActivityWithAssigned_to(),
                    
                
                    
                        
                        await associateActivityWithLead(),
                    
                
                    
                        
                        await associateActivityWithDeal(),
                    
                
                    
                        
                        await associateActivityWithContact(),
                    
                
            
                
                
                    
                
                    
                
                    
                        
                        await associateActivityFileWithActivity(),
                    
                
            
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateDealProductWithDeal(),
                    
                
            
                
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateLeadTagWithLead(),
                    
                
                    
                        
                        await associateLeadTagWithTag(),
                    
                
            
                
                
                    
                        
                        await associateDealTagWithDeal(),
                    
                
                    
                        
                        await associateDealTagWithTag(),
                    
                
            
            ]);
        
    },

    down: async (queryInterface, Sequelize) => {
        
            
            
            
            
            
            await queryInterface.bulkDelete('companies', null, {});
            
            
            await queryInterface.bulkDelete('contacts', null, {});
            
            
            await queryInterface.bulkDelete('pipelines', null, {});
            
            
            await queryInterface.bulkDelete('pipeline_stages', null, {});
            
            
            await queryInterface.bulkDelete('leads', null, {});
            
            
            await queryInterface.bulkDelete('deals', null, {});
            
            
            await queryInterface.bulkDelete('activities', null, {});
            
            
            await queryInterface.bulkDelete('activity_files', null, {});
            
            
            await queryInterface.bulkDelete('deal_products', null, {});
            
            
            await queryInterface.bulkDelete('tags', null, {});
            
            
            await queryInterface.bulkDelete('lead_tags', null, {});
            
            
            await queryInterface.bulkDelete('deal_tags', null, {});
            
        
    },
};