const db = require('../models'); const Users = db.users; const AiSuggestions = db.ai_suggestions; const Resumes = db.resumes; const Templates = db.templates; const AiSuggestionsData = [ { content: 'Consider adding more details to your work experience.', // type code here for "relation_one" field suggested_at: new Date('2023-10-01T14:00:00Z'), }, { content: 'Use action verbs to describe your achievements.', // type code here for "relation_one" field suggested_at: new Date('2023-10-02T15:00:00Z'), }, { content: 'Highlight your key skills in the summary section.', // type code here for "relation_one" field suggested_at: new Date('2023-10-03T16:00:00Z'), }, ]; const ResumesData = [ { title: 'Software Engineer Resume', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "files" field }, { title: 'Marketing Specialist Resume', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "files" field }, { title: 'Graphic Designer Resume', // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "files" field }, ]; const TemplatesData = [ { name: 'Modern Template', description: 'A sleek and modern resume template.', // type code here for "images" field }, { name: 'Classic Template', description: 'A traditional resume layout with a classic touch.', // type code here for "images" field }, { name: 'Creative Template', description: 'A colorful and creative resume design.', // type code here for "images" field }, ]; // Similar logic for "relation_many" async function associateAiSuggestionWithResume() { const relatedResume0 = await Resumes.findOne({ offset: Math.floor(Math.random() * (await Resumes.count())), }); const AiSuggestion0 = await AiSuggestions.findOne({ order: [['id', 'ASC']], offset: 0, }); if (AiSuggestion0?.setResume) { await AiSuggestion0.setResume(relatedResume0); } const relatedResume1 = await Resumes.findOne({ offset: Math.floor(Math.random() * (await Resumes.count())), }); const AiSuggestion1 = await AiSuggestions.findOne({ order: [['id', 'ASC']], offset: 1, }); if (AiSuggestion1?.setResume) { await AiSuggestion1.setResume(relatedResume1); } const relatedResume2 = await Resumes.findOne({ offset: Math.floor(Math.random() * (await Resumes.count())), }); const AiSuggestion2 = await AiSuggestions.findOne({ order: [['id', 'ASC']], offset: 2, }); if (AiSuggestion2?.setResume) { await AiSuggestion2.setResume(relatedResume2); } } 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); } } async function associateResumeWithTemplate() { const relatedTemplate0 = await Templates.findOne({ offset: Math.floor(Math.random() * (await Templates.count())), }); const Resume0 = await Resumes.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Resume0?.setTemplate) { await Resume0.setTemplate(relatedTemplate0); } const relatedTemplate1 = await Templates.findOne({ offset: Math.floor(Math.random() * (await Templates.count())), }); const Resume1 = await Resumes.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Resume1?.setTemplate) { await Resume1.setTemplate(relatedTemplate1); } const relatedTemplate2 = await Templates.findOne({ offset: Math.floor(Math.random() * (await Templates.count())), }); const Resume2 = await Resumes.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Resume2?.setTemplate) { await Resume2.setTemplate(relatedTemplate2); } } module.exports = { up: async (queryInterface, Sequelize) => { await AiSuggestions.bulkCreate(AiSuggestionsData); await Resumes.bulkCreate(ResumesData); await Templates.bulkCreate(TemplatesData); await Promise.all([ // Similar logic for "relation_many" await associateAiSuggestionWithResume(), await associateResumeWithUser(), await associateResumeWithTemplate(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('ai_suggestions', null, {}); await queryInterface.bulkDelete('resumes', null, {}); await queryInterface.bulkDelete('templates', null, {}); }, };