847 lines
19 KiB
JavaScript
847 lines
19 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Classes = db.classes;
|
|
|
|
const Scores = db.scores;
|
|
|
|
const Students = db.students;
|
|
|
|
const Subjects = db.subjects;
|
|
|
|
const Teachers = db.teachers;
|
|
|
|
const Schools = db.schools;
|
|
|
|
const ClassesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
name: 'Basic 9A',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
name: 'Basic 8B',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
name: 'Basic 7C',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
name: 'Basic 6D',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ScoresData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
term: 1,
|
|
|
|
score: 85.5,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
term: 1,
|
|
|
|
score: 90,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
term: 1,
|
|
|
|
score: 78,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
term: 1,
|
|
|
|
score: 88,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const StudentsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
full_name: 'Tommy Lee',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
full_name: 'Jessica Kim',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
full_name: 'Oliver Twist',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
full_name: 'Sophia Brown',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const SubjectsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
name: 'English Language',
|
|
|
|
type: 'Core',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
name: 'Mathematics',
|
|
|
|
type: 'Core',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
name: 'Science',
|
|
|
|
type: 'Elective',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
name: 'Social Studies',
|
|
|
|
type: 'Core',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const TeachersData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
username: 'teacher1',
|
|
|
|
full_name: 'Emily Brown',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
username: 'teacher2',
|
|
|
|
full_name: 'Michael Green',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
username: 'teacher3',
|
|
|
|
full_name: 'Sarah Black',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
username: 'teacher4',
|
|
|
|
full_name: 'James White',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const SchoolsData = [
|
|
{
|
|
name: 'Sunrise Basic School',
|
|
},
|
|
|
|
{
|
|
name: 'Starlight Academy',
|
|
},
|
|
|
|
{
|
|
name: 'Greenfield International',
|
|
},
|
|
|
|
{
|
|
name: 'Blue Ridge High',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateUserWithSchool() {
|
|
const relatedSchool0 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const User0 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (User0?.setSchool) {
|
|
await User0.setSchool(relatedSchool0);
|
|
}
|
|
|
|
const relatedSchool1 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const User1 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (User1?.setSchool) {
|
|
await User1.setSchool(relatedSchool1);
|
|
}
|
|
|
|
const relatedSchool2 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const User2 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (User2?.setSchool) {
|
|
await User2.setSchool(relatedSchool2);
|
|
}
|
|
|
|
const relatedSchool3 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const User3 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (User3?.setSchool) {
|
|
await User3.setSchool(relatedSchool3);
|
|
}
|
|
}
|
|
|
|
async function associateClassWithSchool() {
|
|
const relatedSchool0 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Class0 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Class0?.setSchool) {
|
|
await Class0.setSchool(relatedSchool0);
|
|
}
|
|
|
|
const relatedSchool1 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Class1 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Class1?.setSchool) {
|
|
await Class1.setSchool(relatedSchool1);
|
|
}
|
|
|
|
const relatedSchool2 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Class2 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Class2?.setSchool) {
|
|
await Class2.setSchool(relatedSchool2);
|
|
}
|
|
|
|
const relatedSchool3 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Class3 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Class3?.setSchool) {
|
|
await Class3.setSchool(relatedSchool3);
|
|
}
|
|
}
|
|
|
|
async function associateClassWithSchool() {
|
|
const relatedSchool0 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Class0 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Class0?.setSchool) {
|
|
await Class0.setSchool(relatedSchool0);
|
|
}
|
|
|
|
const relatedSchool1 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Class1 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Class1?.setSchool) {
|
|
await Class1.setSchool(relatedSchool1);
|
|
}
|
|
|
|
const relatedSchool2 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Class2 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Class2?.setSchool) {
|
|
await Class2.setSchool(relatedSchool2);
|
|
}
|
|
|
|
const relatedSchool3 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Class3 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Class3?.setSchool) {
|
|
await Class3.setSchool(relatedSchool3);
|
|
}
|
|
}
|
|
|
|
async function associateScoreWithStudent() {
|
|
const relatedStudent0 = await Students.findOne({
|
|
offset: Math.floor(Math.random() * (await Students.count())),
|
|
});
|
|
const Score0 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Score0?.setStudent) {
|
|
await Score0.setStudent(relatedStudent0);
|
|
}
|
|
|
|
const relatedStudent1 = await Students.findOne({
|
|
offset: Math.floor(Math.random() * (await Students.count())),
|
|
});
|
|
const Score1 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Score1?.setStudent) {
|
|
await Score1.setStudent(relatedStudent1);
|
|
}
|
|
|
|
const relatedStudent2 = await Students.findOne({
|
|
offset: Math.floor(Math.random() * (await Students.count())),
|
|
});
|
|
const Score2 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Score2?.setStudent) {
|
|
await Score2.setStudent(relatedStudent2);
|
|
}
|
|
|
|
const relatedStudent3 = await Students.findOne({
|
|
offset: Math.floor(Math.random() * (await Students.count())),
|
|
});
|
|
const Score3 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Score3?.setStudent) {
|
|
await Score3.setStudent(relatedStudent3);
|
|
}
|
|
}
|
|
|
|
async function associateScoreWithSubject() {
|
|
const relatedSubject0 = await Subjects.findOne({
|
|
offset: Math.floor(Math.random() * (await Subjects.count())),
|
|
});
|
|
const Score0 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Score0?.setSubject) {
|
|
await Score0.setSubject(relatedSubject0);
|
|
}
|
|
|
|
const relatedSubject1 = await Subjects.findOne({
|
|
offset: Math.floor(Math.random() * (await Subjects.count())),
|
|
});
|
|
const Score1 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Score1?.setSubject) {
|
|
await Score1.setSubject(relatedSubject1);
|
|
}
|
|
|
|
const relatedSubject2 = await Subjects.findOne({
|
|
offset: Math.floor(Math.random() * (await Subjects.count())),
|
|
});
|
|
const Score2 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Score2?.setSubject) {
|
|
await Score2.setSubject(relatedSubject2);
|
|
}
|
|
|
|
const relatedSubject3 = await Subjects.findOne({
|
|
offset: Math.floor(Math.random() * (await Subjects.count())),
|
|
});
|
|
const Score3 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Score3?.setSubject) {
|
|
await Score3.setSubject(relatedSubject3);
|
|
}
|
|
}
|
|
|
|
async function associateScoreWithSchool() {
|
|
const relatedSchool0 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Score0 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Score0?.setSchool) {
|
|
await Score0.setSchool(relatedSchool0);
|
|
}
|
|
|
|
const relatedSchool1 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Score1 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Score1?.setSchool) {
|
|
await Score1.setSchool(relatedSchool1);
|
|
}
|
|
|
|
const relatedSchool2 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Score2 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Score2?.setSchool) {
|
|
await Score2.setSchool(relatedSchool2);
|
|
}
|
|
|
|
const relatedSchool3 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Score3 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Score3?.setSchool) {
|
|
await Score3.setSchool(relatedSchool3);
|
|
}
|
|
}
|
|
|
|
async function associateStudentWithSchool() {
|
|
const relatedSchool0 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Student0 = await Students.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Student0?.setSchool) {
|
|
await Student0.setSchool(relatedSchool0);
|
|
}
|
|
|
|
const relatedSchool1 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Student1 = await Students.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Student1?.setSchool) {
|
|
await Student1.setSchool(relatedSchool1);
|
|
}
|
|
|
|
const relatedSchool2 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Student2 = await Students.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Student2?.setSchool) {
|
|
await Student2.setSchool(relatedSchool2);
|
|
}
|
|
|
|
const relatedSchool3 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Student3 = await Students.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Student3?.setSchool) {
|
|
await Student3.setSchool(relatedSchool3);
|
|
}
|
|
}
|
|
|
|
async function associateStudentWithSchool() {
|
|
const relatedSchool0 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Student0 = await Students.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Student0?.setSchool) {
|
|
await Student0.setSchool(relatedSchool0);
|
|
}
|
|
|
|
const relatedSchool1 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Student1 = await Students.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Student1?.setSchool) {
|
|
await Student1.setSchool(relatedSchool1);
|
|
}
|
|
|
|
const relatedSchool2 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Student2 = await Students.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Student2?.setSchool) {
|
|
await Student2.setSchool(relatedSchool2);
|
|
}
|
|
|
|
const relatedSchool3 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Student3 = await Students.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Student3?.setSchool) {
|
|
await Student3.setSchool(relatedSchool3);
|
|
}
|
|
}
|
|
|
|
async function associateSubjectWithSchool() {
|
|
const relatedSchool0 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Subject0 = await Subjects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Subject0?.setSchool) {
|
|
await Subject0.setSchool(relatedSchool0);
|
|
}
|
|
|
|
const relatedSchool1 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Subject1 = await Subjects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Subject1?.setSchool) {
|
|
await Subject1.setSchool(relatedSchool1);
|
|
}
|
|
|
|
const relatedSchool2 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Subject2 = await Subjects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Subject2?.setSchool) {
|
|
await Subject2.setSchool(relatedSchool2);
|
|
}
|
|
|
|
const relatedSchool3 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Subject3 = await Subjects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Subject3?.setSchool) {
|
|
await Subject3.setSchool(relatedSchool3);
|
|
}
|
|
}
|
|
|
|
async function associateSubjectWithSchool() {
|
|
const relatedSchool0 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Subject0 = await Subjects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Subject0?.setSchool) {
|
|
await Subject0.setSchool(relatedSchool0);
|
|
}
|
|
|
|
const relatedSchool1 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Subject1 = await Subjects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Subject1?.setSchool) {
|
|
await Subject1.setSchool(relatedSchool1);
|
|
}
|
|
|
|
const relatedSchool2 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Subject2 = await Subjects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Subject2?.setSchool) {
|
|
await Subject2.setSchool(relatedSchool2);
|
|
}
|
|
|
|
const relatedSchool3 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Subject3 = await Subjects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Subject3?.setSchool) {
|
|
await Subject3.setSchool(relatedSchool3);
|
|
}
|
|
}
|
|
|
|
async function associateTeacherWithSchool() {
|
|
const relatedSchool0 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Teacher0 = await Teachers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Teacher0?.setSchool) {
|
|
await Teacher0.setSchool(relatedSchool0);
|
|
}
|
|
|
|
const relatedSchool1 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Teacher1 = await Teachers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Teacher1?.setSchool) {
|
|
await Teacher1.setSchool(relatedSchool1);
|
|
}
|
|
|
|
const relatedSchool2 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Teacher2 = await Teachers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Teacher2?.setSchool) {
|
|
await Teacher2.setSchool(relatedSchool2);
|
|
}
|
|
|
|
const relatedSchool3 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Teacher3 = await Teachers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Teacher3?.setSchool) {
|
|
await Teacher3.setSchool(relatedSchool3);
|
|
}
|
|
}
|
|
|
|
async function associateTeacherWithSchool() {
|
|
const relatedSchool0 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Teacher0 = await Teachers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Teacher0?.setSchool) {
|
|
await Teacher0.setSchool(relatedSchool0);
|
|
}
|
|
|
|
const relatedSchool1 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Teacher1 = await Teachers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Teacher1?.setSchool) {
|
|
await Teacher1.setSchool(relatedSchool1);
|
|
}
|
|
|
|
const relatedSchool2 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Teacher2 = await Teachers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Teacher2?.setSchool) {
|
|
await Teacher2.setSchool(relatedSchool2);
|
|
}
|
|
|
|
const relatedSchool3 = await Schools.findOne({
|
|
offset: Math.floor(Math.random() * (await Schools.count())),
|
|
});
|
|
const Teacher3 = await Teachers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Teacher3?.setSchool) {
|
|
await Teacher3.setSchool(relatedSchool3);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Classes.bulkCreate(ClassesData);
|
|
|
|
await Scores.bulkCreate(ScoresData);
|
|
|
|
await Students.bulkCreate(StudentsData);
|
|
|
|
await Subjects.bulkCreate(SubjectsData);
|
|
|
|
await Teachers.bulkCreate(TeachersData);
|
|
|
|
await Schools.bulkCreate(SchoolsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithSchool(),
|
|
|
|
await associateClassWithSchool(),
|
|
|
|
await associateClassWithSchool(),
|
|
|
|
await associateScoreWithStudent(),
|
|
|
|
await associateScoreWithSubject(),
|
|
|
|
await associateScoreWithSchool(),
|
|
|
|
await associateStudentWithSchool(),
|
|
|
|
await associateStudentWithSchool(),
|
|
|
|
await associateSubjectWithSchool(),
|
|
|
|
await associateSubjectWithSchool(),
|
|
|
|
await associateTeacherWithSchool(),
|
|
|
|
await associateTeacherWithSchool(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('classes', null, {});
|
|
|
|
await queryInterface.bulkDelete('scores', null, {});
|
|
|
|
await queryInterface.bulkDelete('students', null, {});
|
|
|
|
await queryInterface.bulkDelete('subjects', null, {});
|
|
|
|
await queryInterface.bulkDelete('teachers', null, {});
|
|
|
|
await queryInterface.bulkDelete('schools', null, {});
|
|
},
|
|
};
|