468 lines
11 KiB
JavaScript
468 lines
11 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Projects = db.projects;
|
|
|
|
const Tasks = db.tasks;
|
|
|
|
const Accounts = db.accounts;
|
|
|
|
const ProjectsData = [
|
|
{
|
|
name: 'AI Development',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Website Redesign',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Mobile App Launch',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Cloud Migration',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Data Analysis',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const TasksData = [
|
|
{
|
|
description: 'Research AI algorithms',
|
|
|
|
status: 'Done',
|
|
|
|
due_date: new Date('2023-11-01T10:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
description: 'Design new homepage layout',
|
|
|
|
status: 'Done',
|
|
|
|
due_date: new Date('2023-11-05T15:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
description: 'Test app on Android devices',
|
|
|
|
status: 'ToDo',
|
|
|
|
due_date: new Date('2023-11-10T09:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
description: 'Set up cloud infrastructure',
|
|
|
|
status: 'Done',
|
|
|
|
due_date: new Date('2023-11-15T12:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
description: 'Analyze customer data trends',
|
|
|
|
status: 'ToDo',
|
|
|
|
due_date: new Date('2023-11-20T14:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const AccountsData = [
|
|
{
|
|
name: 'Tech Innovators',
|
|
},
|
|
|
|
{
|
|
name: 'Creative Solutions',
|
|
},
|
|
|
|
{
|
|
name: 'Future Enterprises',
|
|
},
|
|
|
|
{
|
|
name: 'Global Ventures',
|
|
},
|
|
|
|
{
|
|
name: 'NextGen Tech',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateUserWithAccount() {
|
|
const relatedAccount0 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const User0 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (User0?.setAccount) {
|
|
await User0.setAccount(relatedAccount0);
|
|
}
|
|
|
|
const relatedAccount1 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const User1 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (User1?.setAccount) {
|
|
await User1.setAccount(relatedAccount1);
|
|
}
|
|
|
|
const relatedAccount2 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const User2 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (User2?.setAccount) {
|
|
await User2.setAccount(relatedAccount2);
|
|
}
|
|
|
|
const relatedAccount3 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const User3 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (User3?.setAccount) {
|
|
await User3.setAccount(relatedAccount3);
|
|
}
|
|
|
|
const relatedAccount4 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const User4 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (User4?.setAccount) {
|
|
await User4.setAccount(relatedAccount4);
|
|
}
|
|
}
|
|
|
|
async function associateProjectWithAccount() {
|
|
const relatedAccount0 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const Project0 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Project0?.setAccount) {
|
|
await Project0.setAccount(relatedAccount0);
|
|
}
|
|
|
|
const relatedAccount1 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const Project1 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Project1?.setAccount) {
|
|
await Project1.setAccount(relatedAccount1);
|
|
}
|
|
|
|
const relatedAccount2 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const Project2 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Project2?.setAccount) {
|
|
await Project2.setAccount(relatedAccount2);
|
|
}
|
|
|
|
const relatedAccount3 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const Project3 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Project3?.setAccount) {
|
|
await Project3.setAccount(relatedAccount3);
|
|
}
|
|
|
|
const relatedAccount4 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const Project4 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Project4?.setAccount) {
|
|
await Project4.setAccount(relatedAccount4);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateProjectWithAccount() {
|
|
const relatedAccount0 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const Project0 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Project0?.setAccount) {
|
|
await Project0.setAccount(relatedAccount0);
|
|
}
|
|
|
|
const relatedAccount1 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const Project1 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Project1?.setAccount) {
|
|
await Project1.setAccount(relatedAccount1);
|
|
}
|
|
|
|
const relatedAccount2 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const Project2 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Project2?.setAccount) {
|
|
await Project2.setAccount(relatedAccount2);
|
|
}
|
|
|
|
const relatedAccount3 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const Project3 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Project3?.setAccount) {
|
|
await Project3.setAccount(relatedAccount3);
|
|
}
|
|
|
|
const relatedAccount4 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const Project4 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Project4?.setAccount) {
|
|
await Project4.setAccount(relatedAccount4);
|
|
}
|
|
}
|
|
|
|
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 associateTaskWithAccount() {
|
|
const relatedAccount0 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const Task0 = await Tasks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Task0?.setAccount) {
|
|
await Task0.setAccount(relatedAccount0);
|
|
}
|
|
|
|
const relatedAccount1 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const Task1 = await Tasks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Task1?.setAccount) {
|
|
await Task1.setAccount(relatedAccount1);
|
|
}
|
|
|
|
const relatedAccount2 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const Task2 = await Tasks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Task2?.setAccount) {
|
|
await Task2.setAccount(relatedAccount2);
|
|
}
|
|
|
|
const relatedAccount3 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const Task3 = await Tasks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Task3?.setAccount) {
|
|
await Task3.setAccount(relatedAccount3);
|
|
}
|
|
|
|
const relatedAccount4 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const Task4 = await Tasks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Task4?.setAccount) {
|
|
await Task4.setAccount(relatedAccount4);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Projects.bulkCreate(ProjectsData);
|
|
|
|
await Tasks.bulkCreate(TasksData);
|
|
|
|
await Accounts.bulkCreate(AccountsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithAccount(),
|
|
|
|
await associateProjectWithAccount(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateProjectWithAccount(),
|
|
|
|
await associateTaskWithProject(),
|
|
|
|
await associateTaskWithAccount(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('projects', null, {});
|
|
|
|
await queryInterface.bulkDelete('tasks', null, {});
|
|
|
|
await queryInterface.bulkDelete('accounts', null, {});
|
|
},
|
|
};
|