const db = require('../models'); const Users = db.users; const DriverProfiles = db.driver_profiles; const Payments = db.payments; const Reviews = db.reviews; const Rides = db.rides; const Vehicles = db.vehicles; const Messagerie = db.messagerie; const Organizations = db.organizations; const DriverProfilesData = [ { license_number: 'DL123456789', vehicle_info: 'Toyota Prius 2018', // type code here for "relation_one" field // type code here for "relation_one" field }, { license_number: 'DL987654321', vehicle_info: 'Honda Accord 2020', // type code here for "relation_one" field // type code here for "relation_one" field }, { license_number: 'DL112233445', vehicle_info: 'Ford Focus 2019', // type code here for "relation_one" field // type code here for "relation_one" field }, { license_number: 'DL556677889', vehicle_info: 'Chevrolet Bolt 2021', // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const PaymentsData = [ { // type code here for "relation_one" field amount: 25.5, status: 'pending', payment_method: 'credit_card', // type code here for "relation_one" field }, { // type code here for "relation_one" field amount: 30, status: 'completed', payment_method: 'paypal', // type code here for "relation_one" field }, { // type code here for "relation_one" field amount: 15.75, status: 'failed', payment_method: 'cash', // type code here for "relation_one" field }, { // type code here for "relation_one" field amount: 22, status: 'pending', payment_method: 'credit_card', // type code here for "relation_one" field }, ]; const ReviewsData = [ { // type code here for "relation_one" field rating: 5, comment: 'Great ride, very comfortable.', // type code here for "relation_one" field }, { // type code here for "relation_one" field rating: 4, comment: 'Driver was friendly and on time.', // type code here for "relation_one" field }, { // type code here for "relation_one" field rating: 3, comment: 'Average experience, nothing special.', // type code here for "relation_one" field }, { // type code here for "relation_one" field rating: 5, comment: 'Excellent service, highly recommend.', // type code here for "relation_one" field }, ]; const RidesData = [ { // type code here for "relation_one" field // type code here for "relation_one" field pickup_location: '123 Main St', dropoff_location: '456 Elm St', status: 'pending', pickup_time: new Date('2023-10-01T08:00:00Z'), dropoff_time: new Date('2023-10-01T08:30:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field pickup_location: '789 Oak St', dropoff_location: '101 Pine St', status: 'completed', pickup_time: new Date('2023-10-02T09:00:00Z'), dropoff_time: new Date('2023-10-02T09:45:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field pickup_location: '202 Birch St', dropoff_location: '303 Cedar St', status: 'ongoing', pickup_time: new Date('2023-10-03T10:00:00Z'), dropoff_time: new Date('2023-10-03T10:30:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field pickup_location: '404 Maple St', dropoff_location: '505 Walnut St', status: 'completed', pickup_time: new Date('2023-10-04T11:00:00Z'), dropoff_time: new Date('2023-10-04T11:30:00Z'), // type code here for "relation_one" field }, ]; const VehiclesData = [ { model: 'Toyota Prius', type: 'Hybrid', license_plate: 'ABC123', // type code here for "relation_one" field }, { model: 'Honda Accord', type: 'Sedan', license_plate: 'XYZ789', // type code here for "relation_one" field }, { model: 'Ford Focus', type: 'Hatchback', license_plate: 'LMN456', // type code here for "relation_one" field }, { model: 'Chevrolet Bolt', type: 'Electric', license_plate: 'QRS678', // type code here for "relation_one" field }, ]; const MessagerieData = [ { // 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 }, ]; const OrganizationsData = [ { name: 'Pierre Simon de Laplace', }, { name: 'Lucretius', }, { name: 'Sigmund Freud', }, { name: 'William Herschel', }, ]; // Similar logic for "relation_many" async function associateUserWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const User0 = await Users.findOne({ order: [['id', 'ASC']], offset: 0, }); if (User0?.setOrganization) { await User0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const User1 = await Users.findOne({ order: [['id', 'ASC']], offset: 1, }); if (User1?.setOrganization) { await User1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const User2 = await Users.findOne({ order: [['id', 'ASC']], offset: 2, }); if (User2?.setOrganization) { await User2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const User3 = await Users.findOne({ order: [['id', 'ASC']], offset: 3, }); if (User3?.setOrganization) { await User3.setOrganization(relatedOrganization3); } } async function associateDriverProfileWithVehicle() { const relatedVehicle0 = await Vehicles.findOne({ offset: Math.floor(Math.random() * (await Vehicles.count())), }); const DriverProfile0 = await DriverProfiles.findOne({ order: [['id', 'ASC']], offset: 0, }); if (DriverProfile0?.setVehicle) { await DriverProfile0.setVehicle(relatedVehicle0); } const relatedVehicle1 = await Vehicles.findOne({ offset: Math.floor(Math.random() * (await Vehicles.count())), }); const DriverProfile1 = await DriverProfiles.findOne({ order: [['id', 'ASC']], offset: 1, }); if (DriverProfile1?.setVehicle) { await DriverProfile1.setVehicle(relatedVehicle1); } const relatedVehicle2 = await Vehicles.findOne({ offset: Math.floor(Math.random() * (await Vehicles.count())), }); const DriverProfile2 = await DriverProfiles.findOne({ order: [['id', 'ASC']], offset: 2, }); if (DriverProfile2?.setVehicle) { await DriverProfile2.setVehicle(relatedVehicle2); } const relatedVehicle3 = await Vehicles.findOne({ offset: Math.floor(Math.random() * (await Vehicles.count())), }); const DriverProfile3 = await DriverProfiles.findOne({ order: [['id', 'ASC']], offset: 3, }); if (DriverProfile3?.setVehicle) { await DriverProfile3.setVehicle(relatedVehicle3); } } async function associateDriverProfileWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const DriverProfile0 = await DriverProfiles.findOne({ order: [['id', 'ASC']], offset: 0, }); if (DriverProfile0?.setOrganization) { await DriverProfile0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const DriverProfile1 = await DriverProfiles.findOne({ order: [['id', 'ASC']], offset: 1, }); if (DriverProfile1?.setOrganization) { await DriverProfile1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const DriverProfile2 = await DriverProfiles.findOne({ order: [['id', 'ASC']], offset: 2, }); if (DriverProfile2?.setOrganization) { await DriverProfile2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const DriverProfile3 = await DriverProfiles.findOne({ order: [['id', 'ASC']], offset: 3, }); if (DriverProfile3?.setOrganization) { await DriverProfile3.setOrganization(relatedOrganization3); } } async function associatePaymentWithRide() { const relatedRide0 = await Rides.findOne({ offset: Math.floor(Math.random() * (await Rides.count())), }); const Payment0 = await Payments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Payment0?.setRide) { await Payment0.setRide(relatedRide0); } const relatedRide1 = await Rides.findOne({ offset: Math.floor(Math.random() * (await Rides.count())), }); const Payment1 = await Payments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Payment1?.setRide) { await Payment1.setRide(relatedRide1); } const relatedRide2 = await Rides.findOne({ offset: Math.floor(Math.random() * (await Rides.count())), }); const Payment2 = await Payments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Payment2?.setRide) { await Payment2.setRide(relatedRide2); } const relatedRide3 = await Rides.findOne({ offset: Math.floor(Math.random() * (await Rides.count())), }); const Payment3 = await Payments.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Payment3?.setRide) { await Payment3.setRide(relatedRide3); } } async function associatePaymentWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Payment0 = await Payments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Payment0?.setOrganization) { await Payment0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Payment1 = await Payments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Payment1?.setOrganization) { await Payment1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Payment2 = await Payments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Payment2?.setOrganization) { await Payment2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Payment3 = await Payments.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Payment3?.setOrganization) { await Payment3.setOrganization(relatedOrganization3); } } async function associateReviewWithRide() { const relatedRide0 = await Rides.findOne({ offset: Math.floor(Math.random() * (await Rides.count())), }); const Review0 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Review0?.setRide) { await Review0.setRide(relatedRide0); } const relatedRide1 = await Rides.findOne({ offset: Math.floor(Math.random() * (await Rides.count())), }); const Review1 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Review1?.setRide) { await Review1.setRide(relatedRide1); } const relatedRide2 = await Rides.findOne({ offset: Math.floor(Math.random() * (await Rides.count())), }); const Review2 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Review2?.setRide) { await Review2.setRide(relatedRide2); } const relatedRide3 = await Rides.findOne({ offset: Math.floor(Math.random() * (await Rides.count())), }); const Review3 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Review3?.setRide) { await Review3.setRide(relatedRide3); } } async function associateReviewWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Review0 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Review0?.setOrganization) { await Review0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Review1 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Review1?.setOrganization) { await Review1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Review2 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Review2?.setOrganization) { await Review2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Review3 = await Reviews.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Review3?.setOrganization) { await Review3.setOrganization(relatedOrganization3); } } async function associateRideWithPassenger() { const relatedPassenger0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Ride0 = await Rides.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Ride0?.setPassenger) { await Ride0.setPassenger(relatedPassenger0); } const relatedPassenger1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Ride1 = await Rides.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Ride1?.setPassenger) { await Ride1.setPassenger(relatedPassenger1); } const relatedPassenger2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Ride2 = await Rides.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Ride2?.setPassenger) { await Ride2.setPassenger(relatedPassenger2); } const relatedPassenger3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Ride3 = await Rides.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Ride3?.setPassenger) { await Ride3.setPassenger(relatedPassenger3); } } async function associateRideWithDriver() { const relatedDriver0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Ride0 = await Rides.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Ride0?.setDriver) { await Ride0.setDriver(relatedDriver0); } const relatedDriver1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Ride1 = await Rides.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Ride1?.setDriver) { await Ride1.setDriver(relatedDriver1); } const relatedDriver2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Ride2 = await Rides.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Ride2?.setDriver) { await Ride2.setDriver(relatedDriver2); } const relatedDriver3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Ride3 = await Rides.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Ride3?.setDriver) { await Ride3.setDriver(relatedDriver3); } } async function associateRideWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Ride0 = await Rides.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Ride0?.setOrganization) { await Ride0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Ride1 = await Rides.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Ride1?.setOrganization) { await Ride1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Ride2 = await Rides.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Ride2?.setOrganization) { await Ride2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Ride3 = await Rides.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Ride3?.setOrganization) { await Ride3.setOrganization(relatedOrganization3); } } async function associateVehicleWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Vehicle0 = await Vehicles.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Vehicle0?.setOrganization) { await Vehicle0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Vehicle1 = await Vehicles.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Vehicle1?.setOrganization) { await Vehicle1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Vehicle2 = await Vehicles.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Vehicle2?.setOrganization) { await Vehicle2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Vehicle3 = await Vehicles.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Vehicle3?.setOrganization) { await Vehicle3.setOrganization(relatedOrganization3); } } async function associateMessagerieWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Messagerie0 = await Messagerie.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Messagerie0?.setOrganization) { await Messagerie0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Messagerie1 = await Messagerie.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Messagerie1?.setOrganization) { await Messagerie1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Messagerie2 = await Messagerie.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Messagerie2?.setOrganization) { await Messagerie2.setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Messagerie3 = await Messagerie.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Messagerie3?.setOrganization) { await Messagerie3.setOrganization(relatedOrganization3); } } module.exports = { up: async (queryInterface, Sequelize) => { await DriverProfiles.bulkCreate(DriverProfilesData); await Payments.bulkCreate(PaymentsData); await Reviews.bulkCreate(ReviewsData); await Rides.bulkCreate(RidesData); await Vehicles.bulkCreate(VehiclesData); await Messagerie.bulkCreate(MessagerieData); await Organizations.bulkCreate(OrganizationsData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithOrganization(), await associateDriverProfileWithVehicle(), await associateDriverProfileWithOrganization(), await associatePaymentWithRide(), await associatePaymentWithOrganization(), await associateReviewWithRide(), await associateReviewWithOrganization(), await associateRideWithPassenger(), await associateRideWithDriver(), await associateRideWithOrganization(), await associateVehicleWithOrganization(), await associateMessagerieWithOrganization(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('driver_profiles', null, {}); await queryInterface.bulkDelete('payments', null, {}); await queryInterface.bulkDelete('reviews', null, {}); await queryInterface.bulkDelete('rides', null, {}); await queryInterface.bulkDelete('vehicles', null, {}); await queryInterface.bulkDelete('messagerie', null, {}); await queryInterface.bulkDelete('organizations', null, {}); }, };