const db = require('../models'); const Users = db.users; const Categories = db.categories; const Events = db.events; const Maps = db.maps; const Notifications = db.notifications; const CategoriesData = [ { name: 'Politics', description: 'Events related to political activities and discussions.', }, { name: 'Protests', description: 'Events related to public demonstrations and protests.', }, { name: 'Community', description: 'Events related to community gatherings and meetings.', }, { name: 'Environment', description: 'Events related to environmental awareness and actions.', }, { name: 'Healthcare', description: 'Events related to healthcare policies and forums.', }, ]; const EventsData = [ { title: 'State Election Debate', description: 'A debate between candidates for the upcoming state election.', start_date: new Date('2023-11-01T18:00:00Z'), end_date: new Date('2023-11-01T20:00:00Z'), status: 'unverified', // type code here for "relation_many" field }, { title: 'County Fair Protest', description: 'Protest against the new county fair regulations.', start_date: new Date('2023-11-05T10:00:00Z'), end_date: new Date('2023-11-05T12:00:00Z'), status: 'unverified', // type code here for "relation_many" field }, { title: 'City Council Meeting', description: 'Discussion on the new city development plan.', start_date: new Date('2023-11-10T15:00:00Z'), end_date: new Date('2023-11-10T17:00:00Z'), status: 'unverified', // type code here for "relation_many" field }, { title: 'Environmental Awareness Rally', description: 'Rally to promote environmental awareness in the community.', start_date: new Date('2023-11-15T09:00:00Z'), end_date: new Date('2023-11-15T11:00:00Z'), status: 'verified', // type code here for "relation_many" field }, { title: 'Healthcare Policy Forum', description: 'Forum to discuss the new healthcare policies.', start_date: new Date('2023-11-20T14:00:00Z'), end_date: new Date('2023-11-20T16:00:00Z'), status: 'verified', // type code here for "relation_many" field }, ]; const MapsData = [ { state: 'California', county: 'Los Angeles', // type code here for "relation_many" field }, { state: 'Texas', county: 'Travis', // type code here for "relation_many" field }, { state: 'New York', county: 'Kings', // type code here for "relation_many" field }, { state: 'Florida', county: 'Miami-Dade', // type code here for "relation_many" field }, { state: 'Illinois', county: 'Cook', // type code here for "relation_many" field }, ]; const NotificationsData = [ { message: 'New event: State Election Debate', // type code here for "relation_one" field // type code here for "relation_one" field read: true, }, { message: 'New event: County Fair Protest', // type code here for "relation_one" field // type code here for "relation_one" field read: false, }, { message: 'New event: City Council Meeting', // type code here for "relation_one" field // type code here for "relation_one" field read: true, }, { message: 'New event: Environmental Awareness Rally', // type code here for "relation_one" field // type code here for "relation_one" field read: true, }, { message: 'New event: Healthcare Policy Forum', // type code here for "relation_one" field // type code here for "relation_one" field read: true, }, ]; // Similar logic for "relation_many" // Similar logic for "relation_many" // Similar logic for "relation_many" async function associateNotificationWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Notification0 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Notification0?.setUser) { await Notification0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Notification1 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Notification1?.setUser) { await Notification1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Notification2 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Notification2?.setUser) { await Notification2.setUser(relatedUser2); } const relatedUser3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Notification3 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Notification3?.setUser) { await Notification3.setUser(relatedUser3); } const relatedUser4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Notification4 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Notification4?.setUser) { await Notification4.setUser(relatedUser4); } } async function associateNotificationWithEvent() { const relatedEvent0 = await Events.findOne({ offset: Math.floor(Math.random() * (await Events.count())), }); const Notification0 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Notification0?.setEvent) { await Notification0.setEvent(relatedEvent0); } const relatedEvent1 = await Events.findOne({ offset: Math.floor(Math.random() * (await Events.count())), }); const Notification1 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Notification1?.setEvent) { await Notification1.setEvent(relatedEvent1); } const relatedEvent2 = await Events.findOne({ offset: Math.floor(Math.random() * (await Events.count())), }); const Notification2 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Notification2?.setEvent) { await Notification2.setEvent(relatedEvent2); } const relatedEvent3 = await Events.findOne({ offset: Math.floor(Math.random() * (await Events.count())), }); const Notification3 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Notification3?.setEvent) { await Notification3.setEvent(relatedEvent3); } const relatedEvent4 = await Events.findOne({ offset: Math.floor(Math.random() * (await Events.count())), }); const Notification4 = await Notifications.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Notification4?.setEvent) { await Notification4.setEvent(relatedEvent4); } } module.exports = { up: async (queryInterface, Sequelize) => { await Categories.bulkCreate(CategoriesData); await Events.bulkCreate(EventsData); await Maps.bulkCreate(MapsData); await Notifications.bulkCreate(NotificationsData); await Promise.all([ // Similar logic for "relation_many" // Similar logic for "relation_many" // Similar logic for "relation_many" await associateNotificationWithUser(), await associateNotificationWithEvent(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('categories', null, {}); await queryInterface.bulkDelete('events', null, {}); await queryInterface.bulkDelete('maps', null, {}); await queryInterface.bulkDelete('notifications', null, {}); }, };