const db = require('../models'); const Users = db.users; const Categories = db.categories; const Projects = db.projects; const Tasks = db.tasks; const Organizations = db.organizations; const Tags = db.tags; const CategoriesData = [ { name: 'Jonas Salk', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Francis Crick', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Pierre Simon de Laplace', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Andreas Vesalius', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Justus Liebig', // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const ProjectsData = [ { name: 'Archimedes', description: 'Like fire across the galaxy the Clone Wars spread. In league with the wicked Count Dooku, more and more planets slip. Against this threat, upon the Jedi Knights falls the duty to lead the newly formed army of the Republic. And as the heat of war grows, so, to, grows the prowess of one most gifted student of the Force.', // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Claude Levi-Strauss', description: 'Strong is Vader. Mind what you have learned. Save you it can.', // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Francis Galton', description: 'Soon will I rest, yes, forever sleep. Earned it I have. Twilight is upon me, soon night must fall.', // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Charles Sherrington', description: 'To answer power with power, the Jedi way this is', // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Ludwig Boltzmann', description: 'Death is a natural part of life. Rejoice for those around you who transform into the Force. Mourn them do not. Miss them do not. Attachment leads to jealously. The shadow of greed, that is.', // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const TasksData = [ { title: 'No one tells me shit', description: 'Through the Force, things you will see. Other places. The future - the past. Old friends long gone.', status: 'ToDo', // 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('2024-08-22'), end_date: new Date('2024-04-20'), // type code here for "relation_one" field // type code here for "relation_many" field }, { title: 'No one tells me shit', description: 'That is why you fail.', status: 'InProgress', // 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('2024-07-25'), end_date: new Date('2025-01-16'), // type code here for "relation_one" field // type code here for "relation_many" field }, { title: 'Let me tell ya', description: 'Much to learn you still have my old padawan. ... This is just the beginning!', status: 'ToDo', // 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('2024-10-08'), end_date: new Date('2024-05-10'), // type code here for "relation_one" field // type code here for "relation_many" field }, { title: "How 'bout them Cowboys", description: 'Luminous beings are we - not this crude matter.', status: 'ToDo', // 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('2024-12-06'), end_date: new Date('2025-03-25'), // type code here for "relation_one" field // type code here for "relation_many" field }, { title: 'I want my 5$ back', description: 'Not if anything to say about it I have', status: 'ToDo', // 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('2024-07-05'), end_date: new Date('2024-06-13'), // type code here for "relation_one" field // type code here for "relation_many" field }, ]; const OrganizationsData = [ { name: 'Pierre Simon de Laplace', }, { name: 'Isaac Newton', }, { name: 'Enrico Fermi', }, { name: 'Isaac Newton', }, { name: 'Ernst Haeckel', }, ]; const TagsData = [ { // type code here for "relation_one" field name: 'Enrico Fermi', }, { // type code here for "relation_one" field name: 'Francis Galton', }, { // type code here for "relation_one" field name: 'Anton van Leeuwenhoek', }, { // type code here for "relation_one" field name: 'John von Neumann', }, { // type code here for "relation_one" field name: 'Alfred Binet', }, ]; // 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); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const User3 = await Users.findOne({ order: [['id', 'ASC']], offset: 3, }); if (User3?.setOrganization) { await User3.setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const User4 = await Users.findOne({ order: [['id', 'ASC']], offset: 4, }); if (User4?.setOrganization) { await User4.setOrganization(relatedOrganization4); } } // Similar logic for "relation_many" async function associateCategoryWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Category0 = await Categories.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Category0?.setOrganization) { await Category0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Category1 = await Categories.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Category1?.setOrganization) { await Category1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Category2 = await Categories.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Category2?.setOrganization) { await Category2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Category3 = await Categories.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Category3?.setOrganization) { await Category3.setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Category4 = await Categories.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Category4?.setOrganization) { await Category4.setOrganization(relatedOrganization4); } } // 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); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Project3 = await Projects.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Project3?.setOrganization) { await Project3.setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Project4 = await Projects.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Project4?.setOrganization) { await Project4.setOrganization(relatedOrganization4); } } 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 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); } const relatedAssigned_to3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Task3 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Task3?.setAssigned_to) { await Task3.setAssigned_to(relatedAssigned_to3); } const relatedAssigned_to4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Task4 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Task4?.setAssigned_to) { await Task4.setAssigned_to(relatedAssigned_to4); } } async function associateTaskWithCategory() { const relatedCategory0 = await Categories.findOne({ offset: Math.floor(Math.random() * (await Categories.count())), }); const Task0 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Task0?.setCategory) { await Task0.setCategory(relatedCategory0); } const relatedCategory1 = await Categories.findOne({ offset: Math.floor(Math.random() * (await Categories.count())), }); const Task1 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Task1?.setCategory) { await Task1.setCategory(relatedCategory1); } const relatedCategory2 = await Categories.findOne({ offset: Math.floor(Math.random() * (await Categories.count())), }); const Task2 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Task2?.setCategory) { await Task2.setCategory(relatedCategory2); } const relatedCategory3 = await Categories.findOne({ offset: Math.floor(Math.random() * (await Categories.count())), }); const Task3 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Task3?.setCategory) { await Task3.setCategory(relatedCategory3); } const relatedCategory4 = await Categories.findOne({ offset: Math.floor(Math.random() * (await Categories.count())), }); const Task4 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Task4?.setCategory) { await Task4.setCategory(relatedCategory4); } } 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); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Task3 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Task3?.setOrganization) { await Task3.setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Task4 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Task4?.setOrganization) { await Task4.setOrganization(relatedOrganization4); } } // Similar logic for "relation_many" async function associateTagWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Tag0 = await Tags.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Tag0?.setOrganization) { await Tag0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Tag1 = await Tags.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Tag1?.setOrganization) { await Tag1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Tag2 = await Tags.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Tag2?.setOrganization) { await Tag2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Tag3 = await Tags.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Tag3?.setOrganization) { await Tag3.setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Tag4 = await Tags.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Tag4?.setOrganization) { await Tag4.setOrganization(relatedOrganization4); } } module.exports = { up: async (queryInterface, Sequelize) => { await Categories.bulkCreate(CategoriesData); await Projects.bulkCreate(ProjectsData); await Tasks.bulkCreate(TasksData); await Organizations.bulkCreate(OrganizationsData); await Tags.bulkCreate(TagsData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithOrganization(), // Similar logic for "relation_many" await associateCategoryWithOrganization(), // Similar logic for "relation_many" // Similar logic for "relation_many" await associateProjectWithOrganization(), await associateTaskWithProject(), await associateTaskWithAssigned_to(), await associateTaskWithCategory(), await associateTaskWithOrganization(), // Similar logic for "relation_many" await associateTagWithOrganization(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('categories', null, {}); await queryInterface.bulkDelete('projects', null, {}); await queryInterface.bulkDelete('tasks', null, {}); await queryInterface.bulkDelete('organizations', null, {}); await queryInterface.bulkDelete('tags', null, {}); }, };