const db = require('../models'); const Users = db.users; const Attendances = db.attendances; const Courses = db.courses; const Faculties = db.faculties; const Fees = db.fees; const Marks = db.marks; const Students = db.students; const AttendancesData = [ { // type code here for "relation_one" field // type code here for "relation_one" field date: new Date('2023-10-01T08:00:00Z'), present: true, }, { // type code here for "relation_one" field // type code here for "relation_one" field date: new Date('2023-10-01T08:00:00Z'), present: true, }, { // type code here for "relation_one" field // type code here for "relation_one" field date: new Date('2023-10-01T08:00:00Z'), present: true, }, ]; const CoursesData = [ { course_name: 'Mathematics', // type code here for "relation_many" field // type code here for "relation_many" field }, { course_name: 'Physics', // type code here for "relation_many" field // type code here for "relation_many" field }, { course_name: 'Chemistry', // type code here for "relation_many" field // type code here for "relation_many" field }, ]; const FacultiesData = [ { first_name: 'Madhunisha', last_name: 'R', contact_number: '9876543215', // type code here for "relation_one" field }, { first_name: 'Rajeshkannan', last_name: 'N', contact_number: '9876543216', // type code here for "relation_one" field }, { first_name: 'Nandhini', last_name: 'S', contact_number: '9876543217', // type code here for "relation_one" field }, ]; const FeesData = [ { // type code here for "relation_one" field amount: 5000, paid: true, }, { // type code here for "relation_one" field amount: 5000, paid: true, }, { // type code here for "relation_one" field amount: 5000, paid: true, }, ]; const MarksData = [ { // type code here for "relation_one" field // type code here for "relation_one" field internal_1: 85, internal_2: 90, }, { // type code here for "relation_one" field // type code here for "relation_one" field internal_1: 75, internal_2: 80, }, { // type code here for "relation_one" field // type code here for "relation_one" field internal_1: 88, internal_2: 92, }, ]; const StudentsData = [ { first_name: 'Aadithya', last_name: 'V', contact_number: '9876543210', // type code here for "relation_one" field // type code here for "relation_many" field }, { first_name: 'Adhithyan', last_name: 'M S', contact_number: '9876543211', // type code here for "relation_one" field // type code here for "relation_many" field }, { first_name: 'Afreen', last_name: 'A', contact_number: '9876543212', // type code here for "relation_one" field // type code here for "relation_many" field }, ]; // Similar logic for "relation_many" async function associateAttendanceWithStudent() { const relatedStudent0 = await Students.findOne({ offset: Math.floor(Math.random() * (await Students.count())), }); const Attendance0 = await Attendances.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Attendance0?.setStudent) { await Attendance0.setStudent(relatedStudent0); } const relatedStudent1 = await Students.findOne({ offset: Math.floor(Math.random() * (await Students.count())), }); const Attendance1 = await Attendances.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Attendance1?.setStudent) { await Attendance1.setStudent(relatedStudent1); } const relatedStudent2 = await Students.findOne({ offset: Math.floor(Math.random() * (await Students.count())), }); const Attendance2 = await Attendances.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Attendance2?.setStudent) { await Attendance2.setStudent(relatedStudent2); } } async function associateAttendanceWithCourse() { const relatedCourse0 = await Courses.findOne({ offset: Math.floor(Math.random() * (await Courses.count())), }); const Attendance0 = await Attendances.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Attendance0?.setCourse) { await Attendance0.setCourse(relatedCourse0); } const relatedCourse1 = await Courses.findOne({ offset: Math.floor(Math.random() * (await Courses.count())), }); const Attendance1 = await Attendances.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Attendance1?.setCourse) { await Attendance1.setCourse(relatedCourse1); } const relatedCourse2 = await Courses.findOne({ offset: Math.floor(Math.random() * (await Courses.count())), }); const Attendance2 = await Attendances.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Attendance2?.setCourse) { await Attendance2.setCourse(relatedCourse2); } } // Similar logic for "relation_many" // Similar logic for "relation_many" async function associateFacultyWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Faculty0 = await Faculties.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Faculty0?.setUser) { await Faculty0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Faculty1 = await Faculties.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Faculty1?.setUser) { await Faculty1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Faculty2 = await Faculties.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Faculty2?.setUser) { await Faculty2.setUser(relatedUser2); } } async function associateFeeWithStudent() { const relatedStudent0 = await Students.findOne({ offset: Math.floor(Math.random() * (await Students.count())), }); const Fee0 = await Fees.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Fee0?.setStudent) { await Fee0.setStudent(relatedStudent0); } const relatedStudent1 = await Students.findOne({ offset: Math.floor(Math.random() * (await Students.count())), }); const Fee1 = await Fees.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Fee1?.setStudent) { await Fee1.setStudent(relatedStudent1); } const relatedStudent2 = await Students.findOne({ offset: Math.floor(Math.random() * (await Students.count())), }); const Fee2 = await Fees.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Fee2?.setStudent) { await Fee2.setStudent(relatedStudent2); } } async function associateMarkWithStudent() { const relatedStudent0 = await Students.findOne({ offset: Math.floor(Math.random() * (await Students.count())), }); const Mark0 = await Marks.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Mark0?.setStudent) { await Mark0.setStudent(relatedStudent0); } const relatedStudent1 = await Students.findOne({ offset: Math.floor(Math.random() * (await Students.count())), }); const Mark1 = await Marks.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Mark1?.setStudent) { await Mark1.setStudent(relatedStudent1); } const relatedStudent2 = await Students.findOne({ offset: Math.floor(Math.random() * (await Students.count())), }); const Mark2 = await Marks.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Mark2?.setStudent) { await Mark2.setStudent(relatedStudent2); } } async function associateMarkWithCourse() { const relatedCourse0 = await Courses.findOne({ offset: Math.floor(Math.random() * (await Courses.count())), }); const Mark0 = await Marks.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Mark0?.setCourse) { await Mark0.setCourse(relatedCourse0); } const relatedCourse1 = await Courses.findOne({ offset: Math.floor(Math.random() * (await Courses.count())), }); const Mark1 = await Marks.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Mark1?.setCourse) { await Mark1.setCourse(relatedCourse1); } const relatedCourse2 = await Courses.findOne({ offset: Math.floor(Math.random() * (await Courses.count())), }); const Mark2 = await Marks.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Mark2?.setCourse) { await Mark2.setCourse(relatedCourse2); } } async function associateStudentWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Student0 = await Students.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Student0?.setUser) { await Student0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Student1 = await Students.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Student1?.setUser) { await Student1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Student2 = await Students.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Student2?.setUser) { await Student2.setUser(relatedUser2); } } // Similar logic for "relation_many" module.exports = { up: async (queryInterface, Sequelize) => { await Attendances.bulkCreate(AttendancesData); await Courses.bulkCreate(CoursesData); await Faculties.bulkCreate(FacultiesData); await Fees.bulkCreate(FeesData); await Marks.bulkCreate(MarksData); await Students.bulkCreate(StudentsData); await Promise.all([ // Similar logic for "relation_many" await associateAttendanceWithStudent(), await associateAttendanceWithCourse(), // Similar logic for "relation_many" // Similar logic for "relation_many" await associateFacultyWithUser(), await associateFeeWithStudent(), await associateMarkWithStudent(), await associateMarkWithCourse(), await associateStudentWithUser(), // Similar logic for "relation_many" ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('attendances', null, {}); await queryInterface.bulkDelete('courses', null, {}); await queryInterface.bulkDelete('faculties', null, {}); await queryInterface.bulkDelete('fees', null, {}); await queryInterface.bulkDelete('marks', null, {}); await queryInterface.bulkDelete('students', null, {}); }, };