const db = require('../models'); const Users = db.users; const Bookings = db.bookings; const Languages = db.languages; const Skills = db.skills; const BookingsData = [ { // type code here for "relation_one" field // type code here for "relation_one" field booking_date: new Date('2023-10-01T10:00:00Z'), start_time: new Date('2023-10-01T10:00:00Z'), end_time: new Date('2023-10-01T12:00:00Z'), address: '123 Street, Delhi', total_price: 1000, status: 'pending', }, { // type code here for "relation_one" field // type code here for "relation_one" field booking_date: new Date('2023-10-02T14:00:00Z'), start_time: new Date('2023-10-02T14:00:00Z'), end_time: new Date('2023-10-02T16:00:00Z'), address: '456 Avenue, Mumbai', total_price: 1000, status: 'cancelled', }, { // type code here for "relation_one" field // type code here for "relation_one" field booking_date: new Date('2023-10-03T09:00:00Z'), start_time: new Date('2023-10-03T09:00:00Z'), end_time: new Date('2023-10-03T11:00:00Z'), address: '789 Boulevard, Bangalore', total_price: 600, status: 'completed', }, ]; const LanguagesData = [ { language_name: 'Hindi', }, { language_name: 'English', }, { language_name: 'Marathi', }, ]; const SkillsData = [ { skill_name: 'Certified Plumber', }, { skill_name: 'Certified Electrician', }, { skill_name: 'Certified Gardener', }, ]; // Similar logic for "relation_many" async function associateBookingWithService_provider() { const relatedService_provider0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Booking0 = await Bookings.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Booking0?.setService_provider) { await Booking0.setService_provider(relatedService_provider0); } const relatedService_provider1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Booking1 = await Bookings.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Booking1?.setService_provider) { await Booking1.setService_provider(relatedService_provider1); } const relatedService_provider2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Booking2 = await Bookings.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Booking2?.setService_provider) { await Booking2.setService_provider(relatedService_provider2); } } async function associateBookingWithService_taker() { const relatedService_taker0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Booking0 = await Bookings.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Booking0?.setService_taker) { await Booking0.setService_taker(relatedService_taker0); } const relatedService_taker1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Booking1 = await Bookings.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Booking1?.setService_taker) { await Booking1.setService_taker(relatedService_taker1); } const relatedService_taker2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Booking2 = await Bookings.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Booking2?.setService_taker) { await Booking2.setService_taker(relatedService_taker2); } } module.exports = { up: async (queryInterface, Sequelize) => { await Bookings.bulkCreate(BookingsData); await Languages.bulkCreate(LanguagesData); await Skills.bulkCreate(SkillsData); await Promise.all([ // Similar logic for "relation_many" await associateBookingWithService_provider(), await associateBookingWithService_taker(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('bookings', null, {}); await queryInterface.bulkDelete('languages', null, {}); await queryInterface.bulkDelete('skills', null, {}); }, };