421 lines
9.6 KiB
JavaScript
421 lines
9.6 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Comments = db.comments;
|
|
|
|
const Projects = db.projects;
|
|
|
|
const Tasks = db.tasks;
|
|
|
|
const CommentsData = [
|
|
{
|
|
content: 'Great progress on the UI design!',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
content: 'Backend development is on track.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
content: 'Documentation is clear and concise.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
content: 'Testing will start next week.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ProjectsData = [
|
|
{
|
|
name: 'Project Alpha',
|
|
|
|
description: 'Initial phase of the project management tool development.',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Project Beta',
|
|
|
|
description:
|
|
'Enhancements and new features for the project management tool.',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Project Gamma',
|
|
|
|
description:
|
|
'Testing and quality assurance for the project management tool.',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Project Delta',
|
|
|
|
description: 'Deployment and maintenance of the project management tool.',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const TasksData = [
|
|
{
|
|
title: 'Design UI',
|
|
|
|
description: 'Create wireframes and design the user interface.',
|
|
|
|
status: 'Done',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-10-01T09:00:00Z'),
|
|
|
|
due_date: new Date('2023-10-10T17:00:00Z'),
|
|
},
|
|
|
|
{
|
|
title: 'Develop Backend',
|
|
|
|
description: 'Implement the backend services and APIs.',
|
|
|
|
status: 'ToDo',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-10-05T09:00:00Z'),
|
|
|
|
due_date: new Date('2023-10-20T17:00:00Z'),
|
|
},
|
|
|
|
{
|
|
title: 'Write Documentation',
|
|
|
|
description: 'Document the project setup and usage instructions.',
|
|
|
|
status: 'InProgress',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-10-15T09:00:00Z'),
|
|
|
|
due_date: new Date('2023-10-25T17:00:00Z'),
|
|
},
|
|
|
|
{
|
|
title: 'Conduct Testing',
|
|
|
|
description: 'Perform unit and integration testing.',
|
|
|
|
status: 'InProgress',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-10-20T09:00:00Z'),
|
|
|
|
due_date: new Date('2023-10-30T17:00:00Z'),
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateCommentWithTask() {
|
|
const relatedTask0 = await Tasks.findOne({
|
|
offset: Math.floor(Math.random() * (await Tasks.count())),
|
|
});
|
|
const Comment0 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Comment0?.setTask) {
|
|
await Comment0.setTask(relatedTask0);
|
|
}
|
|
|
|
const relatedTask1 = await Tasks.findOne({
|
|
offset: Math.floor(Math.random() * (await Tasks.count())),
|
|
});
|
|
const Comment1 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Comment1?.setTask) {
|
|
await Comment1.setTask(relatedTask1);
|
|
}
|
|
|
|
const relatedTask2 = await Tasks.findOne({
|
|
offset: Math.floor(Math.random() * (await Tasks.count())),
|
|
});
|
|
const Comment2 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Comment2?.setTask) {
|
|
await Comment2.setTask(relatedTask2);
|
|
}
|
|
|
|
const relatedTask3 = await Tasks.findOne({
|
|
offset: Math.floor(Math.random() * (await Tasks.count())),
|
|
});
|
|
const Comment3 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Comment3?.setTask) {
|
|
await Comment3.setTask(relatedTask3);
|
|
}
|
|
}
|
|
|
|
async function associateCommentWithAuthor() {
|
|
const relatedAuthor0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Comment0 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Comment0?.setAuthor) {
|
|
await Comment0.setAuthor(relatedAuthor0);
|
|
}
|
|
|
|
const relatedAuthor1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Comment1 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Comment1?.setAuthor) {
|
|
await Comment1.setAuthor(relatedAuthor1);
|
|
}
|
|
|
|
const relatedAuthor2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Comment2 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Comment2?.setAuthor) {
|
|
await Comment2.setAuthor(relatedAuthor2);
|
|
}
|
|
|
|
const relatedAuthor3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Comment3 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Comment3?.setAuthor) {
|
|
await Comment3.setAuthor(relatedAuthor3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateProjectWithOwner() {
|
|
const relatedOwner0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Project0 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Project0?.setOwner) {
|
|
await Project0.setOwner(relatedOwner0);
|
|
}
|
|
|
|
const relatedOwner1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Project1 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Project1?.setOwner) {
|
|
await Project1.setOwner(relatedOwner1);
|
|
}
|
|
|
|
const relatedOwner2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Project2 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Project2?.setOwner) {
|
|
await Project2.setOwner(relatedOwner2);
|
|
}
|
|
|
|
const relatedOwner3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Project3 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Project3?.setOwner) {
|
|
await Project3.setOwner(relatedOwner3);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Comments.bulkCreate(CommentsData);
|
|
|
|
await Projects.bulkCreate(ProjectsData);
|
|
|
|
await Tasks.bulkCreate(TasksData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateCommentWithTask(),
|
|
|
|
await associateCommentWithAuthor(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateProjectWithOwner(),
|
|
|
|
await associateTaskWithProject(),
|
|
|
|
await associateTaskWithAssignee(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('comments', null, {});
|
|
|
|
await queryInterface.bulkDelete('projects', null, {});
|
|
|
|
await queryInterface.bulkDelete('tasks', null, {});
|
|
},
|
|
};
|