33531/backend/src/db/seeders/20231127130745-sample-data.js
2025-08-21 11:53:29 +00:00

643 lines
16 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Applications = db.applications;
const InternshipCoordinators = db.internship_coordinators;
const InternshipSupervisors = db.internship_supervisors;
const Internships = db.internships;
const Students = db.students;
const Companies = db.companies;
const ApplicationsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
status: 'applied',
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
status: 'applied',
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
status: 'accepted',
// type code here for "relation_one" field
},
];
const InternshipCoordinatorsData = [
{
first_name: 'Alice',
last_name: 'Williams',
email: 'alice.williams@techcorp.com',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
first_name: 'David',
last_name: 'Miller',
email: 'david.miller@innovatech.com',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
first_name: 'Laura',
last_name: 'Wilson',
email: 'laura.wilson@futureworks.com',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
const InternshipSupervisorsData = [
{
first_name: 'Robert',
last_name: 'Anderson',
email: 'robert.anderson@techcorp.com',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
first_name: 'Patricia',
last_name: 'Thomas',
email: 'patricia.thomas@innovatech.com',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
first_name: 'Charles',
last_name: 'Jackson',
email: 'charles.jackson@futureworks.com',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
const InternshipsData = [
{
title: 'Software Development Intern',
description: 'Work on developing new software solutions.',
start_date: new Date('2024-06-01T09:00:00Z'),
end_date: new Date('2024-08-31T17:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
title: 'Marketing Intern',
description: 'Assist in marketing campaigns and strategies.',
start_date: new Date('2024-06-15T09:00:00Z'),
end_date: new Date('2024-09-15T17:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
title: 'Data Analysis Intern',
description: 'Analyze data trends and provide insights.',
start_date: new Date('2024-07-01T09:00:00Z'),
end_date: new Date('2024-09-30T17:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
const StudentsData = [
{
first_name: 'John',
last_name: 'Doe',
email: 'john.doe@example.com',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
first_name: 'Jane',
last_name: 'Smith',
email: 'jane.smith@example.com',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
first_name: 'Emily',
last_name: 'Johnson',
email: 'emily.johnson@example.com',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const CompaniesData = [
{
name: 'TechCorp',
},
{
name: 'Innovatech',
},
{
name: 'FutureWorks',
},
];
// 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);
}
}
async function associateApplicationWithStudent() {
const relatedStudent0 = await Students.findOne({
offset: Math.floor(Math.random() * (await Students.count())),
});
const Application0 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Application0?.setStudent) {
await Application0.setStudent(relatedStudent0);
}
const relatedStudent1 = await Students.findOne({
offset: Math.floor(Math.random() * (await Students.count())),
});
const Application1 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Application1?.setStudent) {
await Application1.setStudent(relatedStudent1);
}
const relatedStudent2 = await Students.findOne({
offset: Math.floor(Math.random() * (await Students.count())),
});
const Application2 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Application2?.setStudent) {
await Application2.setStudent(relatedStudent2);
}
}
async function associateApplicationWithInternship() {
const relatedInternship0 = await Internships.findOne({
offset: Math.floor(Math.random() * (await Internships.count())),
});
const Application0 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Application0?.setInternship) {
await Application0.setInternship(relatedInternship0);
}
const relatedInternship1 = await Internships.findOne({
offset: Math.floor(Math.random() * (await Internships.count())),
});
const Application1 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Application1?.setInternship) {
await Application1.setInternship(relatedInternship1);
}
const relatedInternship2 = await Internships.findOne({
offset: Math.floor(Math.random() * (await Internships.count())),
});
const Application2 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Application2?.setInternship) {
await Application2.setInternship(relatedInternship2);
}
}
async function associateApplicationWithCompany() {
const relatedCompany0 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Application0 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Application0?.setCompany) {
await Application0.setCompany(relatedCompany0);
}
const relatedCompany1 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Application1 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Application1?.setCompany) {
await Application1.setCompany(relatedCompany1);
}
const relatedCompany2 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Application2 = await Applications.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Application2?.setCompany) {
await Application2.setCompany(relatedCompany2);
}
}
// Similar logic for "relation_many"
async function associateInternshipCoordinatorWithCompany() {
const relatedCompany0 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const InternshipCoordinator0 = await InternshipCoordinators.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (InternshipCoordinator0?.setCompany) {
await InternshipCoordinator0.setCompany(relatedCompany0);
}
const relatedCompany1 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const InternshipCoordinator1 = await InternshipCoordinators.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (InternshipCoordinator1?.setCompany) {
await InternshipCoordinator1.setCompany(relatedCompany1);
}
const relatedCompany2 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const InternshipCoordinator2 = await InternshipCoordinators.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (InternshipCoordinator2?.setCompany) {
await InternshipCoordinator2.setCompany(relatedCompany2);
}
}
// Similar logic for "relation_many"
async function associateInternshipSupervisorWithCompany() {
const relatedCompany0 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const InternshipSupervisor0 = await InternshipSupervisors.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (InternshipSupervisor0?.setCompany) {
await InternshipSupervisor0.setCompany(relatedCompany0);
}
const relatedCompany1 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const InternshipSupervisor1 = await InternshipSupervisors.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (InternshipSupervisor1?.setCompany) {
await InternshipSupervisor1.setCompany(relatedCompany1);
}
const relatedCompany2 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const InternshipSupervisor2 = await InternshipSupervisors.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (InternshipSupervisor2?.setCompany) {
await InternshipSupervisor2.setCompany(relatedCompany2);
}
}
async function associateInternshipWithCompany() {
const relatedCompany0 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Internship0 = await Internships.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Internship0?.setCompany) {
await Internship0.setCompany(relatedCompany0);
}
const relatedCompany1 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Internship1 = await Internships.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Internship1?.setCompany) {
await Internship1.setCompany(relatedCompany1);
}
const relatedCompany2 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Internship2 = await Internships.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Internship2?.setCompany) {
await Internship2.setCompany(relatedCompany2);
}
}
// Similar logic for "relation_many"
async function associateInternshipWithCompany() {
const relatedCompany0 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Internship0 = await Internships.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Internship0?.setCompany) {
await Internship0.setCompany(relatedCompany0);
}
const relatedCompany1 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Internship1 = await Internships.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Internship1?.setCompany) {
await Internship1.setCompany(relatedCompany1);
}
const relatedCompany2 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Internship2 = await Internships.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Internship2?.setCompany) {
await Internship2.setCompany(relatedCompany2);
}
}
async function associateStudentWithCompany() {
const relatedCompany0 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Student0 = await Students.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Student0?.setCompany) {
await Student0.setCompany(relatedCompany0);
}
const relatedCompany1 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Student1 = await Students.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Student1?.setCompany) {
await Student1.setCompany(relatedCompany1);
}
const relatedCompany2 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Student2 = await Students.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Student2?.setCompany) {
await Student2.setCompany(relatedCompany2);
}
}
async function associateStudentWithCompany() {
const relatedCompany0 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Student0 = await Students.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Student0?.setCompany) {
await Student0.setCompany(relatedCompany0);
}
const relatedCompany1 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Student1 = await Students.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Student1?.setCompany) {
await Student1.setCompany(relatedCompany1);
}
const relatedCompany2 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Student2 = await Students.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Student2?.setCompany) {
await Student2.setCompany(relatedCompany2);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Applications.bulkCreate(ApplicationsData);
await InternshipCoordinators.bulkCreate(InternshipCoordinatorsData);
await InternshipSupervisors.bulkCreate(InternshipSupervisorsData);
await Internships.bulkCreate(InternshipsData);
await Students.bulkCreate(StudentsData);
await Companies.bulkCreate(CompaniesData);
await Promise.all([
// Similar logic for "relation_many"
await associateUserWithCompany(),
await associateApplicationWithStudent(),
await associateApplicationWithInternship(),
await associateApplicationWithCompany(),
// Similar logic for "relation_many"
await associateInternshipCoordinatorWithCompany(),
// Similar logic for "relation_many"
await associateInternshipSupervisorWithCompany(),
await associateInternshipWithCompany(),
// Similar logic for "relation_many"
await associateInternshipWithCompany(),
await associateStudentWithCompany(),
await associateStudentWithCompany(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('applications', null, {});
await queryInterface.bulkDelete('internship_coordinators', null, {});
await queryInterface.bulkDelete('internship_supervisors', null, {});
await queryInterface.bulkDelete('internships', null, {});
await queryInterface.bulkDelete('students', null, {});
await queryInterface.bulkDelete('companies', null, {});
},
};