const db = require('../models'); const Users = db.users; const Communications = db.communications; const Documents = db.documents; const Leads = db.leads; const Payments = db.payments; const Projects = db.projects; const Properties = db.properties; const Sales = db.sales; const Organizations = db.organizations; const CommunicationsData = [ { // type code here for "relation_one" field content: 'Initial contact made via email.', date: new Date('2023-10-01T09:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field content: 'Follow-up call scheduled.', date: new Date('2023-09-15T10:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field content: 'Meeting set for next week.', date: new Date('2023-08-20T11:00:00Z'), // type code here for "relation_one" field }, ]; const DocumentsData = [ { name: 'Property Deed', // type code here for "files" field // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Lease Agreement', // type code here for "files" field // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Sales Contract', // type code here for "files" field // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const LeadsData = [ { name: 'Alice Johnson', // type code here for "relation_one" field stage: 'new', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Bob Williams', // type code here for "relation_one" field stage: 'qualified', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Charlie Brown', // type code here for "relation_one" field stage: 'contacted', // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const PaymentsData = [ { // type code here for "relation_one" field payment_date: new Date('2023-10-05T12:00:00Z'), amount: 50000, status: 'completed', // type code here for "relation_one" field }, { // type code here for "relation_one" field payment_date: new Date('2023-09-20T15:00:00Z'), amount: 30000, status: 'completed', // type code here for "relation_one" field }, { // type code here for "relation_one" field payment_date: new Date('2023-08-25T10:30:00Z'), amount: 15000, status: 'pending', // type code here for "relation_one" field }, ]; const ProjectsData = [ { name: 'Greenfield Estates', // type code here for "relation_many" field start_date: new Date('2023-01-01T00:00:00Z'), end_date: new Date('2023-12-31T23:59:59Z'), // type code here for "relation_one" field }, { name: 'Skyline Towers', // type code here for "relation_many" field start_date: new Date('2023-02-01T00:00:00Z'), end_date: new Date('2023-11-30T23:59:59Z'), // type code here for "relation_one" field }, { name: 'Riverside Complex', // type code here for "relation_many" field start_date: new Date('2023-03-01T00:00:00Z'), end_date: new Date('2023-10-31T23:59:59Z'), // type code here for "relation_one" field }, ]; const PropertiesData = [ { name: 'Ocean View Villa', description: 'A luxurious villa with a stunning ocean view.', type: 'apartment', location: 'Miami, FL', status: 'available', // type code here for "relation_one" field }, { name: 'Downtown Apartment', description: 'Modern apartment in the heart of the city.', type: 'villa', location: 'New York, NY', status: 'available', // type code here for "relation_one" field }, { name: 'Suburban Plot', description: 'Spacious plot in a quiet suburb.', type: 'plot', location: 'Austin, TX', status: 'available', // type code here for "relation_one" field }, ]; const SalesData = [ { // type code here for "relation_one" field // type code here for "relation_one" field booking_date: new Date('2023-10-01T10:00:00Z'), amount: 500000, // 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-09-15T14:30:00Z'), amount: 300000, // 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-08-20T09:00:00Z'), amount: 150000, // type code here for "relation_one" field }, ]; const OrganizationsData = [ { name: 'Marcello Malpighi', }, { name: 'Erwin Schrodinger', }, { name: 'Konrad Lorenz', }, ]; // 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 associateCommunicationWithLead() { const relatedLead0 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Communication0 = await Communications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Communication0?.setLead) { await Communication0.setLead(relatedLead0); } const relatedLead1 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Communication1 = await Communications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Communication1?.setLead) { await Communication1.setLead(relatedLead1); } const relatedLead2 = await Leads.findOne({ offset: Math.floor(Math.random() * (await Leads.count())), }); const Communication2 = await Communications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Communication2?.setLead) { await Communication2.setLead(relatedLead2); } } async function associateCommunicationWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Communication0 = await Communications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Communication0?.setOrganization) { await Communication0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Communication1 = await Communications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Communication1?.setOrganization) { await Communication1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Communication2 = await Communications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Communication2?.setOrganization) { await Communication2.setOrganization(relatedOrganization2); } } async function associateDocumentWithOwner() { const relatedOwner0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Document0 = await Documents.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Document0?.setOwner) { await Document0.setOwner(relatedOwner0); } const relatedOwner1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Document1 = await Documents.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Document1?.setOwner) { await Document1.setOwner(relatedOwner1); } const relatedOwner2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Document2 = await Documents.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Document2?.setOwner) { await Document2.setOwner(relatedOwner2); } } async function associateDocumentWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Document0 = await Documents.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Document0?.setOrganization) { await Document0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Document1 = await Documents.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Document1?.setOrganization) { await Document1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Document2 = await Documents.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Document2?.setOrganization) { await Document2.setOrganization(relatedOrganization2); } } async function associateLeadWithAssigned_to() { const relatedAssigned_to0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lead0 = await Leads.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Lead0?.setAssigned_to) { await Lead0.setAssigned_to(relatedAssigned_to0); } const relatedAssigned_to1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lead1 = await Leads.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Lead1?.setAssigned_to) { await Lead1.setAssigned_to(relatedAssigned_to1); } const relatedAssigned_to2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lead2 = await Leads.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Lead2?.setAssigned_to) { await Lead2.setAssigned_to(relatedAssigned_to2); } } // Similar logic for "relation_many" async function associateLeadWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Lead0 = await Leads.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Lead0?.setOrganization) { await Lead0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Lead1 = await Leads.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Lead1?.setOrganization) { await Lead1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Lead2 = await Leads.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Lead2?.setOrganization) { await Lead2.setOrganization(relatedOrganization2); } } async function associatePaymentWithSale() { const relatedSale0 = await Sales.findOne({ offset: Math.floor(Math.random() * (await Sales.count())), }); const Payment0 = await Payments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Payment0?.setSale) { await Payment0.setSale(relatedSale0); } const relatedSale1 = await Sales.findOne({ offset: Math.floor(Math.random() * (await Sales.count())), }); const Payment1 = await Payments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Payment1?.setSale) { await Payment1.setSale(relatedSale1); } const relatedSale2 = await Sales.findOne({ offset: Math.floor(Math.random() * (await Sales.count())), }); const Payment2 = await Payments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Payment2?.setSale) { await Payment2.setSale(relatedSale2); } } 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); } } // Similar logic for "relation_many" async function associateProjectWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Project0 = await Projects.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Project0?.setOrganization) { await Project0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Project1 = await Projects.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Project1?.setOrganization) { await Project1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Project2 = await Projects.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Project2?.setOrganization) { await Project2.setOrganization(relatedOrganization2); } } async function associatePropertyWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Property0 = await Properties.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Property0?.setOrganization) { await Property0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Property1 = await Properties.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Property1?.setOrganization) { await Property1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Property2 = await Properties.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Property2?.setOrganization) { await Property2.setOrganization(relatedOrganization2); } } async function associateSaleWithProperty() { const relatedProperty0 = await Properties.findOne({ offset: Math.floor(Math.random() * (await Properties.count())), }); const Sale0 = await Sales.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Sale0?.setProperty) { await Sale0.setProperty(relatedProperty0); } const relatedProperty1 = await Properties.findOne({ offset: Math.floor(Math.random() * (await Properties.count())), }); const Sale1 = await Sales.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Sale1?.setProperty) { await Sale1.setProperty(relatedProperty1); } const relatedProperty2 = await Properties.findOne({ offset: Math.floor(Math.random() * (await Properties.count())), }); const Sale2 = await Sales.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Sale2?.setProperty) { await Sale2.setProperty(relatedProperty2); } } async function associateSaleWithCustomer() { const relatedCustomer0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Sale0 = await Sales.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Sale0?.setCustomer) { await Sale0.setCustomer(relatedCustomer0); } const relatedCustomer1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Sale1 = await Sales.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Sale1?.setCustomer) { await Sale1.setCustomer(relatedCustomer1); } const relatedCustomer2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Sale2 = await Sales.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Sale2?.setCustomer) { await Sale2.setCustomer(relatedCustomer2); } } async function associateSaleWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Sale0 = await Sales.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Sale0?.setOrganization) { await Sale0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Sale1 = await Sales.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Sale1?.setOrganization) { await Sale1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Sale2 = await Sales.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Sale2?.setOrganization) { await Sale2.setOrganization(relatedOrganization2); } } module.exports = { up: async (queryInterface, Sequelize) => { await Communications.bulkCreate(CommunicationsData); await Documents.bulkCreate(DocumentsData); await Leads.bulkCreate(LeadsData); await Payments.bulkCreate(PaymentsData); await Projects.bulkCreate(ProjectsData); await Properties.bulkCreate(PropertiesData); await Sales.bulkCreate(SalesData); await Organizations.bulkCreate(OrganizationsData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithOrganization(), await associateCommunicationWithLead(), await associateCommunicationWithOrganization(), await associateDocumentWithOwner(), await associateDocumentWithOrganization(), await associateLeadWithAssigned_to(), // Similar logic for "relation_many" await associateLeadWithOrganization(), await associatePaymentWithSale(), await associatePaymentWithOrganization(), // Similar logic for "relation_many" await associateProjectWithOrganization(), await associatePropertyWithOrganization(), await associateSaleWithProperty(), await associateSaleWithCustomer(), await associateSaleWithOrganization(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('communications', null, {}); await queryInterface.bulkDelete('documents', null, {}); await queryInterface.bulkDelete('leads', null, {}); await queryInterface.bulkDelete('payments', null, {}); await queryInterface.bulkDelete('projects', null, {}); await queryInterface.bulkDelete('properties', null, {}); await queryInterface.bulkDelete('sales', null, {}); await queryInterface.bulkDelete('organizations', null, {}); }, };