const db = require('../models'); const Users = db.users; const Applicants = db.applicants; const Applications = db.applications; const Institutions = db.institutions; const Payments = db.payments; const Reviews = db.reviews; const ApplicantsData = [ { // type code here for "relation_one" field first_name: 'John', last_name: 'Doe', personal_information: 'Student at Ndhiwa High School', academic_information: 'Grade A in KCSE', family_information: 'Single parent household', // type code here for "files" field application_status: 'Submitted', }, { // type code here for "relation_one" field first_name: 'Jane', last_name: 'Smith', personal_information: 'Student at Ndhiwa College', academic_information: 'Diploma in IT', family_information: 'Orphan', // type code here for "files" field application_status: 'UnderReview', }, { // type code here for "relation_one" field first_name: 'Alice', last_name: 'Johnson', personal_information: 'Student at Ndhiwa University', academic_information: "Bachelor's in Business", family_information: 'Low income family', // type code here for "files" field application_status: 'Rejected', }, { // type code here for "relation_one" field first_name: 'Bob', last_name: 'Brown', personal_information: 'Student at Ndhiwa Technical Institute', academic_information: 'Certificate in Engineering', family_information: 'Lives with grandparents', // type code here for "files" field application_status: 'Submitted', }, { // type code here for "relation_one" field first_name: 'Emily', last_name: 'Davis', personal_information: 'Student at Ndhiwa Secondary School', academic_information: 'Grade B in KCSE', family_information: 'Both parents unemployed', // type code here for "files" field application_status: 'Rejected', }, ]; const ApplicationsData = [ { // type code here for "relation_one" field submission_date: new Date('2023-10-01T10:00:00Z'), status: 'Approved', // type code here for "relation_many" field // type code here for "relation_one" field }, { // type code here for "relation_one" field submission_date: new Date('2023-10-02T11:00:00Z'), status: 'Approved', // type code here for "relation_many" field // type code here for "relation_one" field }, { // type code here for "relation_one" field submission_date: new Date('2023-10-03T12:00:00Z'), status: 'Rejected', // type code here for "relation_many" field // type code here for "relation_one" field }, { // type code here for "relation_one" field submission_date: new Date('2023-10-04T13:00:00Z'), status: 'Submitted', // type code here for "relation_many" field // type code here for "relation_one" field }, { // type code here for "relation_one" field submission_date: new Date('2023-10-05T14:00:00Z'), status: 'Approved', // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const InstitutionsData = [ { name: 'Ndhiwa High School', address: '123 Main St, Ndhiwa', // type code here for "relation_many" field }, { name: 'Ndhiwa College', address: '456 College Ave, Ndhiwa', // type code here for "relation_many" field }, { name: 'Ndhiwa University', address: '789 University Blvd, Ndhiwa', // type code here for "relation_many" field }, { name: 'Ndhiwa Technical Institute', address: '101 Tech Rd, Ndhiwa', // type code here for "relation_many" field }, { name: 'Ndhiwa Secondary School', address: '202 School Ln, Ndhiwa', // type code here for "relation_many" field }, ]; const PaymentsData = [ { // type code here for "relation_one" field amount: 5000, payment_date: new Date('2023-10-10T15:00:00Z'), payment_status: 'Completed', }, { // type code here for "relation_one" field amount: 3000, payment_date: new Date('2023-10-11T16:00:00Z'), payment_status: 'Completed', }, { // type code here for "relation_one" field amount: 4500, payment_date: new Date('2023-10-12T17:00:00Z'), payment_status: 'Completed', }, { // type code here for "relation_one" field amount: 2500, payment_date: new Date('2023-10-13T18:00:00Z'), payment_status: 'Completed', }, { // type code here for "relation_one" field amount: 6000, payment_date: new Date('2023-10-14T19:00:00Z'), payment_status: 'Pending', }, ]; const ReviewsData = [ { // type code here for "relation_one" field // type code here for "relation_one" field score: 85.5, comments: 'Excellent application, meets all criteria.', }, { // type code here for "relation_one" field // type code here for "relation_one" field score: 78, comments: 'Good application, minor issues noted.', }, { // type code here for "relation_one" field // type code here for "relation_one" field score: 92, comments: 'Outstanding application, highly recommended.', }, { // type code here for "relation_one" field // type code here for "relation_one" field score: 60, comments: 'Application lacks sufficient documentation.', }, { // type code here for "relation_one" field // type code here for "relation_one" field score: 88, comments: 'Strong application, well-documented.', }, ]; // Similar logic for "relation_many" async function associateApplicantWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Applicant0 = await Applicants.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Applicant0?.setUser) { await Applicant0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Applicant1 = await Applicants.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Applicant1?.setUser) { await Applicant1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Applicant2 = await Applicants.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Applicant2?.setUser) { await Applicant2.setUser(relatedUser2); } const relatedUser3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Applicant3 = await Applicants.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Applicant3?.setUser) { await Applicant3.setUser(relatedUser3); } const relatedUser4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Applicant4 = await Applicants.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Applicant4?.setUser) { await Applicant4.setUser(relatedUser4); } } async function associateApplicationWithApplicant() { const relatedApplicant0 = await Applicants.findOne({ offset: Math.floor(Math.random() * (await Applicants.count())), }); const Application0 = await Applications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Application0?.setApplicant) { await Application0.setApplicant(relatedApplicant0); } const relatedApplicant1 = await Applicants.findOne({ offset: Math.floor(Math.random() * (await Applicants.count())), }); const Application1 = await Applications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Application1?.setApplicant) { await Application1.setApplicant(relatedApplicant1); } const relatedApplicant2 = await Applicants.findOne({ offset: Math.floor(Math.random() * (await Applicants.count())), }); const Application2 = await Applications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Application2?.setApplicant) { await Application2.setApplicant(relatedApplicant2); } const relatedApplicant3 = await Applicants.findOne({ offset: Math.floor(Math.random() * (await Applicants.count())), }); const Application3 = await Applications.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Application3?.setApplicant) { await Application3.setApplicant(relatedApplicant3); } const relatedApplicant4 = await Applicants.findOne({ offset: Math.floor(Math.random() * (await Applicants.count())), }); const Application4 = await Applications.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Application4?.setApplicant) { await Application4.setApplicant(relatedApplicant4); } } // Similar logic for "relation_many" async function associateApplicationWithInstitution() { const relatedInstitution0 = await Institutions.findOne({ offset: Math.floor(Math.random() * (await Institutions.count())), }); const Application0 = await Applications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Application0?.setInstitution) { await Application0.setInstitution(relatedInstitution0); } const relatedInstitution1 = await Institutions.findOne({ offset: Math.floor(Math.random() * (await Institutions.count())), }); const Application1 = await Applications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Application1?.setInstitution) { await Application1.setInstitution(relatedInstitution1); } const relatedInstitution2 = await Institutions.findOne({ offset: Math.floor(Math.random() * (await Institutions.count())), }); const Application2 = await Applications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Application2?.setInstitution) { await Application2.setInstitution(relatedInstitution2); } const relatedInstitution3 = await Institutions.findOne({ offset: Math.floor(Math.random() * (await Institutions.count())), }); const Application3 = await Applications.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Application3?.setInstitution) { await Application3.setInstitution(relatedInstitution3); } const relatedInstitution4 = await Institutions.findOne({ offset: Math.floor(Math.random() * (await Institutions.count())), }); const Application4 = await Applications.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Application4?.setInstitution) { await Application4.setInstitution(relatedInstitution4); } } // Similar logic for "relation_many" async function associatePaymentWithApplication() { const relatedApplication0 = await Applications.findOne({ offset: Math.floor(Math.random() * (await Applications.count())), }); const Payment0 = await Payments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Payment0?.setApplication) { await Payment0.setApplication(relatedApplication0); } const relatedApplication1 = await Applications.findOne({ offset: Math.floor(Math.random() * (await Applications.count())), }); const Payment1 = await Payments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Payment1?.setApplication) { await Payment1.setApplication(relatedApplication1); } const relatedApplication2 = await Applications.findOne({ offset: Math.floor(Math.random() * (await Applications.count())), }); const Payment2 = await Payments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Payment2?.setApplication) { await Payment2.setApplication(relatedApplication2); } const relatedApplication3 = await Applications.findOne({ offset: Math.floor(Math.random() * (await Applications.count())), }); const Payment3 = await Payments.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Payment3?.setApplication) { await Payment3.setApplication(relatedApplication3); } const relatedApplication4 = await Applications.findOne({ offset: Math.floor(Math.random() * (await Applications.count())), }); const Payment4 = await Payments.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Payment4?.setApplication) { await Payment4.setApplication(relatedApplication4); } } async function associateReviewWithApplication() { const relatedApplication0 = await Applications.findOne({ offset: Math.floor(Math.random() * (await Applications.count())), }); const Review0 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Review0?.setApplication) { await Review0.setApplication(relatedApplication0); } const relatedApplication1 = await Applications.findOne({ offset: Math.floor(Math.random() * (await Applications.count())), }); const Review1 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Review1?.setApplication) { await Review1.setApplication(relatedApplication1); } const relatedApplication2 = await Applications.findOne({ offset: Math.floor(Math.random() * (await Applications.count())), }); const Review2 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Review2?.setApplication) { await Review2.setApplication(relatedApplication2); } const relatedApplication3 = await Applications.findOne({ offset: Math.floor(Math.random() * (await Applications.count())), }); const Review3 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Review3?.setApplication) { await Review3.setApplication(relatedApplication3); } const relatedApplication4 = await Applications.findOne({ offset: Math.floor(Math.random() * (await Applications.count())), }); const Review4 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Review4?.setApplication) { await Review4.setApplication(relatedApplication4); } } async function associateReviewWithReviewer() { const relatedReviewer0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Review0 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Review0?.setReviewer) { await Review0.setReviewer(relatedReviewer0); } const relatedReviewer1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Review1 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Review1?.setReviewer) { await Review1.setReviewer(relatedReviewer1); } const relatedReviewer2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Review2 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Review2?.setReviewer) { await Review2.setReviewer(relatedReviewer2); } const relatedReviewer3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Review3 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Review3?.setReviewer) { await Review3.setReviewer(relatedReviewer3); } const relatedReviewer4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Review4 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Review4?.setReviewer) { await Review4.setReviewer(relatedReviewer4); } } module.exports = { up: async (queryInterface, Sequelize) => { await Applicants.bulkCreate(ApplicantsData); await Applications.bulkCreate(ApplicationsData); await Institutions.bulkCreate(InstitutionsData); await Payments.bulkCreate(PaymentsData); await Reviews.bulkCreate(ReviewsData); await Promise.all([ // Similar logic for "relation_many" await associateApplicantWithUser(), await associateApplicationWithApplicant(), // Similar logic for "relation_many" await associateApplicationWithInstitution(), // Similar logic for "relation_many" await associatePaymentWithApplication(), await associateReviewWithApplication(), await associateReviewWithReviewer(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('applicants', null, {}); await queryInterface.bulkDelete('applications', null, {}); await queryInterface.bulkDelete('institutions', null, {}); await queryInterface.bulkDelete('payments', null, {}); await queryInterface.bulkDelete('reviews', null, {}); }, };