const db = require('../models'); const Users = db.users; const Analyses = db.analyses; const JobDescriptions = db.job_descriptions; const Resumes = db.resumes; const AnalysesData = [ { // type code here for "relation_one" field // type code here for "relation_one" field recommendations: 'Add React projects to experience.', approved: true, }, { // type code here for "relation_one" field // type code here for "relation_one" field recommendations: 'Highlight machine learning skills.', approved: true, }, { // type code here for "relation_one" field // type code here for "relation_one" field recommendations: 'Include agile methodologies.', approved: true, }, ]; const JobDescriptionsData = [ { title: 'Frontend Developer JD', content: 'Looking for a skilled frontend developer with experience in React.', // type code here for "relation_one" field }, { title: 'Data Scientist JD', content: 'Seeking a data scientist with expertise in machine learning.', // type code here for "relation_one" field }, { title: 'Product Manager JD', content: 'Need a product manager with agile experience.', // type code here for "relation_one" field }, ]; const ResumesData = [ { title: 'Software Engineer Resume', // type code here for "files" field // type code here for "relation_one" field }, { title: 'Data Analyst Resume', // type code here for "files" field // type code here for "relation_one" field }, { title: 'Project Manager Resume', // type code here for "files" field // type code here for "relation_one" field }, ]; // Similar logic for "relation_many" async function associateAnalysisWithResume() { const relatedResume0 = await Resumes.findOne({ offset: Math.floor(Math.random() * (await Resumes.count())), }); const Analysis0 = await Analyses.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Analysis0?.setResume) { await Analysis0.setResume(relatedResume0); } const relatedResume1 = await Resumes.findOne({ offset: Math.floor(Math.random() * (await Resumes.count())), }); const Analysis1 = await Analyses.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Analysis1?.setResume) { await Analysis1.setResume(relatedResume1); } const relatedResume2 = await Resumes.findOne({ offset: Math.floor(Math.random() * (await Resumes.count())), }); const Analysis2 = await Analyses.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Analysis2?.setResume) { await Analysis2.setResume(relatedResume2); } } async function associateAnalysisWithJob_description() { const relatedJob_description0 = await JobDescriptions.findOne({ offset: Math.floor(Math.random() * (await JobDescriptions.count())), }); const Analysis0 = await Analyses.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Analysis0?.setJob_description) { await Analysis0.setJob_description(relatedJob_description0); } const relatedJob_description1 = await JobDescriptions.findOne({ offset: Math.floor(Math.random() * (await JobDescriptions.count())), }); const Analysis1 = await Analyses.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Analysis1?.setJob_description) { await Analysis1.setJob_description(relatedJob_description1); } const relatedJob_description2 = await JobDescriptions.findOne({ offset: Math.floor(Math.random() * (await JobDescriptions.count())), }); const Analysis2 = await Analyses.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Analysis2?.setJob_description) { await Analysis2.setJob_description(relatedJob_description2); } } async function associateJobDescriptionWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const JobDescription0 = await JobDescriptions.findOne({ order: [['id', 'ASC']], offset: 0, }); if (JobDescription0?.setUser) { await JobDescription0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const JobDescription1 = await JobDescriptions.findOne({ order: [['id', 'ASC']], offset: 1, }); if (JobDescription1?.setUser) { await JobDescription1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const JobDescription2 = await JobDescriptions.findOne({ order: [['id', 'ASC']], offset: 2, }); if (JobDescription2?.setUser) { await JobDescription2.setUser(relatedUser2); } } async function associateResumeWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Resume0 = await Resumes.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Resume0?.setUser) { await Resume0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Resume1 = await Resumes.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Resume1?.setUser) { await Resume1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Resume2 = await Resumes.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Resume2?.setUser) { await Resume2.setUser(relatedUser2); } } module.exports = { up: async (queryInterface, Sequelize) => { await Analyses.bulkCreate(AnalysesData); await JobDescriptions.bulkCreate(JobDescriptionsData); await Resumes.bulkCreate(ResumesData); await Promise.all([ // Similar logic for "relation_many" await associateAnalysisWithResume(), await associateAnalysisWithJob_description(), await associateJobDescriptionWithUser(), await associateResumeWithUser(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('analyses', null, {}); await queryInterface.bulkDelete('job_descriptions', null, {}); await queryInterface.bulkDelete('resumes', null, {}); }, };