30796/backend/src/db/seeders/20231127130745-sample-data.js
2025-04-17 18:55:57 +00:00

577 lines
14 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Projects = db.projects;
const Tasks = db.tasks;
const Organizations = db.organizations;
const ProjectsData = [
{
name: 'Project Alpha',
description: 'Initial project setup and planning',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Project Beta',
description: 'Development phase',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Project Gamma',
description: 'Testing and QA',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Project Delta',
description: 'Deployment and launch',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Project Epsilon',
description: 'Post-launch support',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
const TasksData = [
{
task_name: 'Design UI',
// type code here for "relation_one" field
percent_complete: 50,
estimated_end_date: new Date('2023-12-01T00:00:00Z'),
end_date: new Date('2023-12-05T00:00:00Z'),
story_points: 5,
// type code here for "relation_one" field
status: 'Done',
// type code here for "relation_one" field
},
{
task_name: 'Develop Backend',
// type code here for "relation_one" field
percent_complete: 30,
estimated_end_date: new Date('2023-12-10T00:00:00Z'),
end_date: new Date('2023-12-15T00:00:00Z'),
story_points: 8,
// type code here for "relation_one" field
status: 'Done',
// type code here for "relation_one" field
},
{
task_name: 'Write Test Cases',
// type code here for "relation_one" field
percent_complete: 70,
estimated_end_date: new Date('2023-12-20T00:00:00Z'),
end_date: new Date('2023-12-25T00:00:00Z'),
story_points: 3,
// type code here for "relation_one" field
status: 'InProgress',
// type code here for "relation_one" field
},
{
task_name: 'Deploy to Production',
// type code here for "relation_one" field
percent_complete: 20,
estimated_end_date: new Date('2023-12-30T00:00:00Z'),
end_date: new Date('2024-01-05T00:00:00Z'),
story_points: 10,
// type code here for "relation_one" field
status: 'Done',
// type code here for "relation_one" field
},
{
task_name: 'Monitor System',
// type code here for "relation_one" field
percent_complete: 90,
estimated_end_date: new Date('2024-01-10T00:00:00Z'),
end_date: new Date('2024-01-15T00:00:00Z'),
story_points: 2,
// type code here for "relation_one" field
status: 'ToDo',
// type code here for "relation_one" field
},
];
const OrganizationsData = [
{
name: 'Tech Innovators',
},
{
name: 'Creative Solutions',
},
{
name: 'Future Enterprises',
},
{
name: 'Visionary Group',
},
{
name: 'Innovatech',
},
];
// 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);
}
}
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);
}
}
// 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 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 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 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);
}
}
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 associateTaskWithAssigned_to(),
await associateTaskWithProject(),
await associateTaskWithOrganization(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('projects', null, {});
await queryInterface.bulkDelete('tasks', null, {});
await queryInterface.bulkDelete('organizations', null, {});
},
};