419 lines
9.2 KiB
JavaScript
419 lines
9.2 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Collaborations = db.collaborations;
|
|
|
|
const Exams = db.exams;
|
|
|
|
const Materials = db.materials;
|
|
|
|
const StudyPlans = db.study_plans;
|
|
|
|
const StudyResources = db.study_resources;
|
|
|
|
const CollaborationsData = [
|
|
{
|
|
name: 'Biology Study Group',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'History Team',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Math Club',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Chemistry Partners',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const ExamsData = [
|
|
{
|
|
name: 'Biology Midterm',
|
|
|
|
date: new Date('2023-11-15T09:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'History Final',
|
|
|
|
date: new Date('2023-12-20T14:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Math Quiz',
|
|
|
|
date: new Date('2023-10-30T11:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Chemistry Test',
|
|
|
|
date: new Date('2023-11-10T13:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const MaterialsData = [
|
|
{
|
|
title: 'Biology Notes Chapter 1',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'History Presentation',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Math Textbook Photos',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Chemistry Lab Report',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const StudyPlansData = [
|
|
{
|
|
name: 'Biology Study Plan',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'History Study Plan',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Math Study Plan',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Chemistry Study Plan',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const StudyResourcesData = [
|
|
{
|
|
title: 'Biology Chapter 1 Summary',
|
|
|
|
resource_type: 'flashcard',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'History Quiz',
|
|
|
|
resource_type: 'explanation',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Math Flashcards',
|
|
|
|
resource_type: 'quiz',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Chemistry Game',
|
|
|
|
resource_type: 'explanation',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateExamWithStudent() {
|
|
const relatedStudent0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Exam0 = await Exams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Exam0?.setStudent) {
|
|
await Exam0.setStudent(relatedStudent0);
|
|
}
|
|
|
|
const relatedStudent1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Exam1 = await Exams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Exam1?.setStudent) {
|
|
await Exam1.setStudent(relatedStudent1);
|
|
}
|
|
|
|
const relatedStudent2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Exam2 = await Exams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Exam2?.setStudent) {
|
|
await Exam2.setStudent(relatedStudent2);
|
|
}
|
|
|
|
const relatedStudent3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Exam3 = await Exams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Exam3?.setStudent) {
|
|
await Exam3.setStudent(relatedStudent3);
|
|
}
|
|
}
|
|
|
|
async function associateMaterialWithUploaded_by() {
|
|
const relatedUploaded_by0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Material0 = await Materials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Material0?.setUploaded_by) {
|
|
await Material0.setUploaded_by(relatedUploaded_by0);
|
|
}
|
|
|
|
const relatedUploaded_by1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Material1 = await Materials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Material1?.setUploaded_by) {
|
|
await Material1.setUploaded_by(relatedUploaded_by1);
|
|
}
|
|
|
|
const relatedUploaded_by2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Material2 = await Materials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Material2?.setUploaded_by) {
|
|
await Material2.setUploaded_by(relatedUploaded_by2);
|
|
}
|
|
|
|
const relatedUploaded_by3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Material3 = await Materials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Material3?.setUploaded_by) {
|
|
await Material3.setUploaded_by(relatedUploaded_by3);
|
|
}
|
|
}
|
|
|
|
async function associateStudyPlanWithStudent() {
|
|
const relatedStudent0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const StudyPlan0 = await StudyPlans.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (StudyPlan0?.setStudent) {
|
|
await StudyPlan0.setStudent(relatedStudent0);
|
|
}
|
|
|
|
const relatedStudent1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const StudyPlan1 = await StudyPlans.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (StudyPlan1?.setStudent) {
|
|
await StudyPlan1.setStudent(relatedStudent1);
|
|
}
|
|
|
|
const relatedStudent2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const StudyPlan2 = await StudyPlans.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (StudyPlan2?.setStudent) {
|
|
await StudyPlan2.setStudent(relatedStudent2);
|
|
}
|
|
|
|
const relatedStudent3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const StudyPlan3 = await StudyPlans.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (StudyPlan3?.setStudent) {
|
|
await StudyPlan3.setStudent(relatedStudent3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateStudyResourceWithMaterial() {
|
|
const relatedMaterial0 = await Materials.findOne({
|
|
offset: Math.floor(Math.random() * (await Materials.count())),
|
|
});
|
|
const StudyResource0 = await StudyResources.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (StudyResource0?.setMaterial) {
|
|
await StudyResource0.setMaterial(relatedMaterial0);
|
|
}
|
|
|
|
const relatedMaterial1 = await Materials.findOne({
|
|
offset: Math.floor(Math.random() * (await Materials.count())),
|
|
});
|
|
const StudyResource1 = await StudyResources.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (StudyResource1?.setMaterial) {
|
|
await StudyResource1.setMaterial(relatedMaterial1);
|
|
}
|
|
|
|
const relatedMaterial2 = await Materials.findOne({
|
|
offset: Math.floor(Math.random() * (await Materials.count())),
|
|
});
|
|
const StudyResource2 = await StudyResources.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (StudyResource2?.setMaterial) {
|
|
await StudyResource2.setMaterial(relatedMaterial2);
|
|
}
|
|
|
|
const relatedMaterial3 = await Materials.findOne({
|
|
offset: Math.floor(Math.random() * (await Materials.count())),
|
|
});
|
|
const StudyResource3 = await StudyResources.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (StudyResource3?.setMaterial) {
|
|
await StudyResource3.setMaterial(relatedMaterial3);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Collaborations.bulkCreate(CollaborationsData);
|
|
|
|
await Exams.bulkCreate(ExamsData);
|
|
|
|
await Materials.bulkCreate(MaterialsData);
|
|
|
|
await StudyPlans.bulkCreate(StudyPlansData);
|
|
|
|
await StudyResources.bulkCreate(StudyResourcesData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateExamWithStudent(),
|
|
|
|
await associateMaterialWithUploaded_by(),
|
|
|
|
await associateStudyPlanWithStudent(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateStudyResourceWithMaterial(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('collaborations', null, {});
|
|
|
|
await queryInterface.bulkDelete('exams', null, {});
|
|
|
|
await queryInterface.bulkDelete('materials', null, {});
|
|
|
|
await queryInterface.bulkDelete('study_plans', null, {});
|
|
|
|
await queryInterface.bulkDelete('study_resources', null, {});
|
|
},
|
|
};
|