30208/backend/src/db/seeders/20231127130745-sample-data.js
2025-03-26 17:31:27 +00:00

939 lines
22 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 Posts = db.posts;
const Students = db.students;
const AnalyticsData = [
{
// type code here for "relation_one" field
student_engagement: 75,
completion_rate: 80,
instructor_performance: 85,
},
{
// type code here for "relation_one" field
student_engagement: 65,
completion_rate: 70,
instructor_performance: 75,
},
{
// type code here for "relation_one" field
student_engagement: 85,
completion_rate: 90,
instructor_performance: 95,
},
{
// type code here for "relation_one" field
student_engagement: 55,
completion_rate: 60,
instructor_performance: 65,
},
{
// type code here for "relation_one" field
student_engagement: 95,
completion_rate: 100,
instructor_performance: 90,
},
];
const CoursesData = [
{
title: 'Introduction to Python',
description: 'Learn the basics of Python programming.',
// type code here for "relation_one" field
start_date: new Date('2023-01-10T09:00:00Z'),
end_date: new Date('2023-03-10T17:00:00Z'),
status: 'draft',
},
{
title: 'Advanced JavaScript',
description: 'Deep dive into JavaScript and its frameworks.',
// type code here for "relation_one" field
start_date: new Date('2023-02-15T09:00:00Z'),
end_date: new Date('2023-04-15T17:00:00Z'),
status: 'archived',
},
{
title: 'Data Science with R',
description: 'Explore data analysis and visualization using R.',
// type code here for "relation_one" field
start_date: new Date('2023-03-01T09:00:00Z'),
end_date: new Date('2023-05-01T17:00:00Z'),
status: 'published',
},
{
title: 'Web Development Bootcamp',
description: 'Full-stack web development course.',
// type code here for "relation_one" field
start_date: new Date('2023-04-01T09:00:00Z'),
end_date: new Date('2023-06-01T17:00:00Z'),
status: 'archived',
},
{
title: 'Machine Learning Basics',
description: 'Introduction to machine learning concepts.',
// type code here for "relation_one" field
start_date: new Date('2023-05-01T09:00:00Z'),
end_date: new Date('2023-07-01T17:00:00Z'),
status: 'published',
},
];
const DiscussionBoardsData = [
{
// type code here for "relation_one" field
topic: 'Python Basics Discussion',
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
topic: 'JavaScript Frameworks',
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
topic: 'Data Visualization Techniques',
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
topic: 'Web Development Tools',
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
topic: 'Machine Learning Algorithms',
// 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: 'failed',
grade: 85.5,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
payment_status: 'completed',
grade: 77.02,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
payment_status: 'completed',
grade: 90,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
payment_status: 'pending',
grade: 85.92,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
payment_status: 'failed',
grade: 88,
},
];
const InstructorsData = [
{
// type code here for "relation_one" field
qualifications: 'PhD in Computer Science',
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
qualifications: 'MSc in Data Science',
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
qualifications: 'BSc in Software Engineering',
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
qualifications: 'MSc in Information Technology',
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
qualifications: 'PhD in Artificial Intelligence',
// type code here for "relation_many" field
},
];
const PostsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
content: 'I found the Python loops section very helpful.',
posted_at: new Date('2023-01-15T10:00:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
content: 'Can someone explain list comprehensions?',
posted_at: new Date('2023-01-16T11:00:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
content: 'React is my favorite framework.',
posted_at: new Date('2023-02-20T12:00:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
content: 'I prefer Vue.js for its simplicity.',
posted_at: new Date('2023-02-21T13:00:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
content: 'R has great libraries for data visualization.',
posted_at: new Date('2023-03-05T14:00:00Z'),
},
];
const StudentsData = [
{
// type code here for "relation_one" field
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
// type code here for "relation_many" field
},
];
// Similar logic for "relation_many"
async function associateAnalyticWithCourse() {
const relatedCourse0 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Analytic0 = await Analytics.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Analytic0?.setCourse) {
await Analytic0.setCourse(relatedCourse0);
}
const relatedCourse1 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Analytic1 = await Analytics.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Analytic1?.setCourse) {
await Analytic1.setCourse(relatedCourse1);
}
const relatedCourse2 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Analytic2 = await Analytics.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Analytic2?.setCourse) {
await Analytic2.setCourse(relatedCourse2);
}
const relatedCourse3 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Analytic3 = await Analytics.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Analytic3?.setCourse) {
await Analytic3.setCourse(relatedCourse3);
}
const relatedCourse4 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Analytic4 = await Analytics.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Analytic4?.setCourse) {
await Analytic4.setCourse(relatedCourse4);
}
}
async function associateCourseWithInstructor() {
const relatedInstructor0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Course0 = await Courses.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Course0?.setInstructor) {
await Course0.setInstructor(relatedInstructor0);
}
const relatedInstructor1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Course1 = await Courses.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Course1?.setInstructor) {
await Course1.setInstructor(relatedInstructor1);
}
const relatedInstructor2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Course2 = await Courses.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Course2?.setInstructor) {
await Course2.setInstructor(relatedInstructor2);
}
const relatedInstructor3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Course3 = await Courses.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Course3?.setInstructor) {
await Course3.setInstructor(relatedInstructor3);
}
const relatedInstructor4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Course4 = await Courses.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Course4?.setInstructor) {
await Course4.setInstructor(relatedInstructor4);
}
}
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 associatePostWithDiscussion_board() {
const relatedDiscussion_board0 = await DiscussionBoards.findOne({
offset: Math.floor(Math.random() * (await DiscussionBoards.count())),
});
const Post0 = await Posts.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Post0?.setDiscussion_board) {
await Post0.setDiscussion_board(relatedDiscussion_board0);
}
const relatedDiscussion_board1 = await DiscussionBoards.findOne({
offset: Math.floor(Math.random() * (await DiscussionBoards.count())),
});
const Post1 = await Posts.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Post1?.setDiscussion_board) {
await Post1.setDiscussion_board(relatedDiscussion_board1);
}
const relatedDiscussion_board2 = await DiscussionBoards.findOne({
offset: Math.floor(Math.random() * (await DiscussionBoards.count())),
});
const Post2 = await Posts.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Post2?.setDiscussion_board) {
await Post2.setDiscussion_board(relatedDiscussion_board2);
}
const relatedDiscussion_board3 = await DiscussionBoards.findOne({
offset: Math.floor(Math.random() * (await DiscussionBoards.count())),
});
const Post3 = await Posts.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Post3?.setDiscussion_board) {
await Post3.setDiscussion_board(relatedDiscussion_board3);
}
const relatedDiscussion_board4 = await DiscussionBoards.findOne({
offset: Math.floor(Math.random() * (await DiscussionBoards.count())),
});
const Post4 = await Posts.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Post4?.setDiscussion_board) {
await Post4.setDiscussion_board(relatedDiscussion_board4);
}
}
async function associatePostWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Post0 = await Posts.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Post0?.setUser) {
await Post0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Post1 = await Posts.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Post1?.setUser) {
await Post1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Post2 = await Posts.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Post2?.setUser) {
await Post2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Post3 = await Posts.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Post3?.setUser) {
await Post3.setUser(relatedUser3);
}
const relatedUser4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Post4 = await Posts.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Post4?.setUser) {
await Post4.setUser(relatedUser4);
}
}
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"
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 Posts.bulkCreate(PostsData);
await Students.bulkCreate(StudentsData);
await Promise.all([
// Similar logic for "relation_many"
await associateAnalyticWithCourse(),
await associateCourseWithInstructor(),
await associateDiscussionBoardWithCourse(),
// Similar logic for "relation_many"
await associateEnrollmentWithStudent(),
await associateEnrollmentWithCourse(),
await associateInstructorWithUser(),
// Similar logic for "relation_many"
await associatePostWithDiscussion_board(),
await associatePostWithUser(),
await associateStudentWithUser(),
// Similar logic for "relation_many"
]);
},
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('posts', null, {});
await queryInterface.bulkDelete('students', null, {});
},
};