const db = require('../models'); const Users = db.users; const Projects = db.projects; const Suppliers = db.suppliers; const Tasks = db.tasks; const Organizations = db.organizations; const ProjectsData = [ { name: 'Project Alpha', description: 'Initial phase of the new product launch.', start_date: new Date('2023-11-01T09:00:00Z'), end_date: new Date('2023-12-31T17:00:00Z'), // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Project Beta', description: 'Development of the mobile application.', start_date: new Date('2023-10-15T09:00:00Z'), end_date: new Date('2024-01-15T17:00:00Z'), // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Project Gamma', description: 'Research and development for AI integration.', start_date: new Date('2023-09-01T09:00:00Z'), end_date: new Date('2023-11-30T17:00:00Z'), // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const SuppliersData = [ { name: 'Tech Supplies Co.', contact_info: '123 Tech Street, tech@supplies.com', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Office Essentials Ltd.', contact_info: '456 Office Ave, office@essentials.com', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Creative Solutions Inc.', contact_info: '789 Creative Blvd, creative@solutions.com', // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const TasksData = [ { title: 'Design UI Mockups', description: 'Create initial design mockups for the new app.', status: 'InProgress', due_date: new Date('2023-11-10T17:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field }, { title: 'Develop Backend API', description: 'Implement RESTful API for the application.', status: 'Done', due_date: new Date('2023-12-01T17:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field }, { title: 'Conduct User Testing', description: 'Organize and conduct user testing sessions.', status: 'ToDo', due_date: new Date('2023-11-20T17:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const OrganizationsData = [ { name: 'Gregor Mendel', }, { name: 'Erwin Schrodinger', }, { name: 'Galileo Galilei', }, ]; // 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); } } // Similar logic for "relation_many" // Similar logic for "relation_many" 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); } } // Similar logic for "relation_many" async function associateSupplierWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Supplier0 = await Suppliers.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Supplier0?.setOrganization) { await Supplier0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Supplier1 = await Suppliers.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Supplier1?.setOrganization) { await Supplier1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Supplier2 = await Suppliers.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Supplier2?.setOrganization) { await Supplier2.setOrganization(relatedOrganization2); } } async function associateTaskWithAssigned_to() { const relatedAssigned_to0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Task0 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Task0?.setAssigned_to) { await Task0.setAssigned_to(relatedAssigned_to0); } const relatedAssigned_to1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Task1 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Task1?.setAssigned_to) { await Task1.setAssigned_to(relatedAssigned_to1); } const relatedAssigned_to2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Task2 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Task2?.setAssigned_to) { await Task2.setAssigned_to(relatedAssigned_to2); } } async function associateTaskWithProject() { const relatedProject0 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Task0 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Task0?.setProject) { await Task0.setProject(relatedProject0); } const relatedProject1 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Task1 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Task1?.setProject) { await Task1.setProject(relatedProject1); } const relatedProject2 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Task2 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Task2?.setProject) { await Task2.setProject(relatedProject2); } } async function associateTaskWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Task0 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Task0?.setOrganization) { await Task0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Task1 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Task1?.setOrganization) { await Task1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Task2 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Task2?.setOrganization) { await Task2.setOrganization(relatedOrganization2); } } module.exports = { up: async (queryInterface, Sequelize) => { await Projects.bulkCreate(ProjectsData); await Suppliers.bulkCreate(SuppliersData); await Tasks.bulkCreate(TasksData); await Organizations.bulkCreate(OrganizationsData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithOrganization(), // Similar logic for "relation_many" // Similar logic for "relation_many" await associateProjectWithOrganization(), // Similar logic for "relation_many" await associateSupplierWithOrganization(), await associateTaskWithAssigned_to(), await associateTaskWithProject(), await associateTaskWithOrganization(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('projects', null, {}); await queryInterface.bulkDelete('suppliers', null, {}); await queryInterface.bulkDelete('tasks', null, {}); await queryInterface.bulkDelete('organizations', null, {}); }, };