30528/backend/src/db/seeders/20231127130745-sample-data.js
2025-04-06 20:51:00 +00:00

654 lines
15 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Attendances = db.attendances;
const RunCrews = db.run_crews;
const Sessions = db.sessions;
const Runcrew = db.runcrew;
const AttendancesData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
status: 'Absent',
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
status: 'RSVP',
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
status: 'Absent',
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
status: 'CheckedIn',
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
status: 'CheckedIn',
// type code here for "relation_one" field
},
];
const RunCrewsData = [
{
name: 'Downtown Runners',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'City Sprinters',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Suburban Joggers',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Trail Blazers',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Night Owls',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
const SessionsData = [
{
title: 'Morning Run',
start_time: new Date('2023-11-01T07:00:00Z'),
end_time: new Date('2023-11-01T08:00:00Z'),
location: 'Central Park',
notes: 'Easy pace, 5 miles',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
title: 'Evening Sprint',
start_time: new Date('2023-11-02T18:00:00Z'),
end_time: new Date('2023-11-02T19:00:00Z'),
location: 'Riverside Track',
notes: 'Interval training',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
title: 'Weekend Long Run',
start_time: new Date('2023-11-04T08:00:00Z'),
end_time: new Date('2023-11-04T10:00:00Z'),
location: 'Suburban Trails',
notes: '10 miles, mixed terrain',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
title: 'Night Run',
start_time: new Date('2023-11-05T20:00:00Z'),
end_time: new Date('2023-11-05T21:00:00Z'),
location: 'City Streets',
notes: 'Bring reflective gear',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
title: 'Trail Adventure',
start_time: new Date('2023-11-06T09:00:00Z'),
end_time: new Date('2023-11-06T11:00:00Z'),
location: 'Mountain Trails',
notes: 'Challenging route, 8 miles',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const RuncrewData = [
{
name: 'Johannes Kepler',
},
{
name: 'Gregor Mendel',
},
{
name: 'Ernst Mayr',
},
{
name: 'Jean Baptiste Lamarck',
},
{
name: 'Arthur Eddington',
},
];
// Similar logic for "relation_many"
async function associateUserWithRuncrew() {
const relatedRuncrew0 = await Runcrew.findOne({
offset: Math.floor(Math.random() * (await Runcrew.count())),
});
const User0 = await Users.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (User0?.setRuncrew) {
await User0.setRuncrew(relatedRuncrew0);
}
const relatedRuncrew1 = await Runcrew.findOne({
offset: Math.floor(Math.random() * (await Runcrew.count())),
});
const User1 = await Users.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (User1?.setRuncrew) {
await User1.setRuncrew(relatedRuncrew1);
}
const relatedRuncrew2 = await Runcrew.findOne({
offset: Math.floor(Math.random() * (await Runcrew.count())),
});
const User2 = await Users.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (User2?.setRuncrew) {
await User2.setRuncrew(relatedRuncrew2);
}
const relatedRuncrew3 = await Runcrew.findOne({
offset: Math.floor(Math.random() * (await Runcrew.count())),
});
const User3 = await Users.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (User3?.setRuncrew) {
await User3.setRuncrew(relatedRuncrew3);
}
const relatedRuncrew4 = await Runcrew.findOne({
offset: Math.floor(Math.random() * (await Runcrew.count())),
});
const User4 = await Users.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (User4?.setRuncrew) {
await User4.setRuncrew(relatedRuncrew4);
}
}
async function associateAttendanceWithSession() {
const relatedSession0 = await Sessions.findOne({
offset: Math.floor(Math.random() * (await Sessions.count())),
});
const Attendance0 = await Attendances.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Attendance0?.setSession) {
await Attendance0.setSession(relatedSession0);
}
const relatedSession1 = await Sessions.findOne({
offset: Math.floor(Math.random() * (await Sessions.count())),
});
const Attendance1 = await Attendances.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Attendance1?.setSession) {
await Attendance1.setSession(relatedSession1);
}
const relatedSession2 = await Sessions.findOne({
offset: Math.floor(Math.random() * (await Sessions.count())),
});
const Attendance2 = await Attendances.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Attendance2?.setSession) {
await Attendance2.setSession(relatedSession2);
}
const relatedSession3 = await Sessions.findOne({
offset: Math.floor(Math.random() * (await Sessions.count())),
});
const Attendance3 = await Attendances.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Attendance3?.setSession) {
await Attendance3.setSession(relatedSession3);
}
const relatedSession4 = await Sessions.findOne({
offset: Math.floor(Math.random() * (await Sessions.count())),
});
const Attendance4 = await Attendances.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Attendance4?.setSession) {
await Attendance4.setSession(relatedSession4);
}
}
async function associateAttendanceWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Attendance0 = await Attendances.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Attendance0?.setUser) {
await Attendance0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Attendance1 = await Attendances.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Attendance1?.setUser) {
await Attendance1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Attendance2 = await Attendances.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Attendance2?.setUser) {
await Attendance2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Attendance3 = await Attendances.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Attendance3?.setUser) {
await Attendance3.setUser(relatedUser3);
}
const relatedUser4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Attendance4 = await Attendances.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Attendance4?.setUser) {
await Attendance4.setUser(relatedUser4);
}
}
async function associateAttendanceWithRuncrew() {
const relatedRuncrew0 = await Runcrew.findOne({
offset: Math.floor(Math.random() * (await Runcrew.count())),
});
const Attendance0 = await Attendances.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Attendance0?.setRuncrew) {
await Attendance0.setRuncrew(relatedRuncrew0);
}
const relatedRuncrew1 = await Runcrew.findOne({
offset: Math.floor(Math.random() * (await Runcrew.count())),
});
const Attendance1 = await Attendances.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Attendance1?.setRuncrew) {
await Attendance1.setRuncrew(relatedRuncrew1);
}
const relatedRuncrew2 = await Runcrew.findOne({
offset: Math.floor(Math.random() * (await Runcrew.count())),
});
const Attendance2 = await Attendances.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Attendance2?.setRuncrew) {
await Attendance2.setRuncrew(relatedRuncrew2);
}
const relatedRuncrew3 = await Runcrew.findOne({
offset: Math.floor(Math.random() * (await Runcrew.count())),
});
const Attendance3 = await Attendances.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Attendance3?.setRuncrew) {
await Attendance3.setRuncrew(relatedRuncrew3);
}
const relatedRuncrew4 = await Runcrew.findOne({
offset: Math.floor(Math.random() * (await Runcrew.count())),
});
const Attendance4 = await Attendances.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Attendance4?.setRuncrew) {
await Attendance4.setRuncrew(relatedRuncrew4);
}
}
// Similar logic for "relation_many"
async function associateRunCrewWithRuncrew() {
const relatedRuncrew0 = await Runcrew.findOne({
offset: Math.floor(Math.random() * (await Runcrew.count())),
});
const RunCrew0 = await RunCrews.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (RunCrew0?.setRuncrew) {
await RunCrew0.setRuncrew(relatedRuncrew0);
}
const relatedRuncrew1 = await Runcrew.findOne({
offset: Math.floor(Math.random() * (await Runcrew.count())),
});
const RunCrew1 = await RunCrews.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (RunCrew1?.setRuncrew) {
await RunCrew1.setRuncrew(relatedRuncrew1);
}
const relatedRuncrew2 = await Runcrew.findOne({
offset: Math.floor(Math.random() * (await Runcrew.count())),
});
const RunCrew2 = await RunCrews.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (RunCrew2?.setRuncrew) {
await RunCrew2.setRuncrew(relatedRuncrew2);
}
const relatedRuncrew3 = await Runcrew.findOne({
offset: Math.floor(Math.random() * (await Runcrew.count())),
});
const RunCrew3 = await RunCrews.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (RunCrew3?.setRuncrew) {
await RunCrew3.setRuncrew(relatedRuncrew3);
}
const relatedRuncrew4 = await Runcrew.findOne({
offset: Math.floor(Math.random() * (await Runcrew.count())),
});
const RunCrew4 = await RunCrews.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (RunCrew4?.setRuncrew) {
await RunCrew4.setRuncrew(relatedRuncrew4);
}
}
async function associateSessionWithRun_crew() {
const relatedRun_crew0 = await RunCrews.findOne({
offset: Math.floor(Math.random() * (await RunCrews.count())),
});
const Session0 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Session0?.setRun_crew) {
await Session0.setRun_crew(relatedRun_crew0);
}
const relatedRun_crew1 = await RunCrews.findOne({
offset: Math.floor(Math.random() * (await RunCrews.count())),
});
const Session1 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Session1?.setRun_crew) {
await Session1.setRun_crew(relatedRun_crew1);
}
const relatedRun_crew2 = await RunCrews.findOne({
offset: Math.floor(Math.random() * (await RunCrews.count())),
});
const Session2 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Session2?.setRun_crew) {
await Session2.setRun_crew(relatedRun_crew2);
}
const relatedRun_crew3 = await RunCrews.findOne({
offset: Math.floor(Math.random() * (await RunCrews.count())),
});
const Session3 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Session3?.setRun_crew) {
await Session3.setRun_crew(relatedRun_crew3);
}
const relatedRun_crew4 = await RunCrews.findOne({
offset: Math.floor(Math.random() * (await RunCrews.count())),
});
const Session4 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Session4?.setRun_crew) {
await Session4.setRun_crew(relatedRun_crew4);
}
}
async function associateSessionWithRuncrew() {
const relatedRuncrew0 = await Runcrew.findOne({
offset: Math.floor(Math.random() * (await Runcrew.count())),
});
const Session0 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Session0?.setRuncrew) {
await Session0.setRuncrew(relatedRuncrew0);
}
const relatedRuncrew1 = await Runcrew.findOne({
offset: Math.floor(Math.random() * (await Runcrew.count())),
});
const Session1 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Session1?.setRuncrew) {
await Session1.setRuncrew(relatedRuncrew1);
}
const relatedRuncrew2 = await Runcrew.findOne({
offset: Math.floor(Math.random() * (await Runcrew.count())),
});
const Session2 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Session2?.setRuncrew) {
await Session2.setRuncrew(relatedRuncrew2);
}
const relatedRuncrew3 = await Runcrew.findOne({
offset: Math.floor(Math.random() * (await Runcrew.count())),
});
const Session3 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Session3?.setRuncrew) {
await Session3.setRuncrew(relatedRuncrew3);
}
const relatedRuncrew4 = await Runcrew.findOne({
offset: Math.floor(Math.random() * (await Runcrew.count())),
});
const Session4 = await Sessions.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Session4?.setRuncrew) {
await Session4.setRuncrew(relatedRuncrew4);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Attendances.bulkCreate(AttendancesData);
await RunCrews.bulkCreate(RunCrewsData);
await Sessions.bulkCreate(SessionsData);
await Runcrew.bulkCreate(RuncrewData);
await Promise.all([
// Similar logic for "relation_many"
await associateUserWithRuncrew(),
await associateAttendanceWithSession(),
await associateAttendanceWithUser(),
await associateAttendanceWithRuncrew(),
// Similar logic for "relation_many"
await associateRunCrewWithRuncrew(),
await associateSessionWithRun_crew(),
await associateSessionWithRuncrew(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('attendances', null, {});
await queryInterface.bulkDelete('run_crews', null, {});
await queryInterface.bulkDelete('sessions', null, {});
await queryInterface.bulkDelete('runcrew', null, {});
},
};