461 lines
9.8 KiB
JavaScript
461 lines
9.8 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Files = db.files;
|
|
|
|
const Leads = db.leads;
|
|
|
|
const Milestones = db.milestones;
|
|
|
|
const Projects = db.projects;
|
|
|
|
const Tasks = db.tasks;
|
|
|
|
const FilesData = [
|
|
{
|
|
file_name: 'Project_Plan.pdf',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
file_name: 'Design_Mockup.png',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
file_name: 'API_Documentation.docx',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
file_name: 'Marketing_Strategy.pptx',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const LeadsData = [
|
|
{
|
|
name: 'John Doe',
|
|
|
|
email: 'john.doe@example.com',
|
|
|
|
message: 'Interested in project collaboration.',
|
|
},
|
|
|
|
{
|
|
name: 'Jane Smith',
|
|
|
|
email: 'jane.smith@example.com',
|
|
|
|
message: 'Looking for partnership opportunities.',
|
|
},
|
|
|
|
{
|
|
name: 'Alice Johnson',
|
|
|
|
email: 'alice.johnson@example.com',
|
|
|
|
message: 'Requesting more information about services.',
|
|
},
|
|
|
|
{
|
|
name: 'Bob Brown',
|
|
|
|
email: 'bob.brown@example.com',
|
|
|
|
message: 'Interested in a demo of the product.',
|
|
},
|
|
];
|
|
|
|
const MilestonesData = [
|
|
{
|
|
name: 'Phase 1 Completion',
|
|
|
|
start_date: new Date('2023-11-01'),
|
|
|
|
end_date: new Date('2023-11-10'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Phase 2 Completion',
|
|
|
|
start_date: new Date('2023-11-11'),
|
|
|
|
end_date: new Date('2023-11-20'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Launch Date',
|
|
|
|
start_date: new Date('2023-11-21'),
|
|
|
|
end_date: new Date('2023-11-30'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Feedback Review',
|
|
|
|
start_date: new Date('2023-12-01'),
|
|
|
|
end_date: new Date('2023-12-05'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ProjectsData = [
|
|
{
|
|
name: 'Website Redesign',
|
|
|
|
description:
|
|
'Revamp the company website with a new design and improved UX.',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Mobile App Development',
|
|
|
|
description:
|
|
'Develop a cross-platform mobile application for our services.',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Marketing Campaign',
|
|
|
|
description: 'Launch a new marketing campaign for the upcoming product.',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Data Migration',
|
|
|
|
description: 'Migrate all data from the old system to the new platform.',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const TasksData = [
|
|
{
|
|
title: 'Design Homepage',
|
|
|
|
status: 'to_do',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
due_date: new Date('2023-11-15'),
|
|
},
|
|
|
|
{
|
|
title: 'Develop API',
|
|
|
|
status: 'in_progress',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
due_date: new Date('2023-11-20'),
|
|
},
|
|
|
|
{
|
|
title: 'Create Marketing Materials',
|
|
|
|
status: 'done',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
due_date: new Date('2023-11-10'),
|
|
},
|
|
|
|
{
|
|
title: 'Test Mobile App',
|
|
|
|
status: 'to_do',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
due_date: new Date('2023-11-25'),
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateFileWithProject() {
|
|
const relatedProject0 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const File0 = await Files.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (File0?.setProject) {
|
|
await File0.setProject(relatedProject0);
|
|
}
|
|
|
|
const relatedProject1 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const File1 = await Files.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (File1?.setProject) {
|
|
await File1.setProject(relatedProject1);
|
|
}
|
|
|
|
const relatedProject2 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const File2 = await Files.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (File2?.setProject) {
|
|
await File2.setProject(relatedProject2);
|
|
}
|
|
|
|
const relatedProject3 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const File3 = await Files.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (File3?.setProject) {
|
|
await File3.setProject(relatedProject3);
|
|
}
|
|
}
|
|
|
|
async function associateMilestoneWithProject() {
|
|
const relatedProject0 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Milestone0 = await Milestones.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Milestone0?.setProject) {
|
|
await Milestone0.setProject(relatedProject0);
|
|
}
|
|
|
|
const relatedProject1 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Milestone1 = await Milestones.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Milestone1?.setProject) {
|
|
await Milestone1.setProject(relatedProject1);
|
|
}
|
|
|
|
const relatedProject2 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Milestone2 = await Milestones.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Milestone2?.setProject) {
|
|
await Milestone2.setProject(relatedProject2);
|
|
}
|
|
|
|
const relatedProject3 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Milestone3 = await Milestones.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Milestone3?.setProject) {
|
|
await Milestone3.setProject(relatedProject3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
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 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);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Files.bulkCreate(FilesData);
|
|
|
|
await Leads.bulkCreate(LeadsData);
|
|
|
|
await Milestones.bulkCreate(MilestonesData);
|
|
|
|
await Projects.bulkCreate(ProjectsData);
|
|
|
|
await Tasks.bulkCreate(TasksData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateFileWithProject(),
|
|
|
|
await associateMilestoneWithProject(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateTaskWithProject(),
|
|
|
|
await associateTaskWithAssigned_to(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('files', null, {});
|
|
|
|
await queryInterface.bulkDelete('leads', null, {});
|
|
|
|
await queryInterface.bulkDelete('milestones', null, {});
|
|
|
|
await queryInterface.bulkDelete('projects', null, {});
|
|
|
|
await queryInterface.bulkDelete('tasks', null, {});
|
|
},
|
|
};
|