32363/backend/src/db/seeders/20231127130745-sample-data.js
2025-06-20 11:39:48 +00:00

691 lines
16 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Customers = db.customers;
const Projects = db.projects;
const Tasks = db.tasks;
const Timesheets = db.timesheets;
const Organizations = db.organizations;
const CustomersData = [
{
name: 'Acme Corp',
// type code here for "relation_many" field
// type code here for "relation_one" field
PhoneNumber: 'Albert Einstein',
InvoicingEmail: 'Comte de Buffon',
Address: 'Antoine Laurent Lavoisier',
},
{
name: 'Globex Inc',
// type code here for "relation_many" field
// type code here for "relation_one" field
PhoneNumber: 'Arthur Eddington',
InvoicingEmail: 'Emil Kraepelin',
Address: 'Sigmund Freud',
},
{
name: 'Initech',
// type code here for "relation_many" field
// type code here for "relation_one" field
PhoneNumber: 'George Gaylord Simpson',
InvoicingEmail: 'Charles Lyell',
Address: 'Hermann von Helmholtz',
},
];
const ProjectsData = [
{
name: 'Project Alpha',
// type code here for "relation_one" field
// type code here for "relation_many" field
budget: 50000,
// type code here for "relation_one" field
// type code here for "relation_one" field
DevelopmentCost: 68.78,
MaintenanceCost: 70.05,
ExpenseCost: 'B. F. Skinner',
Profits: 82.01,
StartDate: new Date(Date.now()),
EndDate: 'Max Planck',
},
{
name: 'Project Beta',
// type code here for "relation_one" field
// type code here for "relation_many" field
budget: 75000,
// type code here for "relation_one" field
// type code here for "relation_one" field
DevelopmentCost: 68.69,
MaintenanceCost: 90.16,
ExpenseCost: 'Albrecht von Haller',
Profits: 63.75,
StartDate: new Date(Date.now()),
EndDate: 'Lynn Margulis',
},
{
name: 'Project Gamma',
// type code here for "relation_one" field
// type code here for "relation_many" field
budget: 100000,
// type code here for "relation_one" field
// type code here for "relation_one" field
DevelopmentCost: 78.44,
MaintenanceCost: 25.18,
ExpenseCost: 'Jean Baptiste Lamarck',
Profits: 51.98,
StartDate: new Date(Date.now()),
EndDate: 'Edwin Hubble',
},
];
const TasksData = [
{
title: 'Design Phase',
status: 'InProgress',
// type code here for "relation_one" field
start_date: new Date('2023-11-01T09:00:00Z'),
end_date: new Date('2023-11-15T17:00:00Z'),
// type code here for "relation_one" field
TaskType: 'User Story',
EpicEstimatedCost: 78.27,
EpicActualCost: 82.44,
EpicEstimatedTime: 3,
EpicCostVariance: 80.45,
EpicActualTime: 7,
EpicVarianceTime: 2,
EpicCompletionRate: 'William Harvey',
},
{
title: 'Development Phase',
status: 'InProgress',
// type code here for "relation_one" field
start_date: new Date('2023-11-16T09:00:00Z'),
end_date: new Date('2023-12-15T17:00:00Z'),
// type code here for "relation_one" field
TaskType: 'Feature',
EpicEstimatedCost: 26.45,
EpicActualCost: 82.28,
EpicEstimatedTime: 8,
EpicCostVariance: 95.76,
EpicActualTime: 4,
EpicVarianceTime: 1,
EpicCompletionRate: 'Sigmund Freud',
},
{
title: 'Testing Phase',
status: 'NotStarted',
// type code here for "relation_one" field
start_date: new Date('2023-12-16T09:00:00Z'),
end_date: new Date('2023-12-31T17:00:00Z'),
// type code here for "relation_one" field
TaskType: 'Feature',
EpicEstimatedCost: 24.21,
EpicActualCost: 92.46,
EpicEstimatedTime: 7,
EpicCostVariance: 55.98,
EpicActualTime: 9,
EpicVarianceTime: 3,
EpicCompletionRate: 'Alfred Wegener',
},
];
const TimesheetsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
hours: 8,
date: new Date('2023-11-01T09:00:00Z'),
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
hours: 6,
date: new Date('2023-11-02T09:00:00Z'),
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
hours: 7,
date: new Date('2023-11-03T09:00:00Z'),
// type code here for "relation_one" field
},
];
const OrganizationsData = [
{
name: 'Tech Innovators',
},
{
name: 'Green Solutions',
},
{
name: 'Blue Sky Enterprises',
},
];
// 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);
}
}
// Similar logic for "relation_many"
async function associateCustomerWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Customer0 = await Customers.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Customer0?.setOrganization) {
await Customer0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Customer1 = await Customers.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Customer1?.setOrganization) {
await Customer1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Customer2 = await Customers.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Customer2?.setOrganization) {
await Customer2.setOrganization(relatedOrganization2);
}
}
async function associateProjectWithCustomer() {
const relatedCustomer0 = await Customers.findOne({
offset: Math.floor(Math.random() * (await Customers.count())),
});
const Project0 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Project0?.setCustomer) {
await Project0.setCustomer(relatedCustomer0);
}
const relatedCustomer1 = await Customers.findOne({
offset: Math.floor(Math.random() * (await Customers.count())),
});
const Project1 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Project1?.setCustomer) {
await Project1.setCustomer(relatedCustomer1);
}
const relatedCustomer2 = await Customers.findOne({
offset: Math.floor(Math.random() * (await Customers.count())),
});
const Project2 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Project2?.setCustomer) {
await Project2.setCustomer(relatedCustomer2);
}
}
// 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);
}
}
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);
}
}
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);
}
}
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);
}
}
async function associateTimesheetWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Timesheet0 = await Timesheets.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Timesheet0?.setUser) {
await Timesheet0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Timesheet1 = await Timesheets.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Timesheet1?.setUser) {
await Timesheet1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Timesheet2 = await Timesheets.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Timesheet2?.setUser) {
await Timesheet2.setUser(relatedUser2);
}
}
async function associateTimesheetWithTask() {
const relatedTask0 = await Tasks.findOne({
offset: Math.floor(Math.random() * (await Tasks.count())),
});
const Timesheet0 = await Timesheets.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Timesheet0?.setTask) {
await Timesheet0.setTask(relatedTask0);
}
const relatedTask1 = await Tasks.findOne({
offset: Math.floor(Math.random() * (await Tasks.count())),
});
const Timesheet1 = await Timesheets.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Timesheet1?.setTask) {
await Timesheet1.setTask(relatedTask1);
}
const relatedTask2 = await Tasks.findOne({
offset: Math.floor(Math.random() * (await Tasks.count())),
});
const Timesheet2 = await Timesheets.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Timesheet2?.setTask) {
await Timesheet2.setTask(relatedTask2);
}
}
async function associateTimesheetWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Timesheet0 = await Timesheets.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Timesheet0?.setOrganization) {
await Timesheet0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Timesheet1 = await Timesheets.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Timesheet1?.setOrganization) {
await Timesheet1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Timesheet2 = await Timesheets.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Timesheet2?.setOrganization) {
await Timesheet2.setOrganization(relatedOrganization2);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Customers.bulkCreate(CustomersData);
await Projects.bulkCreate(ProjectsData);
await Tasks.bulkCreate(TasksData);
await Timesheets.bulkCreate(TimesheetsData);
await Organizations.bulkCreate(OrganizationsData);
await Promise.all([
// Similar logic for "relation_many"
await associateUserWithOrganization(),
// Similar logic for "relation_many"
await associateCustomerWithOrganization(),
await associateProjectWithCustomer(),
// Similar logic for "relation_many"
await associateProjectWithOrganization(),
await associateProjectWithOrganization(),
await associateTaskWithProject(),
await associateTaskWithOrganization(),
await associateTimesheetWithUser(),
await associateTimesheetWithTask(),
await associateTimesheetWithOrganization(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('customers', null, {});
await queryInterface.bulkDelete('projects', null, {});
await queryInterface.bulkDelete('tasks', null, {});
await queryInterface.bulkDelete('timesheets', null, {});
await queryInterface.bulkDelete('organizations', null, {});
},
};