29885/backend/src/db/seeders/20231127130745-sample-data.js
2025-03-14 15:02:55 +00:00

877 lines
23 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Classrooms = db.classrooms;
const Schools = db.schools;
const Sessions = db.sessions;
const Transcriptions = db.transcriptions;
const Schoolsanduniversities = db.schoolsanduniversities;
const ClassroomsData = [
{
name: 'Physics 101',
// type code here for "relation_one" 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_one" field
},
{
name: 'Chemistry 201',
// type code here for "relation_one" 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_one" field
},
{
name: 'Mathematics 301',
// type code here for "relation_one" 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_one" field
},
{
name: 'Biology 101',
// type code here for "relation_one" 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_one" field
},
{
name: 'History 101',
// type code here for "relation_one" 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_one" field
},
];
const SchoolsData = [
{
name: 'Greenwood High',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Riverside University',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Lakeside College',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Hilltop Academy',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Sunset Institute',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
const SessionsData = [
{
subject: 'Physics',
topic: "Newton's Laws",
// type code here for "relation_one" field
start_time: new Date('2023-10-01T09:00:00Z'),
end_time: new Date('2023-10-01T10:30:00Z'),
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
subject: 'Chemistry',
topic: 'Organic Compounds',
// type code here for "relation_one" field
start_time: new Date('2023-10-02T11:00:00Z'),
end_time: new Date('2023-10-02T12:30:00Z'),
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
subject: 'Mathematics',
topic: 'Calculus',
// type code here for "relation_one" field
start_time: new Date('2023-10-03T13:00:00Z'),
end_time: new Date('2023-10-03T14:30:00Z'),
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
subject: 'Biology',
topic: 'Cell Structure',
// type code here for "relation_one" field
start_time: new Date('2023-10-04T15:00:00Z'),
end_time: new Date('2023-10-04T16:30:00Z'),
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
subject: 'History',
topic: 'World War II',
// type code here for "relation_one" field
start_time: new Date('2023-10-05T17:00:00Z'),
end_time: new Date('2023-10-05T18:30:00Z'),
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
const TranscriptionsData = [
{
content:
"Newton's first law states that an object at rest stays at rest...",
// type code here for "relation_one" field
// type code here for "relation_one" field
timestamp: new Date('2023-10-01T09:15:00Z'),
// type code here for "relation_one" field
},
{
content: 'Organic compounds are primarily made of carbon atoms...',
// type code here for "relation_one" field
// type code here for "relation_one" field
timestamp: new Date('2023-10-02T11:15:00Z'),
// type code here for "relation_one" field
},
{
content: 'Calculus is the mathematical study of continuous change...',
// type code here for "relation_one" field
// type code here for "relation_one" field
timestamp: new Date('2023-10-03T13:15:00Z'),
// type code here for "relation_one" field
},
{
content: 'Cells are the basic building blocks of all living organisms...',
// type code here for "relation_one" field
// type code here for "relation_one" field
timestamp: new Date('2023-10-04T15:15:00Z'),
// type code here for "relation_one" field
},
{
content: 'World War II was a global war that lasted from 1939 to 1945...',
// type code here for "relation_one" field
// type code here for "relation_one" field
timestamp: new Date('2023-10-05T17:15:00Z'),
// type code here for "relation_one" field
},
];
const SchoolsanduniversitiesData = [
{
name: 'George Gaylord Simpson',
},
{
name: 'Carl Gauss (Karl Friedrich Gauss)',
},
{
name: 'Dmitri Mendeleev',
},
{
name: 'Lynn Margulis',
},
{
name: 'Lynn Margulis',
},
];
// Similar logic for "relation_many"
async function associateUserWithSchoolsanduniversity() {
const relatedSchoolsanduniversity0 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const User0 = await Users.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (User0?.setSchoolsanduniversity) {
await User0.setSchoolsanduniversity(relatedSchoolsanduniversity0);
}
const relatedSchoolsanduniversity1 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const User1 = await Users.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (User1?.setSchoolsanduniversity) {
await User1.setSchoolsanduniversity(relatedSchoolsanduniversity1);
}
const relatedSchoolsanduniversity2 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const User2 = await Users.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (User2?.setSchoolsanduniversity) {
await User2.setSchoolsanduniversity(relatedSchoolsanduniversity2);
}
const relatedSchoolsanduniversity3 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const User3 = await Users.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (User3?.setSchoolsanduniversity) {
await User3.setSchoolsanduniversity(relatedSchoolsanduniversity3);
}
const relatedSchoolsanduniversity4 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const User4 = await Users.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (User4?.setSchoolsanduniversity) {
await User4.setSchoolsanduniversity(relatedSchoolsanduniversity4);
}
}
async function associateClassroomWithSchool() {
const relatedSchool0 = await Schools.findOne({
offset: Math.floor(Math.random() * (await Schools.count())),
});
const Classroom0 = await Classrooms.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Classroom0?.setSchool) {
await Classroom0.setSchool(relatedSchool0);
}
const relatedSchool1 = await Schools.findOne({
offset: Math.floor(Math.random() * (await Schools.count())),
});
const Classroom1 = await Classrooms.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Classroom1?.setSchool) {
await Classroom1.setSchool(relatedSchool1);
}
const relatedSchool2 = await Schools.findOne({
offset: Math.floor(Math.random() * (await Schools.count())),
});
const Classroom2 = await Classrooms.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Classroom2?.setSchool) {
await Classroom2.setSchool(relatedSchool2);
}
const relatedSchool3 = await Schools.findOne({
offset: Math.floor(Math.random() * (await Schools.count())),
});
const Classroom3 = await Classrooms.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Classroom3?.setSchool) {
await Classroom3.setSchool(relatedSchool3);
}
const relatedSchool4 = await Schools.findOne({
offset: Math.floor(Math.random() * (await Schools.count())),
});
const Classroom4 = await Classrooms.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Classroom4?.setSchool) {
await Classroom4.setSchool(relatedSchool4);
}
}
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
async function associateClassroomWithSchoolsanduniversity() {
const relatedSchoolsanduniversity0 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const Classroom0 = await Classrooms.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Classroom0?.setSchoolsanduniversity) {
await Classroom0.setSchoolsanduniversity(relatedSchoolsanduniversity0);
}
const relatedSchoolsanduniversity1 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const Classroom1 = await Classrooms.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Classroom1?.setSchoolsanduniversity) {
await Classroom1.setSchoolsanduniversity(relatedSchoolsanduniversity1);
}
const relatedSchoolsanduniversity2 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const Classroom2 = await Classrooms.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Classroom2?.setSchoolsanduniversity) {
await Classroom2.setSchoolsanduniversity(relatedSchoolsanduniversity2);
}
const relatedSchoolsanduniversity3 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const Classroom3 = await Classrooms.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Classroom3?.setSchoolsanduniversity) {
await Classroom3.setSchoolsanduniversity(relatedSchoolsanduniversity3);
}
const relatedSchoolsanduniversity4 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const Classroom4 = await Classrooms.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Classroom4?.setSchoolsanduniversity) {
await Classroom4.setSchoolsanduniversity(relatedSchoolsanduniversity4);
}
}
// Similar logic for "relation_many"
async function associateSchoolWithSchoolsanduniversity() {
const relatedSchoolsanduniversity0 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const School0 = await Schools.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (School0?.setSchoolsanduniversity) {
await School0.setSchoolsanduniversity(relatedSchoolsanduniversity0);
}
const relatedSchoolsanduniversity1 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const School1 = await Schools.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (School1?.setSchoolsanduniversity) {
await School1.setSchoolsanduniversity(relatedSchoolsanduniversity1);
}
const relatedSchoolsanduniversity2 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const School2 = await Schools.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (School2?.setSchoolsanduniversity) {
await School2.setSchoolsanduniversity(relatedSchoolsanduniversity2);
}
const relatedSchoolsanduniversity3 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const School3 = await Schools.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (School3?.setSchoolsanduniversity) {
await School3.setSchoolsanduniversity(relatedSchoolsanduniversity3);
}
const relatedSchoolsanduniversity4 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const School4 = await Schools.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (School4?.setSchoolsanduniversity) {
await School4.setSchoolsanduniversity(relatedSchoolsanduniversity4);
}
}
async function associateSessionWithClassroom() {
const relatedClassroom0 = await Classrooms.findOne({
offset: Math.floor(Math.random() * (await Classrooms.count())),
});
const Session0 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Session0?.setClassroom) {
await Session0.setClassroom(relatedClassroom0);
}
const relatedClassroom1 = await Classrooms.findOne({
offset: Math.floor(Math.random() * (await Classrooms.count())),
});
const Session1 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Session1?.setClassroom) {
await Session1.setClassroom(relatedClassroom1);
}
const relatedClassroom2 = await Classrooms.findOne({
offset: Math.floor(Math.random() * (await Classrooms.count())),
});
const Session2 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Session2?.setClassroom) {
await Session2.setClassroom(relatedClassroom2);
}
const relatedClassroom3 = await Classrooms.findOne({
offset: Math.floor(Math.random() * (await Classrooms.count())),
});
const Session3 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Session3?.setClassroom) {
await Session3.setClassroom(relatedClassroom3);
}
const relatedClassroom4 = await Classrooms.findOne({
offset: Math.floor(Math.random() * (await Classrooms.count())),
});
const Session4 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Session4?.setClassroom) {
await Session4.setClassroom(relatedClassroom4);
}
}
// Similar logic for "relation_many"
async function associateSessionWithSchoolsanduniversity() {
const relatedSchoolsanduniversity0 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const Session0 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Session0?.setSchoolsanduniversity) {
await Session0.setSchoolsanduniversity(relatedSchoolsanduniversity0);
}
const relatedSchoolsanduniversity1 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const Session1 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Session1?.setSchoolsanduniversity) {
await Session1.setSchoolsanduniversity(relatedSchoolsanduniversity1);
}
const relatedSchoolsanduniversity2 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const Session2 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Session2?.setSchoolsanduniversity) {
await Session2.setSchoolsanduniversity(relatedSchoolsanduniversity2);
}
const relatedSchoolsanduniversity3 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const Session3 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Session3?.setSchoolsanduniversity) {
await Session3.setSchoolsanduniversity(relatedSchoolsanduniversity3);
}
const relatedSchoolsanduniversity4 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const Session4 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Session4?.setSchoolsanduniversity) {
await Session4.setSchoolsanduniversity(relatedSchoolsanduniversity4);
}
}
async function associateTranscriptionWithSession() {
const relatedSession0 = await Sessions.findOne({
offset: Math.floor(Math.random() * (await Sessions.count())),
});
const Transcription0 = await Transcriptions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Transcription0?.setSession) {
await Transcription0.setSession(relatedSession0);
}
const relatedSession1 = await Sessions.findOne({
offset: Math.floor(Math.random() * (await Sessions.count())),
});
const Transcription1 = await Transcriptions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Transcription1?.setSession) {
await Transcription1.setSession(relatedSession1);
}
const relatedSession2 = await Sessions.findOne({
offset: Math.floor(Math.random() * (await Sessions.count())),
});
const Transcription2 = await Transcriptions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Transcription2?.setSession) {
await Transcription2.setSession(relatedSession2);
}
const relatedSession3 = await Sessions.findOne({
offset: Math.floor(Math.random() * (await Sessions.count())),
});
const Transcription3 = await Transcriptions.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Transcription3?.setSession) {
await Transcription3.setSession(relatedSession3);
}
const relatedSession4 = await Sessions.findOne({
offset: Math.floor(Math.random() * (await Sessions.count())),
});
const Transcription4 = await Transcriptions.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Transcription4?.setSession) {
await Transcription4.setSession(relatedSession4);
}
}
async function associateTranscriptionWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Transcription0 = await Transcriptions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Transcription0?.setUser) {
await Transcription0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Transcription1 = await Transcriptions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Transcription1?.setUser) {
await Transcription1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Transcription2 = await Transcriptions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Transcription2?.setUser) {
await Transcription2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Transcription3 = await Transcriptions.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Transcription3?.setUser) {
await Transcription3.setUser(relatedUser3);
}
const relatedUser4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Transcription4 = await Transcriptions.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Transcription4?.setUser) {
await Transcription4.setUser(relatedUser4);
}
}
async function associateTranscriptionWithSchoolsanduniversity() {
const relatedSchoolsanduniversity0 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const Transcription0 = await Transcriptions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Transcription0?.setSchoolsanduniversity) {
await Transcription0.setSchoolsanduniversity(relatedSchoolsanduniversity0);
}
const relatedSchoolsanduniversity1 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const Transcription1 = await Transcriptions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Transcription1?.setSchoolsanduniversity) {
await Transcription1.setSchoolsanduniversity(relatedSchoolsanduniversity1);
}
const relatedSchoolsanduniversity2 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const Transcription2 = await Transcriptions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Transcription2?.setSchoolsanduniversity) {
await Transcription2.setSchoolsanduniversity(relatedSchoolsanduniversity2);
}
const relatedSchoolsanduniversity3 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const Transcription3 = await Transcriptions.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Transcription3?.setSchoolsanduniversity) {
await Transcription3.setSchoolsanduniversity(relatedSchoolsanduniversity3);
}
const relatedSchoolsanduniversity4 = await Schoolsanduniversities.findOne({
offset: Math.floor(Math.random() * (await Schoolsanduniversities.count())),
});
const Transcription4 = await Transcriptions.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Transcription4?.setSchoolsanduniversity) {
await Transcription4.setSchoolsanduniversity(relatedSchoolsanduniversity4);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Classrooms.bulkCreate(ClassroomsData);
await Schools.bulkCreate(SchoolsData);
await Sessions.bulkCreate(SessionsData);
await Transcriptions.bulkCreate(TranscriptionsData);
await Schoolsanduniversities.bulkCreate(SchoolsanduniversitiesData);
await Promise.all([
// Similar logic for "relation_many"
await associateUserWithSchoolsanduniversity(),
await associateClassroomWithSchool(),
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
await associateClassroomWithSchoolsanduniversity(),
// Similar logic for "relation_many"
await associateSchoolWithSchoolsanduniversity(),
await associateSessionWithClassroom(),
// Similar logic for "relation_many"
await associateSessionWithSchoolsanduniversity(),
await associateTranscriptionWithSession(),
await associateTranscriptionWithUser(),
await associateTranscriptionWithSchoolsanduniversity(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('classrooms', null, {});
await queryInterface.bulkDelete('schools', null, {});
await queryInterface.bulkDelete('sessions', null, {});
await queryInterface.bulkDelete('transcriptions', null, {});
await queryInterface.bulkDelete('schoolsanduniversities', null, {});
},
};