34073/backend/src/db/seeders/20231127130745-sample-data.js
2025-09-15 15:07:29 +00:00

601 lines
12 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Classes = db.classes;
const Days = db.days;
const Lessons = db.lessons;
const Rooms = db.rooms;
const Subjects = db.subjects;
const Teachers = db.teachers;
const Timetables = db.timetables;
const ClassesData = [
{
class_name: 'Grade 1',
// type code here for "relation_one" field
},
{
class_name: 'Grade 2',
// type code here for "relation_one" field
},
{
class_name: 'Grade 3',
// type code here for "relation_one" field
},
{
class_name: 'Grade 4',
// type code here for "relation_one" field
},
{
class_name: 'Grade 5',
// type code here for "relation_one" field
},
];
const DaysData = [
{
day_name: 'Friday',
},
{
day_name: 'Friday',
},
{
day_name: 'Friday',
},
{
day_name: 'Wednesday',
},
{
day_name: 'Tuesday',
},
];
const LessonsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
times_per_week: 3,
duration: 1,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
times_per_week: 2,
duration: 2,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
times_per_week: 4,
duration: 1,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
times_per_week: 3,
duration: 2,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
times_per_week: 1,
duration: 3,
},
];
const RoomsData = [
{
room_name: 'Room 101',
capacity: 30,
},
{
room_name: 'Room 102',
capacity: 25,
},
{
room_name: 'Room 103',
capacity: 20,
},
{
room_name: 'Room 104',
capacity: 35,
},
{
room_name: 'Room 105',
capacity: 40,
},
];
const SubjectsData = [
{
subject_name: 'Mathematics',
},
{
subject_name: 'Science',
},
{
subject_name: 'History',
},
{
subject_name: 'English',
},
{
subject_name: 'Art',
},
];
const TeachersData = [
{
teacher_name: 'Alice Green',
},
{
teacher_name: 'Bob White',
},
{
teacher_name: 'Charlie Black',
},
{
teacher_name: 'Diana Blue',
},
{
teacher_name: 'Eve Red',
},
];
const TimetablesData = [
{
name: 'Spring Semester 2024',
periods_per_day: 6,
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
},
{
name: 'Fall Semester 2023',
periods_per_day: 5,
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
},
{
name: 'Summer School 2023',
periods_per_day: 4,
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
},
{
name: 'Winter Term 2023',
periods_per_day: 3,
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
},
{
name: 'Autumn Term 2023',
periods_per_day: 7,
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
},
];
// Similar logic for "relation_many"
async function associateClassWithClass_teacher() {
const relatedClass_teacher0 = await Teachers.findOne({
offset: Math.floor(Math.random() * (await Teachers.count())),
});
const Class0 = await Classes.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Class0?.setClass_teacher) {
await Class0.setClass_teacher(relatedClass_teacher0);
}
const relatedClass_teacher1 = await Teachers.findOne({
offset: Math.floor(Math.random() * (await Teachers.count())),
});
const Class1 = await Classes.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Class1?.setClass_teacher) {
await Class1.setClass_teacher(relatedClass_teacher1);
}
const relatedClass_teacher2 = await Teachers.findOne({
offset: Math.floor(Math.random() * (await Teachers.count())),
});
const Class2 = await Classes.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Class2?.setClass_teacher) {
await Class2.setClass_teacher(relatedClass_teacher2);
}
const relatedClass_teacher3 = await Teachers.findOne({
offset: Math.floor(Math.random() * (await Teachers.count())),
});
const Class3 = await Classes.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Class3?.setClass_teacher) {
await Class3.setClass_teacher(relatedClass_teacher3);
}
const relatedClass_teacher4 = await Teachers.findOne({
offset: Math.floor(Math.random() * (await Teachers.count())),
});
const Class4 = await Classes.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Class4?.setClass_teacher) {
await Class4.setClass_teacher(relatedClass_teacher4);
}
}
async function associateLessonWithSubject() {
const relatedSubject0 = await Subjects.findOne({
offset: Math.floor(Math.random() * (await Subjects.count())),
});
const Lesson0 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Lesson0?.setSubject) {
await Lesson0.setSubject(relatedSubject0);
}
const relatedSubject1 = await Subjects.findOne({
offset: Math.floor(Math.random() * (await Subjects.count())),
});
const Lesson1 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Lesson1?.setSubject) {
await Lesson1.setSubject(relatedSubject1);
}
const relatedSubject2 = await Subjects.findOne({
offset: Math.floor(Math.random() * (await Subjects.count())),
});
const Lesson2 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Lesson2?.setSubject) {
await Lesson2.setSubject(relatedSubject2);
}
const relatedSubject3 = await Subjects.findOne({
offset: Math.floor(Math.random() * (await Subjects.count())),
});
const Lesson3 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Lesson3?.setSubject) {
await Lesson3.setSubject(relatedSubject3);
}
const relatedSubject4 = await Subjects.findOne({
offset: Math.floor(Math.random() * (await Subjects.count())),
});
const Lesson4 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Lesson4?.setSubject) {
await Lesson4.setSubject(relatedSubject4);
}
}
async function associateLessonWithTeacher() {
const relatedTeacher0 = await Teachers.findOne({
offset: Math.floor(Math.random() * (await Teachers.count())),
});
const Lesson0 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Lesson0?.setTeacher) {
await Lesson0.setTeacher(relatedTeacher0);
}
const relatedTeacher1 = await Teachers.findOne({
offset: Math.floor(Math.random() * (await Teachers.count())),
});
const Lesson1 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Lesson1?.setTeacher) {
await Lesson1.setTeacher(relatedTeacher1);
}
const relatedTeacher2 = await Teachers.findOne({
offset: Math.floor(Math.random() * (await Teachers.count())),
});
const Lesson2 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Lesson2?.setTeacher) {
await Lesson2.setTeacher(relatedTeacher2);
}
const relatedTeacher3 = await Teachers.findOne({
offset: Math.floor(Math.random() * (await Teachers.count())),
});
const Lesson3 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Lesson3?.setTeacher) {
await Lesson3.setTeacher(relatedTeacher3);
}
const relatedTeacher4 = await Teachers.findOne({
offset: Math.floor(Math.random() * (await Teachers.count())),
});
const Lesson4 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Lesson4?.setTeacher) {
await Lesson4.setTeacher(relatedTeacher4);
}
}
async function associateLessonWithRoom() {
const relatedRoom0 = await Rooms.findOne({
offset: Math.floor(Math.random() * (await Rooms.count())),
});
const Lesson0 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Lesson0?.setRoom) {
await Lesson0.setRoom(relatedRoom0);
}
const relatedRoom1 = await Rooms.findOne({
offset: Math.floor(Math.random() * (await Rooms.count())),
});
const Lesson1 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Lesson1?.setRoom) {
await Lesson1.setRoom(relatedRoom1);
}
const relatedRoom2 = await Rooms.findOne({
offset: Math.floor(Math.random() * (await Rooms.count())),
});
const Lesson2 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Lesson2?.setRoom) {
await Lesson2.setRoom(relatedRoom2);
}
const relatedRoom3 = await Rooms.findOne({
offset: Math.floor(Math.random() * (await Rooms.count())),
});
const Lesson3 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Lesson3?.setRoom) {
await Lesson3.setRoom(relatedRoom3);
}
const relatedRoom4 = await Rooms.findOne({
offset: Math.floor(Math.random() * (await Rooms.count())),
});
const Lesson4 = await Lessons.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Lesson4?.setRoom) {
await Lesson4.setRoom(relatedRoom4);
}
}
// 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"
module.exports = {
up: async (queryInterface, Sequelize) => {
await Classes.bulkCreate(ClassesData);
await Days.bulkCreate(DaysData);
await Lessons.bulkCreate(LessonsData);
await Rooms.bulkCreate(RoomsData);
await Subjects.bulkCreate(SubjectsData);
await Teachers.bulkCreate(TeachersData);
await Timetables.bulkCreate(TimetablesData);
await Promise.all([
// Similar logic for "relation_many"
await associateClassWithClass_teacher(),
await associateLessonWithSubject(),
await associateLessonWithTeacher(),
await associateLessonWithRoom(),
// 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"
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('classes', null, {});
await queryInterface.bulkDelete('days', null, {});
await queryInterface.bulkDelete('lessons', null, {});
await queryInterface.bulkDelete('rooms', null, {});
await queryInterface.bulkDelete('subjects', null, {});
await queryInterface.bulkDelete('teachers', null, {});
await queryInterface.bulkDelete('timetables', null, {});
},
};