const db = require('../models'); const Users = db.users; const Budgets = db.budgets; const Guests = db.guests; const Schedules = db.schedules; const Vendors = db.vendors; const Venues = db.venues; const Organizations = db.organizations; const BudgetsData = [ { name: 'Gala Budget', amount: 10000, status: 'Overdue', // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Meeting Budget', amount: 5000, status: 'Overdue', // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Wedding Budget', amount: 15000, status: 'Pending', // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const GuestsData = [ { name: 'John Doe', email: 'john.doe@example.com', is_attending: true, needs_vegetarian: false, // type code here for "relation_one" field }, { name: 'Jane Smith', email: 'jane.smith@example.com', is_attending: true, needs_vegetarian: true, // type code here for "relation_one" field }, { name: 'Alice Johnson', email: 'alice.johnson@example.com', is_attending: false, needs_vegetarian: false, // type code here for "relation_one" field }, ]; const SchedulesData = [ { title: 'Annual Gala', start_time: new Date('2023-12-15T18:00:00Z'), end_time: new Date('2023-12-15T23:00:00Z'), // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Corporate Meeting', start_time: new Date('2023-11-20T09:00:00Z'), end_time: new Date('2023-11-20T17:00:00Z'), // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, { title: 'Wedding Reception', start_time: new Date('2023-10-10T16:00:00Z'), end_time: new Date('2023-10-10T22:00:00Z'), // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const VendorsData = [ { name: 'Gourmet Catering', contact_info: 'catering@example.com', type: 'Entertainer', rating: 4.5, // type code here for "relation_one" field }, { name: 'Elegant Decor', contact_info: 'decor@example.com', type: 'Decorator', rating: 4.7, // type code here for "relation_one" field }, { name: 'Live Band', contact_info: 'band@example.com', type: 'Entertainer', rating: 4.8, // type code here for "relation_one" field }, ]; const VenuesData = [ { name: 'Grand Ballroom', location: 'Downtown Hotel', capacity: 500, features: 'Stage, AV Equipment, Catering', is_booked: false, // type code here for "relation_one" field }, { name: 'Rooftop Terrace', location: 'City Center', capacity: 200, features: 'Open Air, Scenic View', is_booked: true, // type code here for "relation_one" field }, { name: 'Conference Hall A', location: 'Convention Center', capacity: 300, features: 'Projector, Sound System', is_booked: false, // type code here for "relation_one" field }, ]; const OrganizationsData = [ { name: 'EventCorp', }, { name: 'PartyPlanners', }, { name: 'CorporateEvents', }, ]; // 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); } } async function associateBudgetWithEvent() { const relatedEvent0 = await Schedules.findOne({ offset: Math.floor(Math.random() * (await Schedules.count())), }); const Budget0 = await Budgets.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Budget0?.setEvent) { await Budget0.setEvent(relatedEvent0); } const relatedEvent1 = await Schedules.findOne({ offset: Math.floor(Math.random() * (await Schedules.count())), }); const Budget1 = await Budgets.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Budget1?.setEvent) { await Budget1.setEvent(relatedEvent1); } const relatedEvent2 = await Schedules.findOne({ offset: Math.floor(Math.random() * (await Schedules.count())), }); const Budget2 = await Budgets.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Budget2?.setEvent) { await Budget2.setEvent(relatedEvent2); } } async function associateBudgetWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Budget0 = await Budgets.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Budget0?.setOrganization) { await Budget0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Budget1 = await Budgets.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Budget1?.setOrganization) { await Budget1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Budget2 = await Budgets.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Budget2?.setOrganization) { await Budget2.setOrganization(relatedOrganization2); } } async function associateGuestWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Guest0 = await Guests.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Guest0?.setOrganization) { await Guest0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Guest1 = await Guests.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Guest1?.setOrganization) { await Guest1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Guest2 = await Guests.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Guest2?.setOrganization) { await Guest2.setOrganization(relatedOrganization2); } } async function associateScheduleWithVenue() { const relatedVenue0 = await Venues.findOne({ offset: Math.floor(Math.random() * (await Venues.count())), }); const Schedule0 = await Schedules.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Schedule0?.setVenue) { await Schedule0.setVenue(relatedVenue0); } const relatedVenue1 = await Venues.findOne({ offset: Math.floor(Math.random() * (await Venues.count())), }); const Schedule1 = await Schedules.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Schedule1?.setVenue) { await Schedule1.setVenue(relatedVenue1); } const relatedVenue2 = await Venues.findOne({ offset: Math.floor(Math.random() * (await Venues.count())), }); const Schedule2 = await Schedules.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Schedule2?.setVenue) { await Schedule2.setVenue(relatedVenue2); } } // Similar logic for "relation_many" async function associateScheduleWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Schedule0 = await Schedules.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Schedule0?.setOrganization) { await Schedule0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Schedule1 = await Schedules.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Schedule1?.setOrganization) { await Schedule1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Schedule2 = await Schedules.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Schedule2?.setOrganization) { await Schedule2.setOrganization(relatedOrganization2); } } async function associateVendorWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Vendor0 = await Vendors.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Vendor0?.setOrganization) { await Vendor0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Vendor1 = await Vendors.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Vendor1?.setOrganization) { await Vendor1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Vendor2 = await Vendors.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Vendor2?.setOrganization) { await Vendor2.setOrganization(relatedOrganization2); } } async function associateVenueWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Venue0 = await Venues.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Venue0?.setOrganization) { await Venue0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Venue1 = await Venues.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Venue1?.setOrganization) { await Venue1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Venue2 = await Venues.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Venue2?.setOrganization) { await Venue2.setOrganization(relatedOrganization2); } } module.exports = { up: async (queryInterface, Sequelize) => { await Budgets.bulkCreate(BudgetsData); await Guests.bulkCreate(GuestsData); await Schedules.bulkCreate(SchedulesData); await Vendors.bulkCreate(VendorsData); await Venues.bulkCreate(VenuesData); await Organizations.bulkCreate(OrganizationsData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithOrganization(), await associateBudgetWithEvent(), await associateBudgetWithOrganization(), await associateGuestWithOrganization(), await associateScheduleWithVenue(), // Similar logic for "relation_many" await associateScheduleWithOrganization(), await associateVendorWithOrganization(), await associateVenueWithOrganization(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('budgets', null, {}); await queryInterface.bulkDelete('guests', null, {}); await queryInterface.bulkDelete('schedules', null, {}); await queryInterface.bulkDelete('vendors', null, {}); await queryInterface.bulkDelete('venues', null, {}); await queryInterface.bulkDelete('organizations', null, {}); }, };