const db = require('../models'); const Users = db.users; const Contacts = db.contacts; const Leads = db.leads; const Orders = db.orders; const Products = db.products; const Organizations = db.organizations; const ContactsData = [ { first_name: 'Alice', last_name: 'Johnson', email: 'alice.johnson@example.com', // type code here for "relation_one" field // type code here for "relation_one" field }, { first_name: 'Bob', last_name: 'Smith', email: 'bob.smith@example.com', // type code here for "relation_one" field // type code here for "relation_one" field }, { first_name: 'Charlie', last_name: 'Brown', email: 'charlie.brown@example.com', // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const LeadsData = [ { name: 'Acme Corp', status: 'contacted', category: 'warm', // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Globex Inc', status: 'qualified', category: 'warm', // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Initech', status: 'qualified', category: 'hot', // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const OrdersData = [ { // type code here for "relation_one" field // type code here for "relation_many" field total_price: 350, order_date: new Date('2023-10-01T10:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_many" field total_price: 250, order_date: new Date('2023-10-02T11:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_many" field total_price: 400, order_date: new Date('2023-10-03T12:00:00Z'), // type code here for "relation_one" field }, ]; const ProductsData = [ { title: 'Legal Document Review', description: 'Comprehensive review of legal documents.', price: 150, // type code here for "images" field // type code here for "relation_one" field // type code here for "relation_one" field }, { title: 'Contract Drafting', description: 'Drafting of contracts tailored to your needs.', price: 200, // type code here for "images" field // type code here for "relation_one" field // type code here for "relation_one" field }, { title: 'Case Analysis', description: 'In-depth analysis of legal cases.', price: 250, // type code here for "images" field // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const OrganizationsData = [ { name: 'Max Born', }, { name: 'Emil Kraepelin', }, { name: 'Neils Bohr', }, ]; // 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 associateContactWithOwner() { const relatedOwner0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Contact0 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Contact0?.setOwner) { await Contact0.setOwner(relatedOwner0); } const relatedOwner1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Contact1 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Contact1?.setOwner) { await Contact1.setOwner(relatedOwner1); } const relatedOwner2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Contact2 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Contact2?.setOwner) { await Contact2.setOwner(relatedOwner2); } } async function associateContactWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Contact0 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Contact0?.setOrganization) { await Contact0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Contact1 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Contact1?.setOrganization) { await Contact1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Contact2 = await Contacts.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Contact2?.setOrganization) { await Contact2.setOrganization(relatedOrganization2); } } async function associateLeadWithOwner() { const relatedOwner0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lead0 = await Leads.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Lead0?.setOwner) { await Lead0.setOwner(relatedOwner0); } const relatedOwner1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lead1 = await Leads.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Lead1?.setOwner) { await Lead1.setOwner(relatedOwner1); } const relatedOwner2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Lead2 = await Leads.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Lead2?.setOwner) { await Lead2.setOwner(relatedOwner2); } } 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 associateOrderWithBuyer() { const relatedBuyer0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Order0 = await Orders.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Order0?.setBuyer) { await Order0.setBuyer(relatedBuyer0); } const relatedBuyer1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Order1 = await Orders.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Order1?.setBuyer) { await Order1.setBuyer(relatedBuyer1); } const relatedBuyer2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Order2 = await Orders.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Order2?.setBuyer) { await Order2.setBuyer(relatedBuyer2); } } // Similar logic for "relation_many" async function associateOrderWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Order0 = await Orders.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Order0?.setOrganization) { await Order0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Order1 = await Orders.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Order1?.setOrganization) { await Order1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Order2 = await Orders.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Order2?.setOrganization) { await Order2.setOrganization(relatedOrganization2); } } async function associateProductWithSeller() { const relatedSeller0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Product0 = await Products.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Product0?.setSeller) { await Product0.setSeller(relatedSeller0); } const relatedSeller1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Product1 = await Products.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Product1?.setSeller) { await Product1.setSeller(relatedSeller1); } const relatedSeller2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Product2 = await Products.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Product2?.setSeller) { await Product2.setSeller(relatedSeller2); } } async function associateProductWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Product0 = await Products.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Product0?.setOrganization) { await Product0.setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Product1 = await Products.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Product1?.setOrganization) { await Product1.setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Product2 = await Products.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Product2?.setOrganization) { await Product2.setOrganization(relatedOrganization2); } } module.exports = { up: async (queryInterface, Sequelize) => { await Contacts.bulkCreate(ContactsData); await Leads.bulkCreate(LeadsData); await Orders.bulkCreate(OrdersData); await Products.bulkCreate(ProductsData); await Organizations.bulkCreate(OrganizationsData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithOrganization(), await associateContactWithOwner(), await associateContactWithOrganization(), await associateLeadWithOwner(), await associateLeadWithOrganization(), await associateOrderWithBuyer(), // Similar logic for "relation_many" await associateOrderWithOrganization(), await associateProductWithSeller(), await associateProductWithOrganization(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('contacts', null, {}); await queryInterface.bulkDelete('leads', null, {}); await queryInterface.bulkDelete('orders', null, {}); await queryInterface.bulkDelete('products', null, {}); await queryInterface.bulkDelete('organizations', null, {}); }, };