const db = require('../models'); const Users = db.users; const Applications = db.applications; const Appointments = db.appointments; const Blogs = db.blogs; const Programs = db.programs; const Organizations = db.organizations; const ApplicationsData = [ { // type code here for "relation_one" field // type code here for "relation_one" field submission_date: new Date('2023-10-01T10:00:00Z'), status: 'Rejected', // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field submission_date: new Date('2023-09-15T14:30:00Z'), status: 'Pending', // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field submission_date: new Date('2023-08-20T09:00:00Z'), status: 'Pending', // type code here for "relation_one" field }, ]; const AppointmentsData = [ { // type code here for "relation_one" field // type code here for "relation_one" field start_time: new Date('2023-10-05T09:00:00Z'), end_time: new Date('2023-10-05T10:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field start_time: new Date('2023-10-06T11:00:00Z'), end_time: new Date('2023-10-06T12:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field start_time: new Date('2023-10-07T14:00:00Z'), end_time: new Date('2023-10-07T15:00:00Z'), // type code here for "relation_one" field }, ]; const BlogsData = [ { title: 'Top 5 Tips for Studying Abroad', content: 'Studying abroad can be a life-changing experience. Here are five tips to make the most of it.', // type code here for "relation_one" field published_date: new Date('2023-09-01T08:00:00Z'), // type code here for "relation_one" field }, { title: 'Understanding the Visa Process', content: 'Navigating the visa process can be challenging. This guide will help you understand the steps involved.', // type code here for "relation_one" field published_date: new Date('2023-08-15T09:30:00Z'), // type code here for "relation_one" field }, { title: 'Choosing the Right University', content: 'Selecting the right university is crucial for your academic success. Here are some factors to consider.', // type code here for "relation_one" field published_date: new Date('2023-07-20T10:00:00Z'), // type code here for "relation_one" field }, ]; const ProgramsData = [ { name: 'Bachelor of Science in Computer Science', description: 'A comprehensive program covering algorithms, data structures, and software engineering.', // type code here for "relation_one" field country: 'Canada', // type code here for "relation_one" field }, { name: 'Master of Business Administration', description: 'An advanced program focusing on leadership, strategy, and management.', // type code here for "relation_one" field country: 'UK', // type code here for "relation_one" field }, { name: 'Bachelor of Arts in Psychology', description: 'An in-depth study of human behavior and mental processes.', // type code here for "relation_one" field country: 'USA', // type code here for "relation_one" field }, ]; const OrganizationsData = [ { name: 'Global Education Services', }, { name: 'Study Abroad Experts', }, { name: 'International Student Advisors', }, ]; // 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); } } async function associateApplicationWithStudent() { const relatedStudent0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Application0 = await Applications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Application0?.setStudent) { await Application0.setStudent(relatedStudent0); } const relatedStudent1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Application1 = await Applications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Application1?.setStudent) { await Application1.setStudent(relatedStudent1); } const relatedStudent2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Application2 = await Applications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Application2?.setStudent) { await Application2.setStudent(relatedStudent2); } } async function associateApplicationWithProgram() { const relatedProgram0 = await Programs.findOne({ offset: Math.floor(Math.random() * (await Programs.count())), }); const Application0 = await Applications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Application0?.setProgram) { await Application0.setProgram(relatedProgram0); } const relatedProgram1 = await Programs.findOne({ offset: Math.floor(Math.random() * (await Programs.count())), }); const Application1 = await Applications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Application1?.setProgram) { await Application1.setProgram(relatedProgram1); } const relatedProgram2 = await Programs.findOne({ offset: Math.floor(Math.random() * (await Programs.count())), }); const Application2 = await Applications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Application2?.setProgram) { await Application2.setProgram(relatedProgram2); } } 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); } } async function associateAppointmentWithStudent() { const relatedStudent0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Appointment0 = await Appointments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Appointment0?.setStudent) { await Appointment0.setStudent(relatedStudent0); } const relatedStudent1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Appointment1 = await Appointments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Appointment1?.setStudent) { await Appointment1.setStudent(relatedStudent1); } const relatedStudent2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Appointment2 = await Appointments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Appointment2?.setStudent) { await Appointment2.setStudent(relatedStudent2); } } async function associateAppointmentWithCounselor() { const relatedCounselor0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Appointment0 = await Appointments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Appointment0?.setCounselor) { await Appointment0.setCounselor(relatedCounselor0); } const relatedCounselor1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Appointment1 = await Appointments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Appointment1?.setCounselor) { await Appointment1.setCounselor(relatedCounselor1); } const relatedCounselor2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Appointment2 = await Appointments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Appointment2?.setCounselor) { await Appointment2.setCounselor(relatedCounselor2); } } async function associateAppointmentWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Appointment0 = await Appointments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Appointment0?.setOrganization) { await Appointment0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Appointment1 = await Appointments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Appointment1?.setOrganization) { await Appointment1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Appointment2 = await Appointments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Appointment2?.setOrganization) { await Appointment2.setOrganization(relatedOrganization2); } } async function associateBlogWithAuthor() { const relatedAuthor0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Blog0 = await Blogs.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Blog0?.setAuthor) { await Blog0.setAuthor(relatedAuthor0); } const relatedAuthor1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Blog1 = await Blogs.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Blog1?.setAuthor) { await Blog1.setAuthor(relatedAuthor1); } const relatedAuthor2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Blog2 = await Blogs.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Blog2?.setAuthor) { await Blog2.setAuthor(relatedAuthor2); } } async function associateBlogWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Blog0 = await Blogs.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Blog0?.setOrganization) { await Blog0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Blog1 = await Blogs.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Blog1?.setOrganization) { await Blog1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Blog2 = await Blogs.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Blog2?.setOrganization) { await Blog2.setOrganization(relatedOrganization2); } } async function associateProgramWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Program0 = await Programs.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Program0?.setOrganization) { await Program0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Program1 = await Programs.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Program1?.setOrganization) { await Program1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Program2 = await Programs.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Program2?.setOrganization) { await Program2.setOrganization(relatedOrganization2); } } async function associateProgramWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Program0 = await Programs.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Program0?.setOrganization) { await Program0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Program1 = await Programs.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Program1?.setOrganization) { await Program1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Program2 = await Programs.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Program2?.setOrganization) { await Program2.setOrganization(relatedOrganization2); } } module.exports = { up: async (queryInterface, Sequelize) => { await Applications.bulkCreate(ApplicationsData); await Appointments.bulkCreate(AppointmentsData); await Blogs.bulkCreate(BlogsData); await Programs.bulkCreate(ProgramsData); await Organizations.bulkCreate(OrganizationsData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithOrganization(), await associateApplicationWithStudent(), await associateApplicationWithProgram(), await associateApplicationWithOrganization(), await associateAppointmentWithStudent(), await associateAppointmentWithCounselor(), await associateAppointmentWithOrganization(), await associateBlogWithAuthor(), await associateBlogWithOrganization(), await associateProgramWithOrganization(), await associateProgramWithOrganization(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('applications', null, {}); await queryInterface.bulkDelete('appointments', null, {}); await queryInterface.bulkDelete('blogs', null, {}); await queryInterface.bulkDelete('programs', null, {}); await queryInterface.bulkDelete('organizations', null, {}); }, };