const db = require('../models'); const Users = db.users; const Events = db.events; const EventPasses = db.event_passes; const Clubs = db.clubs; const EventsData = [ { title: 'Tech Expo 2023', description: 'An exhibition showcasing the latest in technology.', start_date: new Date('2023-11-01T10:00:00Z'), end_date: new Date('2023-11-01T18:00:00Z'), // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Green Earth Day', description: 'An event to promote environmental awareness.', start_date: new Date('2023-04-22T09:00:00Z'), end_date: new Date('2023-04-22T17:00:00Z'), // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Art Fest', description: 'A festival celebrating various forms of art.', start_date: new Date('2023-06-15T11:00:00Z'), end_date: new Date('2023-06-15T20:00:00Z'), // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Music Fest', description: 'A festival featuring live music performances.', start_date: new Date('2023-08-10T15:00:00Z'), end_date: new Date('2023-08-10T23:00:00Z'), // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Sports Meet', description: 'A gathering for sports competitions and activities.', start_date: new Date('2023-09-05T08:00:00Z'), end_date: new Date('2023-09-05T18:00:00Z'), // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const EventPassesData = [ { // type code here for "relation_one" field // type code here for "relation_one" field issue_date: new Date('2023-10-25T12:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field issue_date: new Date('2023-04-15T12:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field issue_date: new Date('2023-06-01T12:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field issue_date: new Date('2023-08-01T12:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field issue_date: new Date('2023-09-01T12:00:00Z'), // type code here for "relation_one" field }, ]; const ClubsData = [ { name: 'Green Club', }, { name: 'Tech Innovators', }, { name: 'Art Lovers', }, { name: 'Music Mania', }, { name: 'Sports Enthusiasts', }, ]; // Similar logic for "relation_many" async function associateUserWithClub() { const relatedClub0 = await Clubs.findOne({ offset: Math.floor(Math.random() * (await Clubs.count())), }); const User0 = await Users.findOne({ order: [['id', 'ASC']], offset: 0, }); if (User0?.setClub) { await User0.setClub(relatedClub0); } const relatedClub1 = await Clubs.findOne({ offset: Math.floor(Math.random() * (await Clubs.count())), }); const User1 = await Users.findOne({ order: [['id', 'ASC']], offset: 1, }); if (User1?.setClub) { await User1.setClub(relatedClub1); } const relatedClub2 = await Clubs.findOne({ offset: Math.floor(Math.random() * (await Clubs.count())), }); const User2 = await Users.findOne({ order: [['id', 'ASC']], offset: 2, }); if (User2?.setClub) { await User2.setClub(relatedClub2); } const relatedClub3 = await Clubs.findOne({ offset: Math.floor(Math.random() * (await Clubs.count())), }); const User3 = await Users.findOne({ order: [['id', 'ASC']], offset: 3, }); if (User3?.setClub) { await User3.setClub(relatedClub3); } const relatedClub4 = await Clubs.findOne({ offset: Math.floor(Math.random() * (await Clubs.count())), }); const User4 = await Users.findOne({ order: [['id', 'ASC']], offset: 4, }); if (User4?.setClub) { await User4.setClub(relatedClub4); } } async function associateEventWithClub() { const relatedClub0 = await Clubs.findOne({ offset: Math.floor(Math.random() * (await Clubs.count())), }); const Event0 = await Events.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Event0?.setClub) { await Event0.setClub(relatedClub0); } const relatedClub1 = await Clubs.findOne({ offset: Math.floor(Math.random() * (await Clubs.count())), }); const Event1 = await Events.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Event1?.setClub) { await Event1.setClub(relatedClub1); } const relatedClub2 = await Clubs.findOne({ offset: Math.floor(Math.random() * (await Clubs.count())), }); const Event2 = await Events.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Event2?.setClub) { await Event2.setClub(relatedClub2); } const relatedClub3 = await Clubs.findOne({ offset: Math.floor(Math.random() * (await Clubs.count())), }); const Event3 = await Events.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Event3?.setClub) { await Event3.setClub(relatedClub3); } const relatedClub4 = await Clubs.findOne({ offset: Math.floor(Math.random() * (await Clubs.count())), }); const Event4 = await Events.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Event4?.setClub) { await Event4.setClub(relatedClub4); } } // Similar logic for "relation_many" async function associateEventWithClub() { const relatedClub0 = await Clubs.findOne({ offset: Math.floor(Math.random() * (await Clubs.count())), }); const Event0 = await Events.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Event0?.setClub) { await Event0.setClub(relatedClub0); } const relatedClub1 = await Clubs.findOne({ offset: Math.floor(Math.random() * (await Clubs.count())), }); const Event1 = await Events.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Event1?.setClub) { await Event1.setClub(relatedClub1); } const relatedClub2 = await Clubs.findOne({ offset: Math.floor(Math.random() * (await Clubs.count())), }); const Event2 = await Events.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Event2?.setClub) { await Event2.setClub(relatedClub2); } const relatedClub3 = await Clubs.findOne({ offset: Math.floor(Math.random() * (await Clubs.count())), }); const Event3 = await Events.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Event3?.setClub) { await Event3.setClub(relatedClub3); } const relatedClub4 = await Clubs.findOne({ offset: Math.floor(Math.random() * (await Clubs.count())), }); const Event4 = await Events.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Event4?.setClub) { await Event4.setClub(relatedClub4); } } async function associateEventPassWithEvent() { const relatedEvent0 = await Events.findOne({ offset: Math.floor(Math.random() * (await Events.count())), }); const EventPass0 = await EventPasses.findOne({ order: [['id', 'ASC']], offset: 0, }); if (EventPass0?.setEvent) { await EventPass0.setEvent(relatedEvent0); } const relatedEvent1 = await Events.findOne({ offset: Math.floor(Math.random() * (await Events.count())), }); const EventPass1 = await EventPasses.findOne({ order: [['id', 'ASC']], offset: 1, }); if (EventPass1?.setEvent) { await EventPass1.setEvent(relatedEvent1); } const relatedEvent2 = await Events.findOne({ offset: Math.floor(Math.random() * (await Events.count())), }); const EventPass2 = await EventPasses.findOne({ order: [['id', 'ASC']], offset: 2, }); if (EventPass2?.setEvent) { await EventPass2.setEvent(relatedEvent2); } const relatedEvent3 = await Events.findOne({ offset: Math.floor(Math.random() * (await Events.count())), }); const EventPass3 = await EventPasses.findOne({ order: [['id', 'ASC']], offset: 3, }); if (EventPass3?.setEvent) { await EventPass3.setEvent(relatedEvent3); } const relatedEvent4 = await Events.findOne({ offset: Math.floor(Math.random() * (await Events.count())), }); const EventPass4 = await EventPasses.findOne({ order: [['id', 'ASC']], offset: 4, }); if (EventPass4?.setEvent) { await EventPass4.setEvent(relatedEvent4); } } async function associateEventPassWithVisitor() { const relatedVisitor0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const EventPass0 = await EventPasses.findOne({ order: [['id', 'ASC']], offset: 0, }); if (EventPass0?.setVisitor) { await EventPass0.setVisitor(relatedVisitor0); } const relatedVisitor1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const EventPass1 = await EventPasses.findOne({ order: [['id', 'ASC']], offset: 1, }); if (EventPass1?.setVisitor) { await EventPass1.setVisitor(relatedVisitor1); } const relatedVisitor2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const EventPass2 = await EventPasses.findOne({ order: [['id', 'ASC']], offset: 2, }); if (EventPass2?.setVisitor) { await EventPass2.setVisitor(relatedVisitor2); } const relatedVisitor3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const EventPass3 = await EventPasses.findOne({ order: [['id', 'ASC']], offset: 3, }); if (EventPass3?.setVisitor) { await EventPass3.setVisitor(relatedVisitor3); } const relatedVisitor4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const EventPass4 = await EventPasses.findOne({ order: [['id', 'ASC']], offset: 4, }); if (EventPass4?.setVisitor) { await EventPass4.setVisitor(relatedVisitor4); } } async function associateEventPassWithClub() { const relatedClub0 = await Clubs.findOne({ offset: Math.floor(Math.random() * (await Clubs.count())), }); const EventPass0 = await EventPasses.findOne({ order: [['id', 'ASC']], offset: 0, }); if (EventPass0?.setClub) { await EventPass0.setClub(relatedClub0); } const relatedClub1 = await Clubs.findOne({ offset: Math.floor(Math.random() * (await Clubs.count())), }); const EventPass1 = await EventPasses.findOne({ order: [['id', 'ASC']], offset: 1, }); if (EventPass1?.setClub) { await EventPass1.setClub(relatedClub1); } const relatedClub2 = await Clubs.findOne({ offset: Math.floor(Math.random() * (await Clubs.count())), }); const EventPass2 = await EventPasses.findOne({ order: [['id', 'ASC']], offset: 2, }); if (EventPass2?.setClub) { await EventPass2.setClub(relatedClub2); } const relatedClub3 = await Clubs.findOne({ offset: Math.floor(Math.random() * (await Clubs.count())), }); const EventPass3 = await EventPasses.findOne({ order: [['id', 'ASC']], offset: 3, }); if (EventPass3?.setClub) { await EventPass3.setClub(relatedClub3); } const relatedClub4 = await Clubs.findOne({ offset: Math.floor(Math.random() * (await Clubs.count())), }); const EventPass4 = await EventPasses.findOne({ order: [['id', 'ASC']], offset: 4, }); if (EventPass4?.setClub) { await EventPass4.setClub(relatedClub4); } } module.exports = { up: async (queryInterface, Sequelize) => { await Events.bulkCreate(EventsData); await EventPasses.bulkCreate(EventPassesData); await Clubs.bulkCreate(ClubsData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithClub(), await associateEventWithClub(), // Similar logic for "relation_many" await associateEventWithClub(), await associateEventPassWithEvent(), await associateEventPassWithVisitor(), await associateEventPassWithClub(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('events', null, {}); await queryInterface.bulkDelete('event_passes', null, {}); await queryInterface.bulkDelete('clubs', null, {}); }, };