30412/backend/src/db/seeders/20231127130745-sample-data.js
Flatlogic Bot 0296244a80 ver #2
2025-04-02 10:04:26 +00:00

853 lines
18 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Analytics = db.analytics;
const Courses = db.courses;
const DiscussionBoards = db.discussion_boards;
const Enrollments = db.enrollments;
const Instructors = db.instructors;
const Students = db.students;
const Categories = db.categories;
const Tasks = db.tasks;
const AnalyticsData = [
{
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
engagement_rate: 75.5,
completion_rate: 80,
instructor_performance: 85,
},
{
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
engagement_rate: 82,
completion_rate: 78.5,
instructor_performance: 88,
},
{
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
engagement_rate: 79,
completion_rate: 85,
instructor_performance: 90,
},
{
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
engagement_rate: 81.5,
completion_rate: 82,
instructor_performance: 87.5,
},
{
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
engagement_rate: 77,
completion_rate: 79.5,
instructor_performance: 86,
},
];
const CoursesData = [
{
title: 'Introduction to Programming',
description: 'Learn the basics of programming using Python.',
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "files" field
// type code here for "relation_many" field
},
{
title: 'Advanced Mathematics',
description: 'Explore advanced mathematical concepts and theories.',
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "files" field
// type code here for "relation_many" field
},
{
title: 'Digital Marketing',
description: 'Master the art of digital marketing strategies.',
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "files" field
// type code here for "relation_many" field
},
{
title: 'Graphic Design Basics',
description: 'Introduction to graphic design principles and tools.',
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "files" field
// type code here for "relation_many" field
},
{
title: 'Data Science Essentials',
description: 'Understand the fundamentals of data science and analytics.',
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "files" field
// type code here for "relation_many" field
},
];
const DiscussionBoardsData = [
{
// type code here for "relation_one" field
topic: 'Introduction to Python',
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
topic: 'Advanced Calculus Discussion',
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
topic: 'SEO Strategies',
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
topic: 'Design Tools Overview',
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
topic: 'Data Analysis Techniques',
// type code here for "relation_many" field
},
];
const EnrollmentsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
payment_status: 'Completed',
enrollment_date: new Date('2023-01-15T10:00:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
payment_status: 'Failed',
enrollment_date: new Date('2023-02-20T11:30:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
payment_status: 'Failed',
enrollment_date: new Date('2023-03-10T09:45:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
payment_status: 'Completed',
enrollment_date: new Date('2023-04-05T14:20:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
payment_status: 'Pending',
enrollment_date: new Date('2023-05-25T16:00:00Z'),
},
];
const InstructorsData = [
{
// type code here for "relation_one" field
qualifications: 'PhD in Computer Science',
// type code here for "relation_many" field
availability: true,
},
{
// type code here for "relation_one" field
qualifications: 'MSc in Mathematics',
// type code here for "relation_many" field
availability: true,
},
{
// type code here for "relation_one" field
qualifications: 'BFA in Graphic Design',
// type code here for "relation_many" field
availability: false,
},
{
// type code here for "relation_one" field
qualifications: 'MBA in Marketing',
// type code here for "relation_many" field
availability: true,
},
{
// type code here for "relation_one" field
qualifications: 'MSc in Data Science',
// type code here for "relation_many" field
availability: false,
},
];
const StudentsData = [
{
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
average_grade: 85.5,
},
{
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
average_grade: 90,
},
{
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
average_grade: 88,
},
{
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
average_grade: 92,
},
{
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
average_grade: 87.5,
},
];
const CategoriesData = [
{
name: 'August Kekule',
},
{
name: 'Sheldon Glashow',
},
{
name: 'Andreas Vesalius',
},
{
name: 'Edward O. Wilson',
},
{
name: 'John Dalton',
},
];
const TasksData = [
{
name: 'Lynn Margulis',
// type code here for "relation_one" field
},
{
name: 'James Clerk Maxwell',
// type code here for "relation_one" field
},
{
name: 'Charles Sherrington',
// type code here for "relation_one" field
},
{
name: 'Gertrude Belle Elion',
// type code here for "relation_one" field
},
{
name: 'Franz Boas',
// type code here for "relation_one" field
},
];
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
async function associateDiscussionBoardWithCourse() {
const relatedCourse0 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const DiscussionBoard0 = await DiscussionBoards.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (DiscussionBoard0?.setCourse) {
await DiscussionBoard0.setCourse(relatedCourse0);
}
const relatedCourse1 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const DiscussionBoard1 = await DiscussionBoards.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (DiscussionBoard1?.setCourse) {
await DiscussionBoard1.setCourse(relatedCourse1);
}
const relatedCourse2 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const DiscussionBoard2 = await DiscussionBoards.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (DiscussionBoard2?.setCourse) {
await DiscussionBoard2.setCourse(relatedCourse2);
}
const relatedCourse3 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const DiscussionBoard3 = await DiscussionBoards.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (DiscussionBoard3?.setCourse) {
await DiscussionBoard3.setCourse(relatedCourse3);
}
const relatedCourse4 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const DiscussionBoard4 = await DiscussionBoards.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (DiscussionBoard4?.setCourse) {
await DiscussionBoard4.setCourse(relatedCourse4);
}
}
// Similar logic for "relation_many"
async function associateEnrollmentWithStudent() {
const relatedStudent0 = await Students.findOne({
offset: Math.floor(Math.random() * (await Students.count())),
});
const Enrollment0 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Enrollment0?.setStudent) {
await Enrollment0.setStudent(relatedStudent0);
}
const relatedStudent1 = await Students.findOne({
offset: Math.floor(Math.random() * (await Students.count())),
});
const Enrollment1 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Enrollment1?.setStudent) {
await Enrollment1.setStudent(relatedStudent1);
}
const relatedStudent2 = await Students.findOne({
offset: Math.floor(Math.random() * (await Students.count())),
});
const Enrollment2 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Enrollment2?.setStudent) {
await Enrollment2.setStudent(relatedStudent2);
}
const relatedStudent3 = await Students.findOne({
offset: Math.floor(Math.random() * (await Students.count())),
});
const Enrollment3 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Enrollment3?.setStudent) {
await Enrollment3.setStudent(relatedStudent3);
}
const relatedStudent4 = await Students.findOne({
offset: Math.floor(Math.random() * (await Students.count())),
});
const Enrollment4 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Enrollment4?.setStudent) {
await Enrollment4.setStudent(relatedStudent4);
}
}
async function associateEnrollmentWithCourse() {
const relatedCourse0 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Enrollment0 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Enrollment0?.setCourse) {
await Enrollment0.setCourse(relatedCourse0);
}
const relatedCourse1 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Enrollment1 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Enrollment1?.setCourse) {
await Enrollment1.setCourse(relatedCourse1);
}
const relatedCourse2 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Enrollment2 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Enrollment2?.setCourse) {
await Enrollment2.setCourse(relatedCourse2);
}
const relatedCourse3 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Enrollment3 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Enrollment3?.setCourse) {
await Enrollment3.setCourse(relatedCourse3);
}
const relatedCourse4 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Enrollment4 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Enrollment4?.setCourse) {
await Enrollment4.setCourse(relatedCourse4);
}
}
async function associateInstructorWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Instructor0 = await Instructors.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Instructor0?.setUser) {
await Instructor0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Instructor1 = await Instructors.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Instructor1?.setUser) {
await Instructor1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Instructor2 = await Instructors.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Instructor2?.setUser) {
await Instructor2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Instructor3 = await Instructors.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Instructor3?.setUser) {
await Instructor3.setUser(relatedUser3);
}
const relatedUser4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Instructor4 = await Instructors.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Instructor4?.setUser) {
await Instructor4.setUser(relatedUser4);
}
}
// Similar logic for "relation_many"
async function associateStudentWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Student0 = await Students.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Student0?.setUser) {
await Student0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Student1 = await Students.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Student1?.setUser) {
await Student1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Student2 = await Students.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Student2?.setUser) {
await Student2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Student3 = await Students.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Student3?.setUser) {
await Student3.setUser(relatedUser3);
}
const relatedUser4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Student4 = await Students.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Student4?.setUser) {
await Student4.setUser(relatedUser4);
}
}
// Similar logic for "relation_many"
// Similar logic for "relation_many"
async function associateTaskWithCategory() {
const relatedCategory0 = await Categories.findOne({
offset: Math.floor(Math.random() * (await Categories.count())),
});
const Task0 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Task0?.setCategory) {
await Task0.setCategory(relatedCategory0);
}
const relatedCategory1 = await Categories.findOne({
offset: Math.floor(Math.random() * (await Categories.count())),
});
const Task1 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Task1?.setCategory) {
await Task1.setCategory(relatedCategory1);
}
const relatedCategory2 = await Categories.findOne({
offset: Math.floor(Math.random() * (await Categories.count())),
});
const Task2 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Task2?.setCategory) {
await Task2.setCategory(relatedCategory2);
}
const relatedCategory3 = await Categories.findOne({
offset: Math.floor(Math.random() * (await Categories.count())),
});
const Task3 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Task3?.setCategory) {
await Task3.setCategory(relatedCategory3);
}
const relatedCategory4 = await Categories.findOne({
offset: Math.floor(Math.random() * (await Categories.count())),
});
const Task4 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Task4?.setCategory) {
await Task4.setCategory(relatedCategory4);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Analytics.bulkCreate(AnalyticsData);
await Courses.bulkCreate(CoursesData);
await DiscussionBoards.bulkCreate(DiscussionBoardsData);
await Enrollments.bulkCreate(EnrollmentsData);
await Instructors.bulkCreate(InstructorsData);
await Students.bulkCreate(StudentsData);
await Categories.bulkCreate(CategoriesData);
await Tasks.bulkCreate(TasksData);
await Promise.all([
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
await associateDiscussionBoardWithCourse(),
// Similar logic for "relation_many"
await associateEnrollmentWithStudent(),
await associateEnrollmentWithCourse(),
await associateInstructorWithUser(),
// Similar logic for "relation_many"
await associateStudentWithUser(),
// Similar logic for "relation_many"
// Similar logic for "relation_many"
await associateTaskWithCategory(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('analytics', null, {});
await queryInterface.bulkDelete('courses', null, {});
await queryInterface.bulkDelete('discussion_boards', null, {});
await queryInterface.bulkDelete('enrollments', null, {});
await queryInterface.bulkDelete('instructors', null, {});
await queryInterface.bulkDelete('students', null, {});
await queryInterface.bulkDelete('categories', null, {});
await queryInterface.bulkDelete('tasks', null, {});
},
};