const db = require('../models'); const Users = db.users; const Absences = db.absences; const EmployeeStatus = db.employee_status; const Employees = db.employees; const Machines = db.machines; const PerformanceCategories = db.performance_categories; const Projects = db.projects; const Sectors = db.sectors; const Shifts = db.shifts; const Vacations = db.vacations; const Organizations = db.organizations; const AbsencesData = [ { // type code here for "relation_one" field absence_type: 'Custom1', start_date: new Date('2023-07-01T08:00:00Z'), end_date: new Date('2023-07-03T08:00:00Z'), notes: 'Flu symptoms', // type code here for "relation_one" field }, { // type code here for "relation_one" field absence_type: 'Custom1', start_date: new Date('2023-06-01T08:00:00Z'), end_date: new Date('2023-06-02T08:00:00Z'), notes: 'Family emergency', // type code here for "relation_one" field }, { // type code here for "relation_one" field absence_type: 'Vacation', start_date: new Date('2023-05-01T08:00:00Z'), end_date: new Date('2023-05-05T08:00:00Z'), notes: 'Personal leave', // type code here for "relation_one" field }, ]; const EmployeeStatusData = [ { // type code here for "relation_one" field vacation_status: 'OnVacation', performance_rating: 5, absences_count: 2, warnings_count: 0, // type code here for "relation_one" field }, { // type code here for "relation_one" field vacation_status: 'Available', performance_rating: 7, absences_count: 1, warnings_count: 1, // type code here for "relation_one" field }, { // type code here for "relation_one" field vacation_status: 'Available', performance_rating: 6, absences_count: 0, warnings_count: 0, // type code here for "relation_one" field }, ]; const EmployeesData = [ { full_name: 'John Doe', role: 'Operator', registration_number: 'EMP001', cost_center: 'CC1001', hire_date: new Date('2022-01-15T08:00:00Z'), phone: '555-0101', address: '123 Main St, Springfield', // type code here for "images" field // type code here for "relation_one" field // type code here for "relation_one" field }, { full_name: 'Jane Smith', role: 'Supervisor', registration_number: 'EMP002', cost_center: 'CC1002', hire_date: new Date('2021-06-20T08:00:00Z'), phone: '555-0102', address: '456 Elm St, Springfield', // type code here for "images" field // type code here for "relation_one" field // type code here for "relation_one" field }, { full_name: 'Alice Johnson', role: 'Technician', registration_number: 'EMP003', cost_center: 'CC1003', hire_date: new Date('2020-11-05T08:00:00Z'), phone: '555-0103', address: '789 Oak St, Springfield', // type code here for "images" field // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const MachinesData = [ { machine_name: 'CNC Machine 1', // type code here for "relation_one" field // type code here for "relation_one" field }, { machine_name: '3D Printer', // type code here for "relation_one" field // type code here for "relation_one" field }, { machine_name: 'Inspection Station', // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const PerformanceCategoriesData = [ { stars: 1, category_name: 'Beginner', description: 'New to the role, requires supervision.', // type code here for "relation_one" field }, { stars: 2, category_name: 'Beginner Apprentice', description: 'Gaining experience, still learning.', // type code here for "relation_one" field }, { stars: 3, category_name: 'Average Apprentice', description: 'Moderate experience, performs tasks with some guidance.', // type code here for "relation_one" field }, ]; const ProjectsData = [ { project_name: 'Project Alpha', description: 'Initial phase of the new product line.', // type code here for "relation_one" field }, { project_name: 'Project Beta', description: 'Expansion of the existing product line.', // type code here for "relation_one" field }, { project_name: 'Project Gamma', description: 'Research and development for new technologies.', // type code here for "relation_one" field }, ]; const SectorsData = [ { sector_name: 'Manufacturing', // type code here for "relation_one" field // type code here for "relation_one" field }, { sector_name: 'Research', // type code here for "relation_one" field // type code here for "relation_one" field }, { sector_name: 'Quality Control', // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const ShiftsData = [ { shift_name: 'Morning Shift', shift_type: '95B', // type code here for "relation_one" field // type code here for "relation_one" field }, { shift_name: 'Afternoon Shift', shift_type: '49A', // type code here for "relation_one" field // type code here for "relation_one" field }, { shift_name: 'Night Shift', shift_type: '49A', // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const VacationsData = [ { // type code here for "relation_one" field start_date: new Date('2023-12-01T08:00:00Z'), end_date: new Date('2023-12-15T08:00:00Z'), thirteenth_advance: true, // type code here for "relation_one" field // type code here for "relation_one" field }, { // type code here for "relation_one" field start_date: new Date('2023-11-01T08:00:00Z'), end_date: new Date('2023-11-10T08:00:00Z'), thirteenth_advance: false, // type code here for "relation_one" field // type code here for "relation_one" field }, { // type code here for "relation_one" field start_date: new Date('2023-10-01T08:00:00Z'), end_date: new Date('2023-10-14T08:00:00Z'), thirteenth_advance: true, // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const OrganizationsData = [ { name: 'J. Robert Oppenheimer', }, { name: 'William Harvey', }, { name: 'Max Born', }, ]; // 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 associateAbsenceWithEmployee() { const relatedEmployee0 = await Employees.findOne({ offset: Math.floor(Math.random() * (await Employees.count())), }); const Absence0 = await Absences.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Absence0?.setEmployee) { await Absence0.setEmployee(relatedEmployee0); } const relatedEmployee1 = await Employees.findOne({ offset: Math.floor(Math.random() * (await Employees.count())), }); const Absence1 = await Absences.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Absence1?.setEmployee) { await Absence1.setEmployee(relatedEmployee1); } const relatedEmployee2 = await Employees.findOne({ offset: Math.floor(Math.random() * (await Employees.count())), }); const Absence2 = await Absences.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Absence2?.setEmployee) { await Absence2.setEmployee(relatedEmployee2); } } async function associateAbsenceWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Absence0 = await Absences.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Absence0?.setOrganization) { await Absence0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Absence1 = await Absences.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Absence1?.setOrganization) { await Absence1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Absence2 = await Absences.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Absence2?.setOrganization) { await Absence2.setOrganization(relatedOrganization2); } } async function associateEmployeeStatusWithEmployee() { const relatedEmployee0 = await Employees.findOne({ offset: Math.floor(Math.random() * (await Employees.count())), }); const EmployeeStatus0 = await EmployeeStatus.findOne({ order: [['id', 'ASC']], offset: 0, }); if (EmployeeStatus0?.setEmployee) { await EmployeeStatus0.setEmployee(relatedEmployee0); } const relatedEmployee1 = await Employees.findOne({ offset: Math.floor(Math.random() * (await Employees.count())), }); const EmployeeStatus1 = await EmployeeStatus.findOne({ order: [['id', 'ASC']], offset: 1, }); if (EmployeeStatus1?.setEmployee) { await EmployeeStatus1.setEmployee(relatedEmployee1); } const relatedEmployee2 = await Employees.findOne({ offset: Math.floor(Math.random() * (await Employees.count())), }); const EmployeeStatus2 = await EmployeeStatus.findOne({ order: [['id', 'ASC']], offset: 2, }); if (EmployeeStatus2?.setEmployee) { await EmployeeStatus2.setEmployee(relatedEmployee2); } } async function associateEmployeeStatusWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const EmployeeStatus0 = await EmployeeStatus.findOne({ order: [['id', 'ASC']], offset: 0, }); if (EmployeeStatus0?.setOrganization) { await EmployeeStatus0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const EmployeeStatus1 = await EmployeeStatus.findOne({ order: [['id', 'ASC']], offset: 1, }); if (EmployeeStatus1?.setOrganization) { await EmployeeStatus1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const EmployeeStatus2 = await EmployeeStatus.findOne({ order: [['id', 'ASC']], offset: 2, }); if (EmployeeStatus2?.setOrganization) { await EmployeeStatus2.setOrganization(relatedOrganization2); } } async function associateEmployeeWithShift() { const relatedShift0 = await Shifts.findOne({ offset: Math.floor(Math.random() * (await Shifts.count())), }); const Employee0 = await Employees.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Employee0?.setShift) { await Employee0.setShift(relatedShift0); } const relatedShift1 = await Shifts.findOne({ offset: Math.floor(Math.random() * (await Shifts.count())), }); const Employee1 = await Employees.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Employee1?.setShift) { await Employee1.setShift(relatedShift1); } const relatedShift2 = await Shifts.findOne({ offset: Math.floor(Math.random() * (await Shifts.count())), }); const Employee2 = await Employees.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Employee2?.setShift) { await Employee2.setShift(relatedShift2); } } async function associateEmployeeWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Employee0 = await Employees.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Employee0?.setOrganization) { await Employee0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Employee1 = await Employees.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Employee1?.setOrganization) { await Employee1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Employee2 = await Employees.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Employee2?.setOrganization) { await Employee2.setOrganization(relatedOrganization2); } } async function associateMachineWithSector() { const relatedSector0 = await Sectors.findOne({ offset: Math.floor(Math.random() * (await Sectors.count())), }); const Machine0 = await Machines.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Machine0?.setSector) { await Machine0.setSector(relatedSector0); } const relatedSector1 = await Sectors.findOne({ offset: Math.floor(Math.random() * (await Sectors.count())), }); const Machine1 = await Machines.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Machine1?.setSector) { await Machine1.setSector(relatedSector1); } const relatedSector2 = await Sectors.findOne({ offset: Math.floor(Math.random() * (await Sectors.count())), }); const Machine2 = await Machines.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Machine2?.setSector) { await Machine2.setSector(relatedSector2); } } async function associateMachineWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Machine0 = await Machines.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Machine0?.setOrganization) { await Machine0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Machine1 = await Machines.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Machine1?.setOrganization) { await Machine1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Machine2 = await Machines.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Machine2?.setOrganization) { await Machine2.setOrganization(relatedOrganization2); } } async function associatePerformanceCategoryWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const PerformanceCategory0 = await PerformanceCategories.findOne({ order: [['id', 'ASC']], offset: 0, }); if (PerformanceCategory0?.setOrganization) { await PerformanceCategory0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const PerformanceCategory1 = await PerformanceCategories.findOne({ order: [['id', 'ASC']], offset: 1, }); if (PerformanceCategory1?.setOrganization) { await PerformanceCategory1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const PerformanceCategory2 = await PerformanceCategories.findOne({ order: [['id', 'ASC']], offset: 2, }); if (PerformanceCategory2?.setOrganization) { await PerformanceCategory2.setOrganization(relatedOrganization2); } } async function associateProjectWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Project0 = await Projects.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Project0?.setOrganization) { await Project0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Project1 = await Projects.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Project1?.setOrganization) { await Project1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Project2 = await Projects.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Project2?.setOrganization) { await Project2.setOrganization(relatedOrganization2); } } async function associateSectorWithProject() { const relatedProject0 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Sector0 = await Sectors.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Sector0?.setProject) { await Sector0.setProject(relatedProject0); } const relatedProject1 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Sector1 = await Sectors.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Sector1?.setProject) { await Sector1.setProject(relatedProject1); } const relatedProject2 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Sector2 = await Sectors.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Sector2?.setProject) { await Sector2.setProject(relatedProject2); } } async function associateSectorWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Sector0 = await Sectors.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Sector0?.setOrganization) { await Sector0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Sector1 = await Sectors.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Sector1?.setOrganization) { await Sector1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Sector2 = await Sectors.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Sector2?.setOrganization) { await Sector2.setOrganization(relatedOrganization2); } } async function associateShiftWithMachine() { const relatedMachine0 = await Machines.findOne({ offset: Math.floor(Math.random() * (await Machines.count())), }); const Shift0 = await Shifts.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Shift0?.setMachine) { await Shift0.setMachine(relatedMachine0); } const relatedMachine1 = await Machines.findOne({ offset: Math.floor(Math.random() * (await Machines.count())), }); const Shift1 = await Shifts.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Shift1?.setMachine) { await Shift1.setMachine(relatedMachine1); } const relatedMachine2 = await Machines.findOne({ offset: Math.floor(Math.random() * (await Machines.count())), }); const Shift2 = await Shifts.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Shift2?.setMachine) { await Shift2.setMachine(relatedMachine2); } } async function associateShiftWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Shift0 = await Shifts.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Shift0?.setOrganization) { await Shift0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Shift1 = await Shifts.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Shift1?.setOrganization) { await Shift1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Shift2 = await Shifts.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Shift2?.setOrganization) { await Shift2.setOrganization(relatedOrganization2); } } async function associateVacationWithEmployee() { const relatedEmployee0 = await Employees.findOne({ offset: Math.floor(Math.random() * (await Employees.count())), }); const Vacation0 = await Vacations.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Vacation0?.setEmployee) { await Vacation0.setEmployee(relatedEmployee0); } const relatedEmployee1 = await Employees.findOne({ offset: Math.floor(Math.random() * (await Employees.count())), }); const Vacation1 = await Vacations.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Vacation1?.setEmployee) { await Vacation1.setEmployee(relatedEmployee1); } const relatedEmployee2 = await Employees.findOne({ offset: Math.floor(Math.random() * (await Employees.count())), }); const Vacation2 = await Vacations.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Vacation2?.setEmployee) { await Vacation2.setEmployee(relatedEmployee2); } } async function associateVacationWithSubstitute_employee() { const relatedSubstitute_employee0 = await Employees.findOne({ offset: Math.floor(Math.random() * (await Employees.count())), }); const Vacation0 = await Vacations.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Vacation0?.setSubstitute_employee) { await Vacation0.setSubstitute_employee(relatedSubstitute_employee0); } const relatedSubstitute_employee1 = await Employees.findOne({ offset: Math.floor(Math.random() * (await Employees.count())), }); const Vacation1 = await Vacations.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Vacation1?.setSubstitute_employee) { await Vacation1.setSubstitute_employee(relatedSubstitute_employee1); } const relatedSubstitute_employee2 = await Employees.findOne({ offset: Math.floor(Math.random() * (await Employees.count())), }); const Vacation2 = await Vacations.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Vacation2?.setSubstitute_employee) { await Vacation2.setSubstitute_employee(relatedSubstitute_employee2); } } async function associateVacationWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Vacation0 = await Vacations.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Vacation0?.setOrganization) { await Vacation0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Vacation1 = await Vacations.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Vacation1?.setOrganization) { await Vacation1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Vacation2 = await Vacations.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Vacation2?.setOrganization) { await Vacation2.setOrganization(relatedOrganization2); } } module.exports = { up: async (queryInterface, Sequelize) => { await Absences.bulkCreate(AbsencesData); await EmployeeStatus.bulkCreate(EmployeeStatusData); await Employees.bulkCreate(EmployeesData); await Machines.bulkCreate(MachinesData); await PerformanceCategories.bulkCreate(PerformanceCategoriesData); await Projects.bulkCreate(ProjectsData); await Sectors.bulkCreate(SectorsData); await Shifts.bulkCreate(ShiftsData); await Vacations.bulkCreate(VacationsData); await Organizations.bulkCreate(OrganizationsData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithOrganization(), await associateAbsenceWithEmployee(), await associateAbsenceWithOrganization(), await associateEmployeeStatusWithEmployee(), await associateEmployeeStatusWithOrganization(), await associateEmployeeWithShift(), await associateEmployeeWithOrganization(), await associateMachineWithSector(), await associateMachineWithOrganization(), await associatePerformanceCategoryWithOrganization(), await associateProjectWithOrganization(), await associateSectorWithProject(), await associateSectorWithOrganization(), await associateShiftWithMachine(), await associateShiftWithOrganization(), await associateVacationWithEmployee(), await associateVacationWithSubstitute_employee(), await associateVacationWithOrganization(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('absences', null, {}); await queryInterface.bulkDelete('employee_status', null, {}); await queryInterface.bulkDelete('employees', null, {}); await queryInterface.bulkDelete('machines', null, {}); await queryInterface.bulkDelete('performance_categories', null, {}); await queryInterface.bulkDelete('projects', null, {}); await queryInterface.bulkDelete('sectors', null, {}); await queryInterface.bulkDelete('shifts', null, {}); await queryInterface.bulkDelete('vacations', null, {}); await queryInterface.bulkDelete('organizations', null, {}); }, };