const db = require('../models'); const Users = db.users; const Applications = db.applications; const Candidates = db.candidates; const HrManagers = db.hr_managers; const Jobs = db.jobs; const Recruiters = db.recruiters; const Organizations = db.organizations; const ApplicationsData = [ { // type code here for "relation_one" field // type code here for "relation_one" field applied_date: new Date('2023-10-01T10:00:00Z'), stage: 'Offer', // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field applied_date: new Date('2023-10-02T11:00:00Z'), stage: 'Offer', // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field applied_date: new Date('2023-10-03T12:00:00Z'), stage: 'Interview', // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field applied_date: new Date('2023-10-04T13:00:00Z'), stage: 'Interview', // type code here for "relation_one" field }, ]; const CandidatesData = [ { name: 'Sophia Lee', email: 'sophia.lee@candidates.com', status: 'Hired', // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Liam Harris', email: 'liam.harris@candidates.com', status: 'New', // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Olivia Walker', email: 'olivia.walker@candidates.com', status: 'Interviewing', // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Noah Young', email: 'noah.young@candidates.com', status: 'Interviewing', // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const HrManagersData = [ { name: 'Grace Thompson', email: 'grace.thompson@hr.com', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Henry White', email: 'henry.white@hr.com', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Isabella Scott', email: 'isabella.scott@hr.com', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'James Green', email: 'james.green@hr.com', // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const JobsData = [ { title: 'Software Engineer', description: 'Develop and maintain software applications.', // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Data Analyst', description: 'Analyze data to support business decisions.', // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Project Manager', description: 'Manage project timelines and deliverables.', // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'UX Designer', description: 'Design user interfaces and experiences.', // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const RecruitersData = [ { name: 'Alice Johnson', email: 'alice.johnson@recruitment.com', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Bob Martin', email: 'bob.martin@recruitment.com', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Charlie Davis', email: 'charlie.davis@recruitment.com', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Diana Evans', email: 'diana.evans@recruitment.com', // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const OrganizationsData = [ { name: 'Charles Sherrington', }, { name: 'Nicolaus Copernicus', }, { name: 'Comte de Buffon', }, { name: 'Richard Feynman', }, ]; // 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 associateApplicationWithCandidate() { const relatedCandidate0 = await Candidates.findOne({ offset: Math.floor(Math.random() * (await Candidates.count())), }); const Application0 = await Applications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Application0?.setCandidate) { await Application0.setCandidate(relatedCandidate0); } const relatedCandidate1 = await Candidates.findOne({ offset: Math.floor(Math.random() * (await Candidates.count())), }); const Application1 = await Applications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Application1?.setCandidate) { await Application1.setCandidate(relatedCandidate1); } const relatedCandidate2 = await Candidates.findOne({ offset: Math.floor(Math.random() * (await Candidates.count())), }); const Application2 = await Applications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Application2?.setCandidate) { await Application2.setCandidate(relatedCandidate2); } const relatedCandidate3 = await Candidates.findOne({ offset: Math.floor(Math.random() * (await Candidates.count())), }); const Application3 = await Applications.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Application3?.setCandidate) { await Application3.setCandidate(relatedCandidate3); } } async function associateApplicationWithJob() { const relatedJob0 = await Jobs.findOne({ offset: Math.floor(Math.random() * (await Jobs.count())), }); const Application0 = await Applications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Application0?.setJob) { await Application0.setJob(relatedJob0); } const relatedJob1 = await Jobs.findOne({ offset: Math.floor(Math.random() * (await Jobs.count())), }); const Application1 = await Applications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Application1?.setJob) { await Application1.setJob(relatedJob1); } const relatedJob2 = await Jobs.findOne({ offset: Math.floor(Math.random() * (await Jobs.count())), }); const Application2 = await Applications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Application2?.setJob) { await Application2.setJob(relatedJob2); } const relatedJob3 = await Jobs.findOne({ offset: Math.floor(Math.random() * (await Jobs.count())), }); const Application3 = await Applications.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Application3?.setJob) { await Application3.setJob(relatedJob3); } } async function associateApplicationWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Application0 = await Applications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Application0?.setOrganization) { await Application0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Application1 = await Applications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Application1?.setOrganization) { await Application1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Application2 = await Applications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Application2?.setOrganization) { await Application2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Application3 = await Applications.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Application3?.setOrganization) { await Application3.setOrganization(relatedOrganization3); } } async function associateCandidateWithRecruiter() { const relatedRecruiter0 = await Recruiters.findOne({ offset: Math.floor(Math.random() * (await Recruiters.count())), }); const Candidate0 = await Candidates.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Candidate0?.setRecruiter) { await Candidate0.setRecruiter(relatedRecruiter0); } const relatedRecruiter1 = await Recruiters.findOne({ offset: Math.floor(Math.random() * (await Recruiters.count())), }); const Candidate1 = await Candidates.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Candidate1?.setRecruiter) { await Candidate1.setRecruiter(relatedRecruiter1); } const relatedRecruiter2 = await Recruiters.findOne({ offset: Math.floor(Math.random() * (await Recruiters.count())), }); const Candidate2 = await Candidates.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Candidate2?.setRecruiter) { await Candidate2.setRecruiter(relatedRecruiter2); } const relatedRecruiter3 = await Recruiters.findOne({ offset: Math.floor(Math.random() * (await Recruiters.count())), }); const Candidate3 = await Candidates.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Candidate3?.setRecruiter) { await Candidate3.setRecruiter(relatedRecruiter3); } } // Similar logic for "relation_many" async function associateCandidateWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Candidate0 = await Candidates.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Candidate0?.setOrganization) { await Candidate0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Candidate1 = await Candidates.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Candidate1?.setOrganization) { await Candidate1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Candidate2 = await Candidates.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Candidate2?.setOrganization) { await Candidate2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Candidate3 = await Candidates.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Candidate3?.setOrganization) { await Candidate3.setOrganization(relatedOrganization3); } } // Similar logic for "relation_many" async function associateHrManagerWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const HrManager0 = await HrManagers.findOne({ order: [['id', 'ASC']], offset: 0, }); if (HrManager0?.setOrganization) { await HrManager0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const HrManager1 = await HrManagers.findOne({ order: [['id', 'ASC']], offset: 1, }); if (HrManager1?.setOrganization) { await HrManager1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const HrManager2 = await HrManagers.findOne({ order: [['id', 'ASC']], offset: 2, }); if (HrManager2?.setOrganization) { await HrManager2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const HrManager3 = await HrManagers.findOne({ order: [['id', 'ASC']], offset: 3, }); if (HrManager3?.setOrganization) { await HrManager3.setOrganization(relatedOrganization3); } } // Similar logic for "relation_many" async function associateJobWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Job0 = await Jobs.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Job0?.setOrganization) { await Job0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Job1 = await Jobs.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Job1?.setOrganization) { await Job1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Job2 = await Jobs.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Job2?.setOrganization) { await Job2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Job3 = await Jobs.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Job3?.setOrganization) { await Job3.setOrganization(relatedOrganization3); } } // Similar logic for "relation_many" async function associateRecruiterWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Recruiter0 = await Recruiters.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Recruiter0?.setOrganization) { await Recruiter0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Recruiter1 = await Recruiters.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Recruiter1?.setOrganization) { await Recruiter1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Recruiter2 = await Recruiters.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Recruiter2?.setOrganization) { await Recruiter2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Recruiter3 = await Recruiters.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Recruiter3?.setOrganization) { await Recruiter3.setOrganization(relatedOrganization3); } } module.exports = { up: async (queryInterface, Sequelize) => { await Applications.bulkCreate(ApplicationsData); await Candidates.bulkCreate(CandidatesData); await HrManagers.bulkCreate(HrManagersData); await Jobs.bulkCreate(JobsData); await Recruiters.bulkCreate(RecruitersData); await Organizations.bulkCreate(OrganizationsData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithOrganization(), await associateApplicationWithCandidate(), await associateApplicationWithJob(), await associateApplicationWithOrganization(), await associateCandidateWithRecruiter(), // Similar logic for "relation_many" await associateCandidateWithOrganization(), // Similar logic for "relation_many" await associateHrManagerWithOrganization(), // Similar logic for "relation_many" await associateJobWithOrganization(), // Similar logic for "relation_many" await associateRecruiterWithOrganization(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('applications', null, {}); await queryInterface.bulkDelete('candidates', null, {}); await queryInterface.bulkDelete('hr_managers', null, {}); await queryInterface.bulkDelete('jobs', null, {}); await queryInterface.bulkDelete('recruiters', null, {}); await queryInterface.bulkDelete('organizations', null, {}); }, };