const db = require('../models'); const Users = db.users; const Courses = db.courses; const Enrollments = db.enrollments; const Companies = db.companies; const CoursesData = [ { title: 'Effective Communication', description: 'Improve verbal and written communication skills.', category: 'customer_service', // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Leadership Essentials', description: 'Develop leadership and management skills.', category: 'teamwork', // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Emotional Intelligence Mastery', description: 'Enhance self-awareness and empathy.', category: 'emotional_intelligence', // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Time Management Techniques', description: 'Learn to prioritize tasks effectively.', category: 'teamwork', // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Critical Thinking Skills', description: 'Build analytical and problem-solving skills.', category: 'time_management', // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const EnrollmentsData = [ { // type code here for "relation_one" field // type code here for "relation_one" field enrollment_date: new Date('2023-01-15T09:00:00Z'), completion_date: new Date('2023-02-15T09:00:00Z'), completed: true, // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field enrollment_date: new Date('2023-01-20T09:00:00Z'), completion_date: new Date('2023-02-20T09:00:00Z'), completed: true, // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field enrollment_date: new Date('2023-01-25T09:00:00Z'), completion_date: new Date('2023-02-25T09:00:00Z'), completed: true, // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field enrollment_date: new Date('2023-02-01T09:00:00Z'), completion_date: new Date('2023-03-01T09:00:00Z'), completed: true, // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field enrollment_date: new Date('2023-02-05T09:00:00Z'), completion_date: new Date('2023-03-05T09:00:00Z'), completed: true, // type code here for "relation_one" field }, ]; const CompaniesData = [ { name: 'Tech Innovators', }, { name: 'Health Solutions', }, { name: 'Retail Giants', }, { name: 'Manufacturing Hub', }, { name: 'Service Experts', }, ]; // Similar logic for "relation_many" async function associateUserWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const User0 = await Users.findOne({ order: [['id', 'ASC']], offset: 0, }); if (User0?.setCompany) { await User0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const User1 = await Users.findOne({ order: [['id', 'ASC']], offset: 1, }); if (User1?.setCompany) { await User1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const User2 = await Users.findOne({ order: [['id', 'ASC']], offset: 2, }); if (User2?.setCompany) { await User2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const User3 = await Users.findOne({ order: [['id', 'ASC']], offset: 3, }); if (User3?.setCompany) { await User3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const User4 = await Users.findOne({ order: [['id', 'ASC']], offset: 4, }); if (User4?.setCompany) { await User4.setCompany(relatedCompany4); } } // Similar logic for "relation_many" async function associateCourseWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Course0 = await Courses.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Course0?.setCompany) { await Course0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Course1 = await Courses.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Course1?.setCompany) { await Course1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Course2 = await Courses.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Course2?.setCompany) { await Course2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Course3 = await Courses.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Course3?.setCompany) { await Course3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Course4 = await Courses.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Course4?.setCompany) { await Course4.setCompany(relatedCompany4); } } async function associateEnrollmentWithEmployee() { const relatedEmployee0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Enrollment0 = await Enrollments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Enrollment0?.setEmployee) { await Enrollment0.setEmployee(relatedEmployee0); } const relatedEmployee1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Enrollment1 = await Enrollments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Enrollment1?.setEmployee) { await Enrollment1.setEmployee(relatedEmployee1); } const relatedEmployee2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Enrollment2 = await Enrollments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Enrollment2?.setEmployee) { await Enrollment2.setEmployee(relatedEmployee2); } const relatedEmployee3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Enrollment3 = await Enrollments.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Enrollment3?.setEmployee) { await Enrollment3.setEmployee(relatedEmployee3); } const relatedEmployee4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Enrollment4 = await Enrollments.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Enrollment4?.setEmployee) { await Enrollment4.setEmployee(relatedEmployee4); } } async function associateEnrollmentWithCourse() { const relatedCourse0 = await Courses.findOne({ offset: Math.floor(Math.random() * (await Courses.count())), }); const Enrollment0 = await Enrollments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Enrollment0?.setCourse) { await Enrollment0.setCourse(relatedCourse0); } const relatedCourse1 = await Courses.findOne({ offset: Math.floor(Math.random() * (await Courses.count())), }); const Enrollment1 = await Enrollments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Enrollment1?.setCourse) { await Enrollment1.setCourse(relatedCourse1); } const relatedCourse2 = await Courses.findOne({ offset: Math.floor(Math.random() * (await Courses.count())), }); const Enrollment2 = await Enrollments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Enrollment2?.setCourse) { await Enrollment2.setCourse(relatedCourse2); } const relatedCourse3 = await Courses.findOne({ offset: Math.floor(Math.random() * (await Courses.count())), }); const Enrollment3 = await Enrollments.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Enrollment3?.setCourse) { await Enrollment3.setCourse(relatedCourse3); } const relatedCourse4 = await Courses.findOne({ offset: Math.floor(Math.random() * (await Courses.count())), }); const Enrollment4 = await Enrollments.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Enrollment4?.setCourse) { await Enrollment4.setCourse(relatedCourse4); } } async function associateEnrollmentWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Enrollment0 = await Enrollments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Enrollment0?.setCompany) { await Enrollment0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Enrollment1 = await Enrollments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Enrollment1?.setCompany) { await Enrollment1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Enrollment2 = await Enrollments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Enrollment2?.setCompany) { await Enrollment2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Enrollment3 = await Enrollments.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Enrollment3?.setCompany) { await Enrollment3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Enrollment4 = await Enrollments.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Enrollment4?.setCompany) { await Enrollment4.setCompany(relatedCompany4); } } module.exports = { up: async (queryInterface, Sequelize) => { await Courses.bulkCreate(CoursesData); await Enrollments.bulkCreate(EnrollmentsData); await Companies.bulkCreate(CompaniesData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithCompany(), // Similar logic for "relation_many" await associateCourseWithCompany(), await associateEnrollmentWithEmployee(), await associateEnrollmentWithCourse(), await associateEnrollmentWithCompany(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('courses', null, {}); await queryInterface.bulkDelete('enrollments', null, {}); await queryInterface.bulkDelete('companies', null, {}); }, };