const db = require('../models'); const Users = db.users; const BookingRequests = db.booking_requests; const Rooms = db.rooms; const BookingRequestsData = [ { // type code here for "relation_one" field // type code here for "relation_one" field start_date: new Date('2023-11-01T14:00:00Z'), end_date: new Date('2023-11-05T11:00:00Z'), status: 'Confirmed', guest_name: 'Max von Laue', guest_company: 'Isaac Newton', guest_phone: 'B. F. Skinner', }, { // type code here for "relation_one" field // type code here for "relation_one" field start_date: new Date('2023-11-10T14:00:00Z'), end_date: new Date('2023-11-15T11:00:00Z'), status: 'Pending', guest_name: 'Erwin Schrodinger', guest_company: 'John Bardeen', guest_phone: 'John Bardeen', }, { // type code here for "relation_one" field // type code here for "relation_one" field start_date: new Date('2023-11-20T14:00:00Z'), end_date: new Date('2023-11-25T11:00:00Z'), status: 'Confirmed', guest_name: 'Linus Pauling', guest_company: 'Antoine Laurent Lavoisier', guest_phone: 'Edwin Hubble', }, { // type code here for "relation_one" field // type code here for "relation_one" field start_date: new Date('2023-12-01T14:00:00Z'), end_date: new Date('2023-12-05T11:00:00Z'), status: 'Rejected', guest_name: 'Charles Darwin', guest_company: 'Frederick Sanger', guest_phone: 'Carl Linnaeus', }, { // type code here for "relation_one" field // type code here for "relation_one" field start_date: new Date('2023-12-10T14:00:00Z'), end_date: new Date('2023-12-15T11:00:00Z'), status: 'Pending', guest_name: 'Max Delbruck', guest_company: 'Trofim Lysenko', guest_phone: 'Louis Victor de Broglie', }, ]; const RoomsData = [ { block: 'Block 1', room_number: 101, bed_type: 'Bed-1', }, { block: 'Block 1', room_number: 102, bed_type: 'Bed-1', }, { block: 'Block 1', room_number: 102, bed_type: 'Bed-1', }, { block: 'Block 2', room_number: 201, bed_type: 'SingleBed', }, { block: 'Block 2', room_number: 201, bed_type: 'Bed-2', }, ]; // Similar logic for "relation_many" async function associateBookingRequestWithGuest() { const relatedGuest0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const BookingRequest0 = await BookingRequests.findOne({ order: [['id', 'ASC']], offset: 0, }); if (BookingRequest0?.setGuest) { await BookingRequest0.setGuest(relatedGuest0); } const relatedGuest1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const BookingRequest1 = await BookingRequests.findOne({ order: [['id', 'ASC']], offset: 1, }); if (BookingRequest1?.setGuest) { await BookingRequest1.setGuest(relatedGuest1); } const relatedGuest2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const BookingRequest2 = await BookingRequests.findOne({ order: [['id', 'ASC']], offset: 2, }); if (BookingRequest2?.setGuest) { await BookingRequest2.setGuest(relatedGuest2); } const relatedGuest3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const BookingRequest3 = await BookingRequests.findOne({ order: [['id', 'ASC']], offset: 3, }); if (BookingRequest3?.setGuest) { await BookingRequest3.setGuest(relatedGuest3); } const relatedGuest4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const BookingRequest4 = await BookingRequests.findOne({ order: [['id', 'ASC']], offset: 4, }); if (BookingRequest4?.setGuest) { await BookingRequest4.setGuest(relatedGuest4); } } async function associateBookingRequestWithRoom() { const relatedRoom0 = await Rooms.findOne({ offset: Math.floor(Math.random() * (await Rooms.count())), }); const BookingRequest0 = await BookingRequests.findOne({ order: [['id', 'ASC']], offset: 0, }); if (BookingRequest0?.setRoom) { await BookingRequest0.setRoom(relatedRoom0); } const relatedRoom1 = await Rooms.findOne({ offset: Math.floor(Math.random() * (await Rooms.count())), }); const BookingRequest1 = await BookingRequests.findOne({ order: [['id', 'ASC']], offset: 1, }); if (BookingRequest1?.setRoom) { await BookingRequest1.setRoom(relatedRoom1); } const relatedRoom2 = await Rooms.findOne({ offset: Math.floor(Math.random() * (await Rooms.count())), }); const BookingRequest2 = await BookingRequests.findOne({ order: [['id', 'ASC']], offset: 2, }); if (BookingRequest2?.setRoom) { await BookingRequest2.setRoom(relatedRoom2); } const relatedRoom3 = await Rooms.findOne({ offset: Math.floor(Math.random() * (await Rooms.count())), }); const BookingRequest3 = await BookingRequests.findOne({ order: [['id', 'ASC']], offset: 3, }); if (BookingRequest3?.setRoom) { await BookingRequest3.setRoom(relatedRoom3); } const relatedRoom4 = await Rooms.findOne({ offset: Math.floor(Math.random() * (await Rooms.count())), }); const BookingRequest4 = await BookingRequests.findOne({ order: [['id', 'ASC']], offset: 4, }); if (BookingRequest4?.setRoom) { await BookingRequest4.setRoom(relatedRoom4); } } module.exports = { up: async (queryInterface, Sequelize) => { await BookingRequests.bulkCreate(BookingRequestsData); await Rooms.bulkCreate(RoomsData); await Promise.all([ // Similar logic for "relation_many" await associateBookingRequestWithGuest(), await associateBookingRequestWithRoom(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('booking_requests', null, {}); await queryInterface.bulkDelete('rooms', null, {}); }, };