const db = require('../models'); const Users = db.users; const Projects = db.projects; const Tasks = db.tasks; const Tenants = db.tenants; const ProjectsData = [ { name: 'Project Alpha', description: 'Development of the new Alpha platform.', // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Project Beta', description: 'Enhancement of the Beta application.', // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Project Gamma', description: 'Testing and QA for Gamma release.', // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Project Delta', description: 'Marketing campaign for Delta launch.', // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Project Epsilon', description: 'Maintenance and support for Epsilon.', // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const TasksData = [ { title: 'Design UI for Alpha', status: 'InProgress', // type code here for "relation_one" field start_date: new Date('2023-11-01T09:00:00Z'), end_date: new Date('2023-11-10T17:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, { title: 'Implement API for Beta', status: 'Done', // type code here for "relation_one" field start_date: new Date('2023-11-05T09:00:00Z'), end_date: new Date('2023-11-15T17:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, { title: 'Test Gamma features', status: 'Done', // type code here for "relation_one" field start_date: new Date('2023-11-08T09:00:00Z'), end_date: new Date('2023-11-18T17:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, { title: 'Launch Delta campaign', status: 'ToDo', // type code here for "relation_one" field start_date: new Date('2023-11-10T09:00:00Z'), end_date: new Date('2023-11-20T17:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, { title: 'Update Epsilon documentation', status: 'Done', // type code here for "relation_one" field start_date: new Date('2023-11-12T09:00:00Z'), end_date: new Date('2023-11-22T17:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const TenantsData = [ { name: 'Tech Innovators', }, { name: 'Quality Assured', }, { name: 'Market Leaders', }, { name: 'Support Squad', }, { name: 'Development Hub', }, ]; // Similar logic for "relation_many" async function associateUserWithTenant() { const relatedTenant0 = await Tenants.findOne({ offset: Math.floor(Math.random() * (await Tenants.count())), }); const User0 = await Users.findOne({ order: [['id', 'ASC']], offset: 0, }); if (User0?.setTenant) { await User0.setTenant(relatedTenant0); } const relatedTenant1 = await Tenants.findOne({ offset: Math.floor(Math.random() * (await Tenants.count())), }); const User1 = await Users.findOne({ order: [['id', 'ASC']], offset: 1, }); if (User1?.setTenant) { await User1.setTenant(relatedTenant1); } const relatedTenant2 = await Tenants.findOne({ offset: Math.floor(Math.random() * (await Tenants.count())), }); const User2 = await Users.findOne({ order: [['id', 'ASC']], offset: 2, }); if (User2?.setTenant) { await User2.setTenant(relatedTenant2); } const relatedTenant3 = await Tenants.findOne({ offset: Math.floor(Math.random() * (await Tenants.count())), }); const User3 = await Users.findOne({ order: [['id', 'ASC']], offset: 3, }); if (User3?.setTenant) { await User3.setTenant(relatedTenant3); } const relatedTenant4 = await Tenants.findOne({ offset: Math.floor(Math.random() * (await Tenants.count())), }); const User4 = await Users.findOne({ order: [['id', 'ASC']], offset: 4, }); if (User4?.setTenant) { await User4.setTenant(relatedTenant4); } } async function associateProjectWithManager() { const relatedManager0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Project0 = await Projects.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Project0?.setManager) { await Project0.setManager(relatedManager0); } const relatedManager1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Project1 = await Projects.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Project1?.setManager) { await Project1.setManager(relatedManager1); } const relatedManager2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Project2 = await Projects.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Project2?.setManager) { await Project2.setManager(relatedManager2); } const relatedManager3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Project3 = await Projects.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Project3?.setManager) { await Project3.setManager(relatedManager3); } const relatedManager4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Project4 = await Projects.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Project4?.setManager) { await Project4.setManager(relatedManager4); } } // Similar logic for "relation_many" async function associateProjectWithTenant() { const relatedTenant0 = await Tenants.findOne({ offset: Math.floor(Math.random() * (await Tenants.count())), }); const Project0 = await Projects.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Project0?.setTenant) { await Project0.setTenant(relatedTenant0); } const relatedTenant1 = await Tenants.findOne({ offset: Math.floor(Math.random() * (await Tenants.count())), }); const Project1 = await Projects.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Project1?.setTenant) { await Project1.setTenant(relatedTenant1); } const relatedTenant2 = await Tenants.findOne({ offset: Math.floor(Math.random() * (await Tenants.count())), }); const Project2 = await Projects.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Project2?.setTenant) { await Project2.setTenant(relatedTenant2); } const relatedTenant3 = await Tenants.findOne({ offset: Math.floor(Math.random() * (await Tenants.count())), }); const Project3 = await Projects.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Project3?.setTenant) { await Project3.setTenant(relatedTenant3); } const relatedTenant4 = await Tenants.findOne({ offset: Math.floor(Math.random() * (await Tenants.count())), }); const Project4 = await Projects.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Project4?.setTenant) { await Project4.setTenant(relatedTenant4); } } async function associateProjectWithTenant() { const relatedTenant0 = await Tenants.findOne({ offset: Math.floor(Math.random() * (await Tenants.count())), }); const Project0 = await Projects.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Project0?.setTenant) { await Project0.setTenant(relatedTenant0); } const relatedTenant1 = await Tenants.findOne({ offset: Math.floor(Math.random() * (await Tenants.count())), }); const Project1 = await Projects.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Project1?.setTenant) { await Project1.setTenant(relatedTenant1); } const relatedTenant2 = await Tenants.findOne({ offset: Math.floor(Math.random() * (await Tenants.count())), }); const Project2 = await Projects.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Project2?.setTenant) { await Project2.setTenant(relatedTenant2); } const relatedTenant3 = await Tenants.findOne({ offset: Math.floor(Math.random() * (await Tenants.count())), }); const Project3 = await Projects.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Project3?.setTenant) { await Project3.setTenant(relatedTenant3); } const relatedTenant4 = await Tenants.findOne({ offset: Math.floor(Math.random() * (await Tenants.count())), }); const Project4 = await Projects.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Project4?.setTenant) { await Project4.setTenant(relatedTenant4); } } async function associateTaskWithAssignee() { const relatedAssignee0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Task0 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Task0?.setAssignee) { await Task0.setAssignee(relatedAssignee0); } const relatedAssignee1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Task1 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Task1?.setAssignee) { await Task1.setAssignee(relatedAssignee1); } const relatedAssignee2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Task2 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Task2?.setAssignee) { await Task2.setAssignee(relatedAssignee2); } const relatedAssignee3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Task3 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Task3?.setAssignee) { await Task3.setAssignee(relatedAssignee3); } const relatedAssignee4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Task4 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Task4?.setAssignee) { await Task4.setAssignee(relatedAssignee4); } } 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); } const relatedProject3 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Task3 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Task3?.setProject) { await Task3.setProject(relatedProject3); } const relatedProject4 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Task4 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Task4?.setProject) { await Task4.setProject(relatedProject4); } } async function associateTaskWithTenant() { const relatedTenant0 = await Tenants.findOne({ offset: Math.floor(Math.random() * (await Tenants.count())), }); const Task0 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Task0?.setTenant) { await Task0.setTenant(relatedTenant0); } const relatedTenant1 = await Tenants.findOne({ offset: Math.floor(Math.random() * (await Tenants.count())), }); const Task1 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Task1?.setTenant) { await Task1.setTenant(relatedTenant1); } const relatedTenant2 = await Tenants.findOne({ offset: Math.floor(Math.random() * (await Tenants.count())), }); const Task2 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Task2?.setTenant) { await Task2.setTenant(relatedTenant2); } const relatedTenant3 = await Tenants.findOne({ offset: Math.floor(Math.random() * (await Tenants.count())), }); const Task3 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Task3?.setTenant) { await Task3.setTenant(relatedTenant3); } const relatedTenant4 = await Tenants.findOne({ offset: Math.floor(Math.random() * (await Tenants.count())), }); const Task4 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Task4?.setTenant) { await Task4.setTenant(relatedTenant4); } } module.exports = { up: async (queryInterface, Sequelize) => { await Projects.bulkCreate(ProjectsData); await Tasks.bulkCreate(TasksData); await Tenants.bulkCreate(TenantsData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithTenant(), await associateProjectWithManager(), // Similar logic for "relation_many" await associateProjectWithTenant(), await associateProjectWithTenant(), await associateTaskWithAssignee(), await associateTaskWithProject(), await associateTaskWithTenant(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('projects', null, {}); await queryInterface.bulkDelete('tasks', null, {}); await queryInterface.bulkDelete('tenants', null, {}); }, };