191 lines
4.1 KiB
JavaScript
191 lines
4.1 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const CvDrafts = db.cv_drafts;
|
|
|
|
const Templates = db.templates;
|
|
|
|
const CvDraftsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
template_id: 'modern',
|
|
|
|
personal_info: 'John Doe, Software Engineer',
|
|
|
|
work_experience: 'Developed web applications using React and Node.js.',
|
|
|
|
education: 'BSc in Computer Science, MIT',
|
|
|
|
skills: 'JavaScript, React, Node.js',
|
|
|
|
projects: 'E-commerce platform development',
|
|
|
|
certifications: 'AWS Certified Solutions Architect',
|
|
|
|
last_updated: new Date('2023-10-01T12:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
template_id: 'classic',
|
|
|
|
personal_info: 'Jane Smith, Marketing Specialist',
|
|
|
|
work_experience: 'Managed digital marketing campaigns.',
|
|
|
|
education: 'MBA, Harvard Business School',
|
|
|
|
skills: 'SEO, Google Analytics, Content Marketing',
|
|
|
|
projects: 'Brand awareness campaign',
|
|
|
|
certifications: 'Google Analytics Certified',
|
|
|
|
last_updated: new Date('2023-10-02T15:30:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
template_id: 'minimalist',
|
|
|
|
personal_info: 'Michael Brown, Data Analyst',
|
|
|
|
work_experience: 'Analyzed data trends for business insights.',
|
|
|
|
education: 'MSc in Data Science, Stanford University',
|
|
|
|
skills: 'Python, SQL, Data Visualization',
|
|
|
|
projects: 'Sales data analysis',
|
|
|
|
certifications: 'Certified Data Analyst',
|
|
|
|
last_updated: new Date('2023-10-03T09:45:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
template_id: 'modern',
|
|
|
|
personal_info: 'Emily Jones, Graphic Designer',
|
|
|
|
work_experience: 'Designed marketing materials and branding.',
|
|
|
|
education: 'BA in Graphic Design, Rhode Island School of Design',
|
|
|
|
skills: 'Adobe Creative Suite, UX/UI Design',
|
|
|
|
projects: 'Corporate rebranding',
|
|
|
|
certifications: 'Adobe Certified Expert',
|
|
|
|
last_updated: new Date('2023-10-04T11:20:00Z'),
|
|
},
|
|
];
|
|
|
|
const TemplatesData = [
|
|
{
|
|
name: 'Modern',
|
|
|
|
thumbnail_url: 'modern_template_thumbnail.png',
|
|
|
|
// type code here for "files" field
|
|
},
|
|
|
|
{
|
|
name: 'Classic',
|
|
|
|
thumbnail_url: 'classic_template_thumbnail.png',
|
|
|
|
// type code here for "files" field
|
|
},
|
|
|
|
{
|
|
name: 'Minimalist',
|
|
|
|
thumbnail_url: 'minimalist_template_thumbnail.png',
|
|
|
|
// type code here for "files" field
|
|
},
|
|
|
|
{
|
|
name: 'Creative',
|
|
|
|
thumbnail_url: 'creative_template_thumbnail.png',
|
|
|
|
// type code here for "files" field
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateCvDraftWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const CvDraft0 = await CvDrafts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (CvDraft0?.setUser) {
|
|
await CvDraft0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const CvDraft1 = await CvDrafts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (CvDraft1?.setUser) {
|
|
await CvDraft1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const CvDraft2 = await CvDrafts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (CvDraft2?.setUser) {
|
|
await CvDraft2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const CvDraft3 = await CvDrafts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (CvDraft3?.setUser) {
|
|
await CvDraft3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await CvDrafts.bulkCreate(CvDraftsData);
|
|
|
|
await Templates.bulkCreate(TemplatesData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateCvDraftWithUser(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('cv_drafts', null, {});
|
|
|
|
await queryInterface.bulkDelete('templates', null, {});
|
|
},
|
|
};
|