467 lines
11 KiB
JavaScript
467 lines
11 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Projects = db.projects;
|
|
|
|
const Tasks = db.tasks;
|
|
|
|
const Organizations = db.organizations;
|
|
|
|
const ProjectsData = [
|
|
{
|
|
title: 'Website Redesign',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
start_date: new Date('2023-01-10T09:00:00Z'),
|
|
|
|
end_date: new Date('2023-03-15T17:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Mobile App Development',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
start_date: new Date('2023-02-01T09:00:00Z'),
|
|
|
|
end_date: new Date('2023-06-30T17:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Cloud Migration',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
start_date: new Date('2023-03-05T09:00:00Z'),
|
|
|
|
end_date: new Date('2023-09-20T17:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'AI Research',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
start_date: new Date('2023-04-15T09:00:00Z'),
|
|
|
|
end_date: new Date('2023-12-01T17:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const TasksData = [
|
|
{
|
|
title: 'Design Mockups',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
status: 'Done',
|
|
|
|
due_date: new Date('2023-02-15T17:00:00Z'),
|
|
|
|
is_delayed: false,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Backend API Development',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
status: 'ToDo',
|
|
|
|
due_date: new Date('2023-04-01T17:00:00Z'),
|
|
|
|
is_delayed: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Data Migration',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
status: 'InProgress',
|
|
|
|
due_date: new Date('2023-07-15T17:00:00Z'),
|
|
|
|
is_delayed: false,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Algorithm Optimization',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
status: 'Done',
|
|
|
|
due_date: new Date('2023-10-01T17:00:00Z'),
|
|
|
|
is_delayed: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const OrganizationsData = [
|
|
{
|
|
name: 'Tech Innovators',
|
|
},
|
|
|
|
{
|
|
name: 'Creative Solutions',
|
|
},
|
|
|
|
{
|
|
name: 'Global Enterprises',
|
|
},
|
|
|
|
{
|
|
name: 'NextGen Tech',
|
|
},
|
|
];
|
|
|
|
// 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);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
// 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);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Projects.bulkCreate(ProjectsData);
|
|
|
|
await Tasks.bulkCreate(TasksData);
|
|
|
|
await Organizations.bulkCreate(OrganizationsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithOrganization(),
|
|
|
|
await associateProjectWithOrganization(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateProjectWithOrganization(),
|
|
|
|
await associateTaskWithProject(),
|
|
|
|
await associateTaskWithAssignee(),
|
|
|
|
await associateTaskWithOrganization(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('projects', null, {});
|
|
|
|
await queryInterface.bulkDelete('tasks', null, {});
|
|
|
|
await queryInterface.bulkDelete('organizations', null, {});
|
|
},
|
|
};
|