const db = require('../models'); const Users = db.users; const Messages = db.messages; const Notifications = db.notifications; const MessagesData = [ { content: 'Meeting scheduled for tomorrow at 10 AM.', // type code here for "relation_one" field // type code here for "relation_many" field sent_at: new Date('2023-10-01T10:00:00Z'), }, { content: 'Project deadline extended to next Friday.', // type code here for "relation_one" field // type code here for "relation_many" field sent_at: new Date('2023-10-02T14:30:00Z'), }, { content: 'Please review the attached document.', // type code here for "relation_one" field // type code here for "relation_many" field sent_at: new Date('2023-10-03T09:15:00Z'), }, ]; const NotificationsData = [ { title: 'System Maintenance', message: 'Scheduled maintenance on Saturday from 2 AM to 4 AM.', // type code here for "relation_many" field broadcasted_at: new Date('2023-10-01T08:00:00Z'), }, { title: 'New Feature Release', message: 'Check out the new dashboard features available now.', // type code here for "relation_many" field broadcasted_at: new Date('2023-10-02T12:00:00Z'), }, { title: 'Security Update', message: 'Please update your passwords regularly to ensure security.', // type code here for "relation_many" field broadcasted_at: new Date('2023-10-03T15:00:00Z'), }, ]; // Similar logic for "relation_many" async function associateMessageWithSender() { const relatedSender0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Message0 = await Messages.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Message0?.setSender) { await Message0.setSender(relatedSender0); } const relatedSender1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Message1 = await Messages.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Message1?.setSender) { await Message1.setSender(relatedSender1); } const relatedSender2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Message2 = await Messages.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Message2?.setSender) { await Message2.setSender(relatedSender2); } } // Similar logic for "relation_many" // Similar logic for "relation_many" module.exports = { up: async (queryInterface, Sequelize) => { await Messages.bulkCreate(MessagesData); await Notifications.bulkCreate(NotificationsData); await Promise.all([ // Similar logic for "relation_many" await associateMessageWithSender(), // Similar logic for "relation_many" // Similar logic for "relation_many" ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('messages', null, {}); await queryInterface.bulkDelete('notifications', null, {}); }, };