39178-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-03-13 16:23:30 +00:00

2105 lines
41 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 CourseCategories = db.course_categories;
const CourseCategoryLinks = db.course_category_links;
const Announcements = db.announcements;
const CoursesData = [
{
"title": "Modern JavaScript Foundations",
"slug": "modern-javascript-foundations",
"subtitle": "Core language skills for real projects",
"description": "Learn JavaScript fundamentals with practical examples and small exercises.",
// type code here for "images" field
"status": "archived",
"level": "Beginner",
"language": "English",
// type code here for "relation_one" field
"published_at": new Date('2026-02-20T10:00:00Z'),
"archived_at": new Date('2026-12-31T00:00:00Z'),
"estimated_duration_minutes": 240,
"is_featured": true,
},
{
"title": "SQL for Analytics",
"slug": "sql-for-analytics",
"subtitle": "Query, join, and summarize confidently",
"description": "Build strong SQL skills for analysis, dashboards, and reporting workflows.",
// type code here for "images" field
"status": "draft",
"level": "Beginner",
"language": "English",
// type code here for "relation_one" field
"published_at": new Date('2026-02-22T10:00:00Z'),
"archived_at": new Date('2026-12-31T00:00:00Z'),
"estimated_duration_minutes": 300,
"is_featured": true,
},
{
"title": "UX Writing Essentials",
"slug": "ux-writing-essentials",
"subtitle": "Clear microcopy for better products",
"description": "Write product copy that is concise, inclusive, and action-oriented.",
// type code here for "images" field
"status": "published",
"level": "Intermediate",
"language": "English",
// type code here for "relation_one" field
"published_at": new Date('2026-02-25T10:00:00Z'),
"archived_at": new Date('2026-12-31T00:00:00Z'),
"estimated_duration_minutes": 180,
"is_featured": true,
},
];
const LessonsData = [
{
// type code here for "relation_one" field
"title": "Variables and Types",
"slug": "variables-and-types",
"content": "Understand let, const, and basic types with simple examples.",
// type code here for "files" field
"video_url": "https://videos.lmsdemo.com/js-foundations/lesson-1",
"order_index": 1,
"status": "draft",
"is_free_preview": true,
"estimated_duration_minutes": 20,
"published_at": new Date('2026-02-20T10:30:00Z'),
},
{
// type code here for "relation_one" field
"title": "Functions and Scope",
"slug": "functions-and-scope",
"content": "Learn function declarations, expressions, and how scope works.",
// type code here for "files" field
"video_url": "https://videos.lmsdemo.com/js-foundations/lesson-2",
"order_index": 2,
"status": "published",
"is_free_preview": false,
"estimated_duration_minutes": 25,
"published_at": new Date('2026-02-20T11:00:00Z'),
},
{
// type code here for "relation_one" field
"title": "SELECT and WHERE",
"slug": "select-and-where",
"content": "Write your first queries using SELECT, WHERE, and basic filtering.",
// type code here for "files" field
"video_url": "https://videos.lmsdemo.com/sql-analytics/lesson-1",
"order_index": 1,
"status": "published",
"is_free_preview": true,
"estimated_duration_minutes": 25,
"published_at": new Date('2026-02-22T10:30:00Z'),
},
];
const EnrollmentsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "active",
"enrolled_at": new Date('2026-03-01T09:00:00Z'),
"completed_at": new Date('2026-12-31T00:00:00Z'),
"progress_percent": 40.0,
"last_accessed_at": new Date('2026-03-12T18:35:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "completed",
"enrolled_at": new Date('2026-03-02T09:00:00Z'),
"completed_at": new Date('2026-12-31T00:00:00Z'),
"progress_percent": 20.0,
"last_accessed_at": new Date('2026-03-12T18:10:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "active",
"enrolled_at": new Date('2026-03-03T09:00:00Z'),
"completed_at": new Date('2026-12-31T00:00:00Z'),
"progress_percent": 55.0,
"last_accessed_at": new Date('2026-03-12T08:10:00Z'),
},
];
const LessonProgressData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "in_progress",
"progress_percent": 100,
"started_at": new Date('2026-03-01T09:10:00Z'),
"completed_at": new Date('2026-03-01T09:35:00Z'),
"last_viewed_at": new Date('2026-03-01T09:35:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "completed",
"progress_percent": 40,
"started_at": new Date('2026-03-10T09:00:00Z'),
"completed_at": new Date('2026-12-31T00:00:00Z'),
"last_viewed_at": new Date('2026-03-12T18:35:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "completed",
"progress_percent": 100,
"started_at": new Date('2026-03-03T09:20:00Z'),
"completed_at": new Date('2026-03-03T09:50:00Z'),
"last_viewed_at": new Date('2026-03-03T09:50:00Z'),
},
];
const CourseCategoriesData = [
{
"name": "Web Development",
"slug": "web-development",
"description": "Frontend and backend development topics.",
// type code here for "relation_one" field
},
{
"name": "Data",
"slug": "data",
"description": "Analytics, SQL, and data literacy.",
// type code here for "relation_one" field
},
{
"name": "Product",
"slug": "product",
"description": "Product management and UX disciplines.",
// type code here for "relation_one" field
},
];
const CourseCategoryLinksData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const AnnouncementsData = [
{
// type code here for "relation_one" field
"title": "Welcome to Modern JavaScript Foundations",
"message": "Start with the first lesson and try the exercises after each section.",
"visibility": "public",
"posted_at": new Date('2026-03-01T10:00:00Z'),
},
{
// type code here for "relation_one" field
"title": "Getting set up for SQL practice",
"message": "Use any Postgres sandbox or local instance to follow along with the examples.",
"visibility": "enrolled_only",
"posted_at": new Date('2026-03-03T10:00:00Z'),
},
{
// type code here for "relation_one" field
"title": "How to get the most from this course",
"message": "Take notes on the problem statement for each module and reflect on tradeoffs.",
"visibility": "enrolled_only",
"posted_at": new Date('2026-03-02T12:00:00Z'),
},
];
// 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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
async function associateCourseCategoryWithParent_category() {
const relatedParent_category0 = await CourseCategories.findOne({
offset: Math.floor(Math.random() * (await CourseCategories.count())),
});
const CourseCategory0 = await CourseCategories.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (CourseCategory0?.setParent_category)
{
await
CourseCategory0.
setParent_category(relatedParent_category0);
}
const relatedParent_category1 = await CourseCategories.findOne({
offset: Math.floor(Math.random() * (await CourseCategories.count())),
});
const CourseCategory1 = await CourseCategories.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (CourseCategory1?.setParent_category)
{
await
CourseCategory1.
setParent_category(relatedParent_category1);
}
const relatedParent_category2 = await CourseCategories.findOne({
offset: Math.floor(Math.random() * (await CourseCategories.count())),
});
const CourseCategory2 = await CourseCategories.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (CourseCategory2?.setParent_category)
{
await
CourseCategory2.
setParent_category(relatedParent_category2);
}
}
async function associateCourseCategoryLinkWithCourse() {
const relatedCourse0 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const CourseCategoryLink0 = await CourseCategoryLinks.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (CourseCategoryLink0?.setCourse)
{
await
CourseCategoryLink0.
setCourse(relatedCourse0);
}
const relatedCourse1 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const CourseCategoryLink1 = await CourseCategoryLinks.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (CourseCategoryLink1?.setCourse)
{
await
CourseCategoryLink1.
setCourse(relatedCourse1);
}
const relatedCourse2 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const CourseCategoryLink2 = await CourseCategoryLinks.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (CourseCategoryLink2?.setCourse)
{
await
CourseCategoryLink2.
setCourse(relatedCourse2);
}
}
async function associateCourseCategoryLinkWithCategory() {
const relatedCategory0 = await CourseCategories.findOne({
offset: Math.floor(Math.random() * (await CourseCategories.count())),
});
const CourseCategoryLink0 = await CourseCategoryLinks.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (CourseCategoryLink0?.setCategory)
{
await
CourseCategoryLink0.
setCategory(relatedCategory0);
}
const relatedCategory1 = await CourseCategories.findOne({
offset: Math.floor(Math.random() * (await CourseCategories.count())),
});
const CourseCategoryLink1 = await CourseCategoryLinks.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (CourseCategoryLink1?.setCategory)
{
await
CourseCategoryLink1.
setCategory(relatedCategory1);
}
const relatedCategory2 = await CourseCategories.findOne({
offset: Math.floor(Math.random() * (await CourseCategories.count())),
});
const CourseCategoryLink2 = await CourseCategoryLinks.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (CourseCategoryLink2?.setCategory)
{
await
CourseCategoryLink2.
setCategory(relatedCategory2);
}
}
async function associateAnnouncementWithCourse() {
const relatedCourse0 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Announcement0 = await Announcements.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Announcement0?.setCourse)
{
await
Announcement0.
setCourse(relatedCourse0);
}
const relatedCourse1 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Announcement1 = await Announcements.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Announcement1?.setCourse)
{
await
Announcement1.
setCourse(relatedCourse1);
}
const relatedCourse2 = await Courses.findOne({
offset: Math.floor(Math.random() * (await Courses.count())),
});
const Announcement2 = await Announcements.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Announcement2?.setCourse)
{
await
Announcement2.
setCourse(relatedCourse2);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Courses.bulkCreate(CoursesData);
await Lessons.bulkCreate(LessonsData);
await Enrollments.bulkCreate(EnrollmentsData);
await LessonProgress.bulkCreate(LessonProgressData);
await CourseCategories.bulkCreate(CourseCategoriesData);
await CourseCategoryLinks.bulkCreate(CourseCategoryLinksData);
await Announcements.bulkCreate(AnnouncementsData);
await Promise.all([
// Similar logic for "relation_many"
await associateCoursWithInstructor(),
await associateLessonWithCourse(),
await associateEnrollmentWithStudent(),
await associateEnrollmentWithCourse(),
await associateLessonProgresWithEnrollment(),
await associateLessonProgresWithLesson(),
await associateCourseCategoryWithParent_category(),
await associateCourseCategoryLinkWithCourse(),
await associateCourseCategoryLinkWithCategory(),
await associateAnnouncementWithCourse(),
]);
},
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, {});
await queryInterface.bulkDelete('course_categories', null, {});
await queryInterface.bulkDelete('course_category_links', null, {});
await queryInterface.bulkDelete('announcements', null, {});
},
};