295 lines
6.7 KiB
JavaScript
295 lines
6.7 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Compilations = db.compilations;
|
|
|
|
const Notifications = db.notifications;
|
|
|
|
const Projects = db.projects;
|
|
|
|
const CompilationsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
start_time: new Date('2023-10-01T10:05:00Z'),
|
|
|
|
end_time: new Date('2023-10-01T10:10:00Z'),
|
|
|
|
success: true,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
start_time: new Date('2023-09-15T09:35:00Z'),
|
|
|
|
end_time: new Date('2023-09-15T09:40:00Z'),
|
|
|
|
success: false,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
start_time: new Date('2023-08-20T08:20:00Z'),
|
|
|
|
end_time: new Date('2023-08-20T08:25:00Z'),
|
|
|
|
success: true,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
start_time: new Date('2023-07-10T07:05:00Z'),
|
|
|
|
end_time: new Date('2023-07-10T07:10:00Z'),
|
|
|
|
success: true,
|
|
},
|
|
];
|
|
|
|
const NotificationsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
message: 'Welcome to the IDE!',
|
|
|
|
sent_at: new Date('2023-10-01T10:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
message: 'Your project compilation failed.',
|
|
|
|
sent_at: new Date('2023-09-15T09:40:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
message: 'New project created successfully.',
|
|
|
|
sent_at: new Date('2023-08-20T08:15:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
message: 'Compilation completed successfully.',
|
|
|
|
sent_at: new Date('2023-07-10T07:10:00Z'),
|
|
},
|
|
];
|
|
|
|
const ProjectsData = [
|
|
{
|
|
name: 'HelloWorldApp',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
created_date: new Date('2023-10-01T10:00:00Z'),
|
|
|
|
last_modified_date: new Date('2023-10-02T12:00:00Z'),
|
|
},
|
|
|
|
{
|
|
name: 'WeatherApp',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
created_date: new Date('2023-09-15T09:30:00Z'),
|
|
|
|
last_modified_date: new Date('2023-09-16T11:45:00Z'),
|
|
},
|
|
|
|
{
|
|
name: 'ToDoList',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
created_date: new Date('2023-08-20T08:15:00Z'),
|
|
|
|
last_modified_date: new Date('2023-08-21T10:20:00Z'),
|
|
},
|
|
|
|
{
|
|
name: 'Calculator',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
created_date: new Date('2023-07-10T07:00:00Z'),
|
|
|
|
last_modified_date: new Date('2023-07-11T09:10:00Z'),
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateCompilationWithProject() {
|
|
const relatedProject0 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Compilation0 = await Compilations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Compilation0?.setProject) {
|
|
await Compilation0.setProject(relatedProject0);
|
|
}
|
|
|
|
const relatedProject1 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Compilation1 = await Compilations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Compilation1?.setProject) {
|
|
await Compilation1.setProject(relatedProject1);
|
|
}
|
|
|
|
const relatedProject2 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Compilation2 = await Compilations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Compilation2?.setProject) {
|
|
await Compilation2.setProject(relatedProject2);
|
|
}
|
|
|
|
const relatedProject3 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Compilation3 = await Compilations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Compilation3?.setProject) {
|
|
await Compilation3.setProject(relatedProject3);
|
|
}
|
|
}
|
|
|
|
async function associateNotificationWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Notification0 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Notification0?.setUser) {
|
|
await Notification0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Notification1 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Notification1?.setUser) {
|
|
await Notification1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Notification2 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Notification2?.setUser) {
|
|
await Notification2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Notification3 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Notification3?.setUser) {
|
|
await Notification3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Compilations.bulkCreate(CompilationsData);
|
|
|
|
await Notifications.bulkCreate(NotificationsData);
|
|
|
|
await Projects.bulkCreate(ProjectsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateCompilationWithProject(),
|
|
|
|
await associateNotificationWithUser(),
|
|
|
|
await associateProjectWithOwner(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('compilations', null, {});
|
|
|
|
await queryInterface.bulkDelete('notifications', null, {});
|
|
|
|
await queryInterface.bulkDelete('projects', null, {});
|
|
},
|
|
};
|