const db = require('../models'); const Users = db.users; const Clients = db.clients; const InteractionLogs = db.interaction_logs; const Projects = db.projects; const Reminders = db.reminders; const ClientsData = [ { name: 'Acme Corp', email: 'contact@acmecorp.com', phone: '1234567890', company: 'Acme Corporation', notes: 'Key client with multiple projects.', // type code here for "relation_one" field }, { name: 'Globex Inc', email: 'info@globex.com', phone: '0987654321', company: 'Globex International', notes: 'Potential for future collaboration.', // type code here for "relation_one" field }, { name: 'Initech', email: 'support@initech.com', phone: '1122334455', company: 'Initech Solutions', notes: 'Regular client with monthly projects.', // type code here for "relation_one" field }, { name: 'Umbrella Corp', email: 'admin@umbrella.com', phone: '2233445566', company: 'Umbrella Corporation', notes: 'High priority client.', // type code here for "relation_one" field }, ]; const InteractionLogsData = [ { date: new Date('2025-04-01T10:00:00Z'), interaction_type: 'Meeting', notes: 'Discussed project requirements.', // type code here for "relation_one" field // type code here for "relation_one" field }, { date: new Date('2025-04-05T14:00:00Z'), interaction_type: 'Call', notes: 'Reviewed project milestones.', // type code here for "relation_one" field // type code here for "relation_one" field }, { date: new Date('2025-04-10T09:30:00Z'), interaction_type: 'Email', notes: 'Sent project proposal.', // type code here for "relation_one" field // type code here for "relation_one" field }, { date: new Date('2025-04-12T11:00:00Z'), interaction_type: 'Call', notes: 'Follow-up on project status.', // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const ProjectsData = [ { title: 'Website Redesign', budget: 5000, deadline: new Date('2025-05-15T00:00:00Z'), status: 'Completed', // type code here for "relation_one" field }, { title: 'Mobile App Development', budget: 15000, deadline: new Date('2025-06-30T00:00:00Z'), status: 'Completed', // type code here for "relation_one" field }, { title: 'SEO Optimization', budget: 3000, deadline: new Date('2025-04-20T00:00:00Z'), status: 'InProgress', // type code here for "relation_one" field }, { title: 'Cloud Migration', budget: 20000, deadline: new Date('2025-07-10T00:00:00Z'), status: 'Completed', // type code here for "relation_one" field }, ]; const RemindersData = [ { reminder_date: new Date('2025-04-20T09:00:00Z'), description: 'Submit project proposal.', // type code here for "relation_one" field // type code here for "relation_one" field }, { reminder_date: new Date('2025-04-25T10:00:00Z'), description: 'Review project progress.', // type code here for "relation_one" field // type code here for "relation_one" field }, { reminder_date: new Date('2025-04-30T11:00:00Z'), description: 'Send invoice.', // type code here for "relation_one" field // type code here for "relation_one" field }, { reminder_date: new Date('2025-05-05T12:00:00Z'), description: 'Schedule follow-up meeting.', // type code here for "relation_one" field // type code here for "relation_one" field }, ]; // Similar logic for "relation_many" async function associateClientWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Client0 = await Clients.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Client0?.setUser) { await Client0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Client1 = await Clients.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Client1?.setUser) { await Client1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Client2 = await Clients.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Client2?.setUser) { await Client2.setUser(relatedUser2); } const relatedUser3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Client3 = await Clients.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Client3?.setUser) { await Client3.setUser(relatedUser3); } } async function associateInteractionLogWithClient() { const relatedClient0 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const InteractionLog0 = await InteractionLogs.findOne({ order: [['id', 'ASC']], offset: 0, }); if (InteractionLog0?.setClient) { await InteractionLog0.setClient(relatedClient0); } const relatedClient1 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const InteractionLog1 = await InteractionLogs.findOne({ order: [['id', 'ASC']], offset: 1, }); if (InteractionLog1?.setClient) { await InteractionLog1.setClient(relatedClient1); } const relatedClient2 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const InteractionLog2 = await InteractionLogs.findOne({ order: [['id', 'ASC']], offset: 2, }); if (InteractionLog2?.setClient) { await InteractionLog2.setClient(relatedClient2); } const relatedClient3 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const InteractionLog3 = await InteractionLogs.findOne({ order: [['id', 'ASC']], offset: 3, }); if (InteractionLog3?.setClient) { await InteractionLog3.setClient(relatedClient3); } } async function associateInteractionLogWithProject() { const relatedProject0 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const InteractionLog0 = await InteractionLogs.findOne({ order: [['id', 'ASC']], offset: 0, }); if (InteractionLog0?.setProject) { await InteractionLog0.setProject(relatedProject0); } const relatedProject1 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const InteractionLog1 = await InteractionLogs.findOne({ order: [['id', 'ASC']], offset: 1, }); if (InteractionLog1?.setProject) { await InteractionLog1.setProject(relatedProject1); } const relatedProject2 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const InteractionLog2 = await InteractionLogs.findOne({ order: [['id', 'ASC']], offset: 2, }); if (InteractionLog2?.setProject) { await InteractionLog2.setProject(relatedProject2); } const relatedProject3 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const InteractionLog3 = await InteractionLogs.findOne({ order: [['id', 'ASC']], offset: 3, }); if (InteractionLog3?.setProject) { await InteractionLog3.setProject(relatedProject3); } } async function associateProjectWithClient() { const relatedClient0 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const Project0 = await Projects.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Project0?.setClient) { await Project0.setClient(relatedClient0); } const relatedClient1 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const Project1 = await Projects.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Project1?.setClient) { await Project1.setClient(relatedClient1); } const relatedClient2 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const Project2 = await Projects.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Project2?.setClient) { await Project2.setClient(relatedClient2); } const relatedClient3 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const Project3 = await Projects.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Project3?.setClient) { await Project3.setClient(relatedClient3); } } async function associateReminderWithClient() { const relatedClient0 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const Reminder0 = await Reminders.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Reminder0?.setClient) { await Reminder0.setClient(relatedClient0); } const relatedClient1 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const Reminder1 = await Reminders.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Reminder1?.setClient) { await Reminder1.setClient(relatedClient1); } const relatedClient2 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const Reminder2 = await Reminders.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Reminder2?.setClient) { await Reminder2.setClient(relatedClient2); } const relatedClient3 = await Clients.findOne({ offset: Math.floor(Math.random() * (await Clients.count())), }); const Reminder3 = await Reminders.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Reminder3?.setClient) { await Reminder3.setClient(relatedClient3); } } async function associateReminderWithProject() { const relatedProject0 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Reminder0 = await Reminders.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Reminder0?.setProject) { await Reminder0.setProject(relatedProject0); } const relatedProject1 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Reminder1 = await Reminders.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Reminder1?.setProject) { await Reminder1.setProject(relatedProject1); } const relatedProject2 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Reminder2 = await Reminders.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Reminder2?.setProject) { await Reminder2.setProject(relatedProject2); } const relatedProject3 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Reminder3 = await Reminders.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Reminder3?.setProject) { await Reminder3.setProject(relatedProject3); } } module.exports = { up: async (queryInterface, Sequelize) => { await Clients.bulkCreate(ClientsData); await InteractionLogs.bulkCreate(InteractionLogsData); await Projects.bulkCreate(ProjectsData); await Reminders.bulkCreate(RemindersData); await Promise.all([ // Similar logic for "relation_many" await associateClientWithUser(), await associateInteractionLogWithClient(), await associateInteractionLogWithProject(), await associateProjectWithClient(), await associateReminderWithClient(), await associateReminderWithProject(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('clients', null, {}); await queryInterface.bulkDelete('interaction_logs', null, {}); await queryInterface.bulkDelete('projects', null, {}); await queryInterface.bulkDelete('reminders', null, {}); }, };