const db = require('../models'); const Users = db.users; const Agents = db.agents; const Bookings = db.bookings; const Tours = db.tours; const Agencies = db.agencies; const Cart = db.cart; const AgentsData = [ { name: 'Alice Green', commission_rate: 0.1, // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Bob White', commission_rate: 0.12, // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Charlie Black', commission_rate: 0.15, // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Diana Blue', commission_rate: 0.08, // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const BookingsData = [ { // type code here for "relation_one" field // type code here for "relation_one" field booking_date: new Date('2023-12-01T10:00:00Z'), status: 'confirmed', // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field booking_date: new Date('2023-12-05T11:00:00Z'), status: 'confirmed', // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field booking_date: new Date('2023-12-10T12:00:00Z'), status: 'pending', // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field booking_date: new Date('2023-12-15T13:00:00Z'), status: 'pending', // type code here for "relation_one" field }, ]; const ToursData = [ { title: 'Luxury Nile Cruise', description: 'Experience the majestic Nile with our luxury cruise.', price: 1500, start_date: new Date('2024-01-15T09:00:00Z'), end_date: new Date('2024-01-22T18:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, { title: 'Sahara Desert Adventure', description: 'Explore the vast Sahara with guided tours and camel rides.', price: 1200, start_date: new Date('2024-02-10T08:00:00Z'), end_date: new Date('2024-02-17T17:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, { title: 'Historic Cairo Tour', description: 'Discover the ancient wonders of Cairo with expert guides.', price: 800, start_date: new Date('2024-03-05T09:00:00Z'), end_date: new Date('2024-03-10T18:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, { title: 'Red Sea Diving Experience', description: 'Dive into the vibrant underwater world of the Red Sea.', price: 1000, start_date: new Date('2024-04-01T09:00:00Z'), end_date: new Date('2024-04-07T18:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const AgenciesData = [ { name: 'Global Travel Co', }, { name: 'Explore Egypt', }, { name: 'Adventure Seekers', }, { name: 'Cultural Journeys', }, ]; const CartData = [ { // type code here for "relation_one" field // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field }, ]; // Similar logic for "relation_many" async function associateUserWithAgency() { const relatedAgency0 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const User0 = await Users.findOne({ order: [['id', 'ASC']], offset: 0, }); if (User0?.setAgency) { await User0.setAgency(relatedAgency0); } const relatedAgency1 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const User1 = await Users.findOne({ order: [['id', 'ASC']], offset: 1, }); if (User1?.setAgency) { await User1.setAgency(relatedAgency1); } const relatedAgency2 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const User2 = await Users.findOne({ order: [['id', 'ASC']], offset: 2, }); if (User2?.setAgency) { await User2.setAgency(relatedAgency2); } const relatedAgency3 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const User3 = await Users.findOne({ order: [['id', 'ASC']], offset: 3, }); if (User3?.setAgency) { await User3.setAgency(relatedAgency3); } } async function associateAgentWithAgency() { const relatedAgency0 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Agent0 = await Agents.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Agent0?.setAgency) { await Agent0.setAgency(relatedAgency0); } const relatedAgency1 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Agent1 = await Agents.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Agent1?.setAgency) { await Agent1.setAgency(relatedAgency1); } const relatedAgency2 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Agent2 = await Agents.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Agent2?.setAgency) { await Agent2.setAgency(relatedAgency2); } const relatedAgency3 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Agent3 = await Agents.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Agent3?.setAgency) { await Agent3.setAgency(relatedAgency3); } } async function associateAgentWithAgency() { const relatedAgency0 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Agent0 = await Agents.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Agent0?.setAgency) { await Agent0.setAgency(relatedAgency0); } const relatedAgency1 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Agent1 = await Agents.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Agent1?.setAgency) { await Agent1.setAgency(relatedAgency1); } const relatedAgency2 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Agent2 = await Agents.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Agent2?.setAgency) { await Agent2.setAgency(relatedAgency2); } const relatedAgency3 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Agent3 = await Agents.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Agent3?.setAgency) { await Agent3.setAgency(relatedAgency3); } } async function associateBookingWithTour() { const relatedTour0 = await Tours.findOne({ offset: Math.floor(Math.random() * (await Tours.count())), }); const Booking0 = await Bookings.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Booking0?.setTour) { await Booking0.setTour(relatedTour0); } const relatedTour1 = await Tours.findOne({ offset: Math.floor(Math.random() * (await Tours.count())), }); const Booking1 = await Bookings.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Booking1?.setTour) { await Booking1.setTour(relatedTour1); } const relatedTour2 = await Tours.findOne({ offset: Math.floor(Math.random() * (await Tours.count())), }); const Booking2 = await Bookings.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Booking2?.setTour) { await Booking2.setTour(relatedTour2); } const relatedTour3 = await Tours.findOne({ offset: Math.floor(Math.random() * (await Tours.count())), }); const Booking3 = await Bookings.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Booking3?.setTour) { await Booking3.setTour(relatedTour3); } } async function associateBookingWithCustomer() { const relatedCustomer0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Booking0 = await Bookings.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Booking0?.setCustomer) { await Booking0.setCustomer(relatedCustomer0); } const relatedCustomer1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Booking1 = await Bookings.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Booking1?.setCustomer) { await Booking1.setCustomer(relatedCustomer1); } const relatedCustomer2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Booking2 = await Bookings.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Booking2?.setCustomer) { await Booking2.setCustomer(relatedCustomer2); } const relatedCustomer3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Booking3 = await Bookings.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Booking3?.setCustomer) { await Booking3.setCustomer(relatedCustomer3); } } async function associateBookingWithAgency() { const relatedAgency0 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Booking0 = await Bookings.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Booking0?.setAgency) { await Booking0.setAgency(relatedAgency0); } const relatedAgency1 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Booking1 = await Bookings.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Booking1?.setAgency) { await Booking1.setAgency(relatedAgency1); } const relatedAgency2 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Booking2 = await Bookings.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Booking2?.setAgency) { await Booking2.setAgency(relatedAgency2); } const relatedAgency3 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Booking3 = await Bookings.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Booking3?.setAgency) { await Booking3.setAgency(relatedAgency3); } } async function associateTourWithAgency() { const relatedAgency0 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Tour0 = await Tours.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Tour0?.setAgency) { await Tour0.setAgency(relatedAgency0); } const relatedAgency1 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Tour1 = await Tours.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Tour1?.setAgency) { await Tour1.setAgency(relatedAgency1); } const relatedAgency2 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Tour2 = await Tours.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Tour2?.setAgency) { await Tour2.setAgency(relatedAgency2); } const relatedAgency3 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Tour3 = await Tours.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Tour3?.setAgency) { await Tour3.setAgency(relatedAgency3); } } async function associateTourWithAgency() { const relatedAgency0 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Tour0 = await Tours.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Tour0?.setAgency) { await Tour0.setAgency(relatedAgency0); } const relatedAgency1 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Tour1 = await Tours.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Tour1?.setAgency) { await Tour1.setAgency(relatedAgency1); } const relatedAgency2 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Tour2 = await Tours.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Tour2?.setAgency) { await Tour2.setAgency(relatedAgency2); } const relatedAgency3 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Tour3 = await Tours.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Tour3?.setAgency) { await Tour3.setAgency(relatedAgency3); } } async function associateCartWithAgency() { const relatedAgency0 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Cart0 = await Cart.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Cart0?.setAgency) { await Cart0.setAgency(relatedAgency0); } const relatedAgency1 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Cart1 = await Cart.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Cart1?.setAgency) { await Cart1.setAgency(relatedAgency1); } const relatedAgency2 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Cart2 = await Cart.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Cart2?.setAgency) { await Cart2.setAgency(relatedAgency2); } const relatedAgency3 = await Agencies.findOne({ offset: Math.floor(Math.random() * (await Agencies.count())), }); const Cart3 = await Cart.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Cart3?.setAgency) { await Cart3.setAgency(relatedAgency3); } } async function associateCartWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Cart0 = await Cart.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Cart0?.setUser) { await Cart0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Cart1 = await Cart.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Cart1?.setUser) { await Cart1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Cart2 = await Cart.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Cart2?.setUser) { await Cart2.setUser(relatedUser2); } const relatedUser3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Cart3 = await Cart.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Cart3?.setUser) { await Cart3.setUser(relatedUser3); } } module.exports = { up: async (queryInterface, Sequelize) => { await Agents.bulkCreate(AgentsData); await Bookings.bulkCreate(BookingsData); await Tours.bulkCreate(ToursData); await Agencies.bulkCreate(AgenciesData); await Cart.bulkCreate(CartData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithAgency(), await associateAgentWithAgency(), await associateAgentWithAgency(), await associateBookingWithTour(), await associateBookingWithCustomer(), await associateBookingWithAgency(), await associateTourWithAgency(), await associateTourWithAgency(), await associateCartWithAgency(), await associateCartWithUser(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('agents', null, {}); await queryInterface.bulkDelete('bookings', null, {}); await queryInterface.bulkDelete('tours', null, {}); await queryInterface.bulkDelete('agencies', null, {}); await queryInterface.bulkDelete('cart', null, {}); }, };