const db = require('../models'); const Users = db.users; const Companies = db.companies; const Contacts = db.contacts; const Leads = db.leads; const Deals = db.deals; const Activities = db.activities; const CompaniesData = [ { "name": "Acme Corporation", "website": "https://acme.example.com", "industry": "Finance", "employee_count": 120, // type code here for "relation_one" field "description": "Global provider of industrial and software solutions", }, { "name": "Greenfield Solutions", "website": "https://greenfield.example.com", "industry": "Technology", "employee_count": 65, // type code here for "relation_one" field "description": "Financial services consultancy focused on SMBs", }, { "name": "Horizon Health", "website": "https://horizonhealth.example.com", "industry": "Finance", "employee_count": 320, // type code here for "relation_one" field "description": "Regional healthcare provider and clinic network", }, ]; const ContactsData = [ { "full_name": "Grace Lin", "email": "grace.lin@acme.example.com", "phone": "+1-415-555-0201", "job_title": "Head of Product", // type code here for "relation_one" field // type code here for "relation_one" field "source": "Event", }, { "full_name": "Marcus Ruiz", "email": "marcus.ruiz@greenfield.example.com", "phone": "+1-415-555-0202", "job_title": "Finance Manager", // type code here for "relation_one" field // type code here for "relation_one" field "source": "Other", }, { "full_name": "Sofia Alvarez", "email": "sofia.alvarez@horizonhealth.example.com", "phone": "+1-415-555-0203", "job_title": "Procurement Lead", // type code here for "relation_one" field // type code here for "relation_one" field "source": "Event", }, ]; const LeadsData = [ { "name": "Acme Mobile App Opportunity", "email": "grace.lin@acme.example.com", "phone": "+1-415-555-0201", "source": "Event", "status": "Contacted", // type code here for "relation_one" field // type code here for "relation_one" field "value": 25000.0, "next_follow_up": new Date('2026-01-20T10:00:00Z'), }, { "name": "Greenfield Payment Integration", "email": "marcus.ruiz@greenfield.example.com", "phone": "+1-415-555-0202", "source": "Website", "status": "New", // type code here for "relation_one" field // type code here for "relation_one" field "value": 48000.0, "next_follow_up": new Date('2026-01-18T14:00:00Z'), }, { "name": "Horizon Health Contract", "email": "sofia.alvarez@horizonhealth.example.com", "phone": "+1-415-555-0203", "source": "Other", "status": "Unqualified", // type code here for "relation_one" field // type code here for "relation_one" field "value": 150000.0, "next_follow_up": new Date('2026-01-25T09:00:00Z'), }, ]; const DealsData = [ { "name": "Acme Enterprise Implementation", "amount": 120000.0, "currency": "GBP", "stage": "Negotiation", // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field "close_date": new Date('2026-03-15T00:00:00Z'), "probability": 60, }, { "name": "Greenfield Payment Platform", "amount": 48000.0, "currency": "EUR", "stage": "ClosedLost", // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field "close_date": new Date('2026-02-28T00:00:00Z'), "probability": 75, }, { "name": "Horizon Health Records", "amount": 150000.0, "currency": "EUR", "stage": "Qualification", // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field "close_date": new Date('2026-04-01T00:00:00Z'), "probability": 40, }, ]; const ActivitiesData = [ { "subject": "Intro call with Acme product team", "activity_type": "Email", "start": new Date('2026-01-20T10:00:00Z'), "end": new Date('2026-01-20T10:30:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field "completed": false, "notes": "Discuss initial scope and timeline", }, { "subject": "Pricing review with Greenfield", "activity_type": "Task", "start": new Date('2026-01-18T14:00:00Z'), "end": new Date('2026-01-18T15:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field "completed": true, "notes": "Reviewed tiered pricing and integration options", }, { "subject": "Discovery session Horizon Health", "activity_type": "Task", "start": new Date('2026-01-25T09:00:00Z'), "end": new Date('2026-01-25T10:30:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field "completed": false, "notes": "Map existing workflows and data sources", }, ]; // 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); } } 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); } } 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); } } 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); } } async function associateLeadWithContact() { const relatedContact0 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const Lead0 = await Leads.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Lead0?.setContact) { await Lead0. setContact(relatedContact0); } const relatedContact1 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const Lead1 = await Leads.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Lead1?.setContact) { await Lead1. setContact(relatedContact1); } const relatedContact2 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const Lead2 = await Leads.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Lead2?.setContact) { await Lead2. setContact(relatedContact2); } } 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); } } async function associateDealWithContact() { const relatedContact0 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const Deal0 = await Deals.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Deal0?.setContact) { await Deal0. setContact(relatedContact0); } const relatedContact1 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const Deal1 = await Deals.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Deal1?.setContact) { await Deal1. setContact(relatedContact1); } const relatedContact2 = await Contacts.findOne({ offset: Math.floor(Math.random() * (await Contacts.count())), }); const Deal2 = await Deals.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Deal2?.setContact) { await Deal2. setContact(relatedContact2); } } 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); } } 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); } } 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); } } async function associateActivityWithOwner() { const relatedOwner0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Activity0 = await Activities.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Activity0?.setOwner) { await Activity0. setOwner(relatedOwner0); } const relatedOwner1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Activity1 = await Activities.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Activity1?.setOwner) { await Activity1. setOwner(relatedOwner1); } const relatedOwner2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Activity2 = await Activities.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Activity2?.setOwner) { await Activity2. setOwner(relatedOwner2); } } module.exports = { up: async (queryInterface, Sequelize) => { await Companies.bulkCreate(CompaniesData); await Contacts.bulkCreate(ContactsData); await Leads.bulkCreate(LeadsData); await Deals.bulkCreate(DealsData); await Activities.bulkCreate(ActivitiesData); await Promise.all([ // Similar logic for "relation_many" await associateCompanyWithOwner(), await associateContactWithCompany(), await associateContactWithOwner(), await associateLeadWithOwner(), await associateLeadWithContact(), await associateDealWithOwner(), await associateDealWithContact(), await associateDealWithCompany(), await associateActivityWithDeal(), await associateActivityWithLead(), await associateActivityWithOwner(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('companies', null, {}); await queryInterface.bulkDelete('contacts', null, {}); await queryInterface.bulkDelete('leads', null, {}); await queryInterface.bulkDelete('deals', null, {}); await queryInterface.bulkDelete('activities', null, {}); }, };