39092-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-03-10 14:29:12 +00:00

2296 lines
43 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Courses = db.courses;
const Lessons = db.lessons;
const Enrollments = db.enrollments;
const LessonProgress = db.lesson_progress;
const CoursesData = [
{
"title": "Modern React Foundations",
"slug": "modern-react-foundations",
"summary": "Learn React fundamentals through hands-on components, state, and routing exercises.",
// type code here for "images" field
"status": "draft",
"level": "beginner",
"category": "Web Development",
"language": "English",
"price": 49.0,
"is_free": false,
"estimated_duration_minutes": 360,
"published_at": new Date('2026-02-20T10:00:00Z'),
// type code here for "relation_one" field
},
{
"title": "SQL for Analytics",
"slug": "sql-for-analytics",
"summary": "Master core SQL for analysis including joins, aggregation, and window functions.",
// type code here for "images" field
"status": "archived",
"level": "intermediate",
"category": "Data",
"language": "English",
"price": 39.0,
"is_free": true,
"estimated_duration_minutes": 300,
"published_at": new Date('2026-02-18T10:00:00Z'),
// type code here for "relation_one" field
},
{
"title": "TypeScript Essentials",
"slug": "typescript-essentials",
"summary": "Build confidence with TypeScript types, interfaces, and real-world patterns.",
// type code here for "images" field
"status": "draft",
"level": "intermediate",
"category": "Programming",
"language": "English",
"price": 0.0,
"is_free": true,
"estimated_duration_minutes": 240,
"published_at": new Date('2026-03-01T10:00:00Z'),
// type code here for "relation_one" field
},
{
"title": "Dashboard Design Basics",
"slug": "dashboard-design-basics",
"summary": "Learn to design clear dashboards with metrics, layout, and storytelling techniques.",
// type code here for "images" field
"status": "draft",
"level": "beginner",
"category": "Data Visualization",
"language": "English",
"price": 29.0,
"is_free": false,
"estimated_duration_minutes": 180,
"published_at": new Date('2026-02-25T10:00:00Z'),
// type code here for "relation_one" field
},
{
"title": "Web Accessibility Fundamentals",
"slug": "web-accessibility-fundamentals",
"summary": "Make web experiences inclusive with semantic HTML, ARIA basics, and testing tips.",
// type code here for "images" field
"status": "published",
"level": "beginner",
"category": "Web Development",
"language": "English",
"price": 0.0,
"is_free": true,
"estimated_duration_minutes": 150,
"published_at": new Date('2025-12-10T10:00:00Z'),
// type code here for "relation_one" field
},
];
const LessonsData = [
{
// type code here for "relation_one" field
"title": "React Project Setup and Tooling",
"content": "Set up a React project, understand folders, and run the dev server with confidence.",
"lesson_type": "text",
"video_url": "https://example.com/videos/react-setup",
// type code here for "files" field
"sort_order": 1,
"is_preview": true,
"status": "draft",
"estimated_duration_minutes": 30,
"published_at": new Date('2026-02-20T12:00:00Z'),
},
{
// type code here for "relation_one" field
"title": "Components and Props",
"content": "Create reusable components and pass data through props using clear patterns.",
"lesson_type": "assignment",
"video_url": "https://example.com/videos/components-props",
// type code here for "files" field
"sort_order": 2,
"is_preview": false,
"status": "archived",
"estimated_duration_minutes": 45,
"published_at": new Date('2026-02-21T12:00:00Z'),
},
{
// type code here for "relation_one" field
"title": "State and Effects",
"content": "Manage state and side effects with hooks and learn common pitfalls to avoid.",
"lesson_type": "quiz",
"video_url": "https://example.com/videos/state-effects",
// type code here for "files" field
"sort_order": 3,
"is_preview": true,
"status": "archived",
"estimated_duration_minutes": 55,
"published_at": new Date('2026-02-22T12:00:00Z'),
},
{
// type code here for "relation_one" field
"title": "Selecting and Filtering Data",
"content": "Write SELECT queries with WHERE clauses, sorting, and basic string and date filters.",
"lesson_type": "quiz",
"video_url": "https://example.com/videos/sql-select",
// type code here for "files" field
"sort_order": 1,
"is_preview": true,
"status": "draft",
"estimated_duration_minutes": 35,
"published_at": new Date('2026-02-18T12:00:00Z'),
},
{
// type code here for "relation_one" field
"title": "Joins and Aggregations",
"content": "Combine tables using joins and summarize results with GROUP BY and HAVING.",
"lesson_type": "video",
"video_url": "https://example.com/videos/sql-joins",
// type code here for "files" field
"sort_order": 2,
"is_preview": true,
"status": "archived",
"estimated_duration_minutes": 50,
"published_at": new Date('2026-02-19T12:00:00Z'),
},
];
const EnrollmentsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "cancelled",
"enrolled_at": new Date('2026-03-01T09:00:00Z'),
"completed_at": new Date('2026-04-01T09:00:00Z'),
"progress_percent": 66.7,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "completed",
"enrolled_at": new Date('2026-03-02T10:30:00Z'),
"completed_at": new Date('2026-04-10T10:30:00Z'),
"progress_percent": 50.0,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "completed",
"enrolled_at": new Date('2026-03-05T14:00:00Z'),
"completed_at": new Date('2026-04-20T14:00:00Z'),
"progress_percent": 20.0,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "completed",
"enrolled_at": new Date('2026-02-10T11:00:00Z'),
"completed_at": new Date('2026-02-28T18:00:00Z'),
"progress_percent": 100.0,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "cancelled",
"enrolled_at": new Date('2026-01-15T08:45:00Z'),
"completed_at": new Date('2026-01-20T08:45:00Z'),
"progress_percent": 0.0,
},
];
const LessonProgressData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "completed",
"time_spent_seconds": 1800,
"started_at": new Date('2026-03-01T09:10:00Z'),
"completed_at": new Date('2026-03-01T09:40:00Z'),
"last_viewed_at": new Date('2026-03-01T09:40:00Z'),
"score": 100.0,
"attempts_count": 1,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "in_progress",
"time_spent_seconds": 2700,
"started_at": new Date('2026-03-02T18:00:00Z'),
"completed_at": new Date('2026-03-02T18:45:00Z'),
"last_viewed_at": new Date('2026-03-02T18:45:00Z'),
"score": 98.0,
"attempts_count": 1,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "in_progress",
"time_spent_seconds": 1200,
"started_at": new Date('2026-03-04T19:00:00Z'),
"completed_at": new Date('2026-04-01T09:00:00Z'),
"last_viewed_at": new Date('2026-03-04T19:20:00Z'),
"score": 0.0,
"attempts_count": 0,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "completed",
"time_spent_seconds": 2100,
"started_at": new Date('2026-03-02T10:45:00Z'),
"completed_at": new Date('2026-03-02T11:20:00Z'),
"last_viewed_at": new Date('2026-03-02T11:20:00Z'),
"score": 100.0,
"attempts_count": 1,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "not_started",
"time_spent_seconds": 900,
"started_at": new Date('2026-03-06T12:00:00Z'),
"completed_at": new Date('2026-04-10T10:30:00Z'),
"last_viewed_at": new Date('2026-03-06T12:15:00Z'),
"score": 70.0,
"attempts_count": 1,
},
];
// Similar logic for "relation_many"
async function associateCoursWithInstructor() {
const relatedInstructor0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Cours0 = await Courses.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Cours0?.setInstructor)
{
await
Cours0.
setInstructor(relatedInstructor0);
}
const relatedInstructor1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Cours1 = await Courses.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Cours1?.setInstructor)
{
await
Cours1.
setInstructor(relatedInstructor1);
}
const relatedInstructor2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Cours2 = await Courses.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Cours2?.setInstructor)
{
await
Cours2.
setInstructor(relatedInstructor2);
}
const relatedInstructor3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Cours3 = await Courses.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Cours3?.setInstructor)
{
await
Cours3.
setInstructor(relatedInstructor3);
}
const relatedInstructor4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Cours4 = await Courses.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Cours4?.setInstructor)
{
await
Cours4.
setInstructor(relatedInstructor4);
}
}
async function associateLessonWithCourse() {
const relatedCourse0 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Lesson0 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Lesson0?.setCourse)
{
await
Lesson0.
setCourse(relatedCourse0);
}
const relatedCourse1 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Lesson1 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Lesson1?.setCourse)
{
await
Lesson1.
setCourse(relatedCourse1);
}
const relatedCourse2 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Lesson2 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Lesson2?.setCourse)
{
await
Lesson2.
setCourse(relatedCourse2);
}
const relatedCourse3 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Lesson3 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Lesson3?.setCourse)
{
await
Lesson3.
setCourse(relatedCourse3);
}
const relatedCourse4 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Lesson4 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Lesson4?.setCourse)
{
await
Lesson4.
setCourse(relatedCourse4);
}
}
async function associateEnrollmentWithStudent() {
const relatedStudent0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Enrollment0 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Enrollment0?.setStudent)
{
await
Enrollment0.
setStudent(relatedStudent0);
}
const relatedStudent1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Enrollment1 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Enrollment1?.setStudent)
{
await
Enrollment1.
setStudent(relatedStudent1);
}
const relatedStudent2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Enrollment2 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Enrollment2?.setStudent)
{
await
Enrollment2.
setStudent(relatedStudent2);
}
const relatedStudent3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Enrollment3 = await Enrollments.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Enrollment3?.setStudent)
{
await
Enrollment3.
setStudent(relatedStudent3);
}
const relatedStudent4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.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 associateLessonProgresWithEnrollment() {
const relatedEnrollment0 = await Enrollments.findOne({
offset: Math.floor(Math.random() * (await Enrollments.count())),
});
const LessonProgres0 = await LessonProgress.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (LessonProgres0?.setEnrollment)
{
await
LessonProgres0.
setEnrollment(relatedEnrollment0);
}
const relatedEnrollment1 = await Enrollments.findOne({
offset: Math.floor(Math.random() * (await Enrollments.count())),
});
const LessonProgres1 = await LessonProgress.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (LessonProgres1?.setEnrollment)
{
await
LessonProgres1.
setEnrollment(relatedEnrollment1);
}
const relatedEnrollment2 = await Enrollments.findOne({
offset: Math.floor(Math.random() * (await Enrollments.count())),
});
const LessonProgres2 = await LessonProgress.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (LessonProgres2?.setEnrollment)
{
await
LessonProgres2.
setEnrollment(relatedEnrollment2);
}
const relatedEnrollment3 = await Enrollments.findOne({
offset: Math.floor(Math.random() * (await Enrollments.count())),
});
const LessonProgres3 = await LessonProgress.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (LessonProgres3?.setEnrollment)
{
await
LessonProgres3.
setEnrollment(relatedEnrollment3);
}
const relatedEnrollment4 = await Enrollments.findOne({
offset: Math.floor(Math.random() * (await Enrollments.count())),
});
const LessonProgres4 = await LessonProgress.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (LessonProgres4?.setEnrollment)
{
await
LessonProgres4.
setEnrollment(relatedEnrollment4);
}
}
async function associateLessonProgresWithLesson() {
const relatedLesson0 = await Lessons.findOne({
offset: Math.floor(Math.random() * (await Lessons.count())),
});
const LessonProgres0 = await LessonProgress.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (LessonProgres0?.setLesson)
{
await
LessonProgres0.
setLesson(relatedLesson0);
}
const relatedLesson1 = await Lessons.findOne({
offset: Math.floor(Math.random() * (await Lessons.count())),
});
const LessonProgres1 = await LessonProgress.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (LessonProgres1?.setLesson)
{
await
LessonProgres1.
setLesson(relatedLesson1);
}
const relatedLesson2 = await Lessons.findOne({
offset: Math.floor(Math.random() * (await Lessons.count())),
});
const LessonProgres2 = await LessonProgress.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (LessonProgres2?.setLesson)
{
await
LessonProgres2.
setLesson(relatedLesson2);
}
const relatedLesson3 = await Lessons.findOne({
offset: Math.floor(Math.random() * (await Lessons.count())),
});
const LessonProgres3 = await LessonProgress.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (LessonProgres3?.setLesson)
{
await
LessonProgres3.
setLesson(relatedLesson3);
}
const relatedLesson4 = await Lessons.findOne({
offset: Math.floor(Math.random() * (await Lessons.count())),
});
const LessonProgres4 = await LessonProgress.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (LessonProgres4?.setLesson)
{
await
LessonProgres4.
setLesson(relatedLesson4);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Courses.bulkCreate(CoursesData);
await Lessons.bulkCreate(LessonsData);
await Enrollments.bulkCreate(EnrollmentsData);
await LessonProgress.bulkCreate(LessonProgressData);
await Promise.all([
// Similar logic for "relation_many"
await associateCoursWithInstructor(),
await associateLessonWithCourse(),
await associateEnrollmentWithStudent(),
await associateEnrollmentWithCourse(),
await associateLessonProgresWithEnrollment(),
await associateLessonProgresWithLesson(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('courses', null, {});
await queryInterface.bulkDelete('lessons', null, {});
await queryInterface.bulkDelete('enrollments', null, {});
await queryInterface.bulkDelete('lesson_progress', null, {});
},
};