const db = require('../models'); const Users = db.users; const Activities = db.activities; const Contacts = db.contacts; const Leads = db.leads; const Metrics = db.metrics; const Notes = db.notes; const Organizations = db.organizations; const ActivitiesData = [ { description: 'Meeting with Acme Corporation', start_time: new Date('2023-10-01T10:00:00Z'), end_time: new Date('2023-10-01T11:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field }, { description: 'Call with Smith & Co', start_time: new Date('2023-10-02T14:00:00Z'), end_time: new Date('2023-10-02T14:30:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field }, { description: 'Document review for Greenfield Estates', start_time: new Date('2023-10-03T09:00:00Z'), end_time: new Date('2023-10-03T10:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field }, { description: 'Client feedback session for Johnson Family', start_time: new Date('2023-10-04T15:00:00Z'), end_time: new Date('2023-10-04T16:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const ContactsData = [ { first_name: 'Alice', last_name: 'Johnson', email: 'alice.johnson@acme.com', // type code here for "relation_one" field // type code here for "relation_one" field }, { first_name: 'Bob', last_name: 'Smith', email: 'bob.smith@acme.com', // type code here for "relation_one" field // type code here for "relation_one" field }, { first_name: 'Charlie', last_name: 'Brown', email: 'charlie.brown@smithco.com', // type code here for "relation_one" field // type code here for "relation_one" field }, { first_name: 'Diana', last_name: 'Green', email: 'diana.green@greenfield.com', // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const LeadsData = [ { name: 'Acme Corporation', status: 'lost', category: 'corporate', // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Smith & Co', status: 'new', category: 'litigation', // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Greenfield Estates', status: 'new', category: 'litigation', // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Johnson Family', status: 'contacted', category: 'real_estate', // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const MetricsData = [ { name: 'Lead Conversion Rate', value: 75.5, // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Client Satisfaction Score', value: 88, // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Case Resolution Time', value: 30, // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Marketing ROI', value: 120, // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const NotesData = [ { content: 'Initial meeting notes with Acme Corporation', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field }, { content: 'Follow-up required for Smith & Co', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field }, { content: 'Greenfield Estates needs contract review', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field }, { content: 'Johnson Family case closed', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const OrganizationsData = [ { name: 'Richard Feynman', }, { name: 'Erwin Schrodinger', }, { name: 'Gustav Kirchhoff', }, { name: 'Max Planck', }, ]; // Similar logic for "relation_many" async function associateUserWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const User0 = await Users.findOne({ order: [['id', 'ASC']], offset: 0, }); if (User0?.setOrganization) { await User0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const User1 = await Users.findOne({ order: [['id', 'ASC']], offset: 1, }); if (User1?.setOrganization) { await User1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const User2 = await Users.findOne({ order: [['id', 'ASC']], offset: 2, }); if (User2?.setOrganization) { await User2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const User3 = await Users.findOne({ order: [['id', 'ASC']], offset: 3, }); if (User3?.setOrganization) { await User3.setOrganization(relatedOrganization3); } } async function associateActivityWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Activity0 = await Activities.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Activity0?.setUser) { await Activity0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Activity1 = await Activities.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Activity1?.setUser) { await Activity1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Activity2 = await Activities.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Activity2?.setUser) { await Activity2.setUser(relatedUser2); } const relatedUser3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Activity3 = await Activities.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Activity3?.setUser) { await Activity3.setUser(relatedUser3); } } 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 associateActivityWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Activity0 = await Activities.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Activity0?.setOrganization) { await Activity0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Activity1 = await Activities.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Activity1?.setOrganization) { await Activity1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Activity2 = await Activities.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Activity2?.setOrganization) { await Activity2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Activity3 = await Activities.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Activity3?.setOrganization) { await Activity3.setOrganization(relatedOrganization3); } } async function associateContactWithLead() { const relatedLead0 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Contact0 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Contact0?.setLead) { await Contact0.setLead(relatedLead0); } const relatedLead1 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Contact1 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Contact1?.setLead) { await Contact1.setLead(relatedLead1); } const relatedLead2 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Contact2 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Contact2?.setLead) { await Contact2.setLead(relatedLead2); } const relatedLead3 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Contact3 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Contact3?.setLead) { await Contact3.setLead(relatedLead3); } } async function associateContactWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Contact0 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Contact0?.setOrganization) { await Contact0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Contact1 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Contact1?.setOrganization) { await Contact1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Contact2 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Contact2?.setOrganization) { await Contact2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Contact3 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Contact3?.setOrganization) { await Contact3.setOrganization(relatedOrganization3); } } 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); } } // Similar logic for "relation_many" async function associateLeadWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Lead0 = await Leads.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Lead0?.setOrganization) { await Lead0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Lead1 = await Leads.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Lead1?.setOrganization) { await Lead1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Lead2 = await Leads.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Lead2?.setOrganization) { await Lead2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Lead3 = await Leads.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Lead3?.setOrganization) { await Lead3.setOrganization(relatedOrganization3); } } async function associateMetricWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Metric0 = await Metrics.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Metric0?.setUser) { await Metric0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Metric1 = await Metrics.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Metric1?.setUser) { await Metric1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Metric2 = await Metrics.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Metric2?.setUser) { await Metric2.setUser(relatedUser2); } const relatedUser3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Metric3 = await Metrics.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Metric3?.setUser) { await Metric3.setUser(relatedUser3); } } async function associateMetricWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Metric0 = await Metrics.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Metric0?.setOrganization) { await Metric0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Metric1 = await Metrics.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Metric1?.setOrganization) { await Metric1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Metric2 = await Metrics.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Metric2?.setOrganization) { await Metric2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Metric3 = await Metrics.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Metric3?.setOrganization) { await Metric3.setOrganization(relatedOrganization3); } } async function associateNoteWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Note0 = await Notes.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Note0?.setUser) { await Note0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Note1 = await Notes.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Note1?.setUser) { await Note1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Note2 = await Notes.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Note2?.setUser) { await Note2.setUser(relatedUser2); } const relatedUser3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Note3 = await Notes.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Note3?.setUser) { await Note3.setUser(relatedUser3); } } async function associateNoteWithLead() { const relatedLead0 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Note0 = await Notes.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Note0?.setLead) { await Note0.setLead(relatedLead0); } const relatedLead1 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Note1 = await Notes.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Note1?.setLead) { await Note1.setLead(relatedLead1); } const relatedLead2 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Note2 = await Notes.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Note2?.setLead) { await Note2.setLead(relatedLead2); } const relatedLead3 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Note3 = await Notes.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Note3?.setLead) { await Note3.setLead(relatedLead3); } } async function associateNoteWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Note0 = await Notes.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Note0?.setOrganization) { await Note0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Note1 = await Notes.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Note1?.setOrganization) { await Note1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Note2 = await Notes.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Note2?.setOrganization) { await Note2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Note3 = await Notes.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Note3?.setOrganization) { await Note3.setOrganization(relatedOrganization3); } } module.exports = { up: async (queryInterface, Sequelize) => { await Activities.bulkCreate(ActivitiesData); await Contacts.bulkCreate(ContactsData); await Leads.bulkCreate(LeadsData); await Metrics.bulkCreate(MetricsData); await Notes.bulkCreate(NotesData); await Organizations.bulkCreate(OrganizationsData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithOrganization(), await associateActivityWithUser(), await associateActivityWithLead(), await associateActivityWithOrganization(), await associateContactWithLead(), await associateContactWithOrganization(), await associateLeadWithOwner(), // Similar logic for "relation_many" await associateLeadWithOrganization(), await associateMetricWithUser(), await associateMetricWithOrganization(), await associateNoteWithUser(), await associateNoteWithLead(), await associateNoteWithOrganization(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('activities', null, {}); await queryInterface.bulkDelete('contacts', null, {}); await queryInterface.bulkDelete('leads', null, {}); await queryInterface.bulkDelete('metrics', null, {}); await queryInterface.bulkDelete('notes', null, {}); await queryInterface.bulkDelete('organizations', null, {}); }, };