const db = require('../models'); const Users = db.users; const AttributeGroups = db.attribute_groups; const Attributes = db.attributes; const Channels = db.channels; const Customers = db.customers; const Files = db.files; const Products = db.products; const Taxonomies = db.taxonomies; const Companies = db.companies; const AttributeGroupsData = [ { name: 'General', // type code here for "relation_one" field }, { name: 'Dimensions', // type code here for "relation_one" field }, { name: 'Specifications', // type code here for "relation_one" field }, { name: 'Connectivity', // type code here for "relation_one" field }, { name: 'Power', // type code here for "relation_one" field }, ]; const AttributesData = [ { name: 'Color', type: 'file_upload', translatable: true, transversal: true, // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Size', type: 'checkbox', translatable: false, transversal: true, // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Weight', type: 'select_single', translatable: true, transversal: true, // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Material', type: 'input_number', translatable: true, transversal: false, // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Warranty', type: 'checkbox', translatable: true, transversal: true, // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const ChannelsData = [ { name: 'Website', // type code here for "relation_one" field }, { name: 'Marketplace', // type code here for "relation_one" field }, { name: 'Print', // type code here for "relation_one" field }, { name: 'Mobile App', // type code here for "relation_one" field }, { name: 'Retail', // type code here for "relation_one" field }, ]; const CustomersData = [ { name: 'Alice Green', contact_details: 'alice.green@example.com', // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Bob White', contact_details: 'bob.white@example.com', // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Charlie Black', contact_details: 'charlie.black@example.com', // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Diana Blue', contact_details: 'diana.blue@example.com', // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Eve Red', contact_details: 'eve.red@example.com', // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const FilesData = [ { file_name: 'product_manual.pdf', // type code here for "files" field // type code here for "relation_one" field }, { file_name: 'warranty_info.pdf', // type code here for "files" field // type code here for "relation_one" field }, { file_name: 'spec_sheet.pdf', // type code here for "files" field // type code here for "relation_one" field }, { file_name: 'installation_guide.pdf', // type code here for "files" field // type code here for "relation_one" field }, { file_name: 'user_guide.pdf', // type code here for "files" field // type code here for "relation_one" field }, ]; const ProductsData = [ { ean: '1234567890123', name: 'Wireless Mouse', // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_one" field // type code here for "relation_one" field }, { ean: '2345678901234', name: 'Bluetooth Speaker', // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_one" field // type code here for "relation_one" field }, { ean: '3456789012345', name: 'Smartphone', // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_one" field // type code here for "relation_one" field }, { ean: '4567890123456', name: 'Laptop', // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_one" field // type code here for "relation_one" field }, { ean: '5678901234567', name: 'Tablet', // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_many" field // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const TaxonomiesData = [ { name: 'Electronics', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Audio', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Mobile Devices', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Computers', // type code here for "relation_many" field // type code here for "relation_one" field }, { name: 'Tablets', // type code here for "relation_many" field // type code here for "relation_one" field }, ]; const CompaniesData = [ { name: 'TechCorp', }, { name: 'SoundWave', }, { name: 'MobileMakers', }, { name: 'CompuWorld', }, { name: 'GadgetHub', }, ]; // Similar logic for "relation_many" async function associateUserWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const User0 = await Users.findOne({ order: [['id', 'ASC']], offset: 0, }); if (User0?.setCompany) { await User0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const User1 = await Users.findOne({ order: [['id', 'ASC']], offset: 1, }); if (User1?.setCompany) { await User1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const User2 = await Users.findOne({ order: [['id', 'ASC']], offset: 2, }); if (User2?.setCompany) { await User2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const User3 = await Users.findOne({ order: [['id', 'ASC']], offset: 3, }); if (User3?.setCompany) { await User3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const User4 = await Users.findOne({ order: [['id', 'ASC']], offset: 4, }); if (User4?.setCompany) { await User4.setCompany(relatedCompany4); } } async function associateAttributeGroupWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const AttributeGroup0 = await AttributeGroups.findOne({ order: [['id', 'ASC']], offset: 0, }); if (AttributeGroup0?.setCompany) { await AttributeGroup0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const AttributeGroup1 = await AttributeGroups.findOne({ order: [['id', 'ASC']], offset: 1, }); if (AttributeGroup1?.setCompany) { await AttributeGroup1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const AttributeGroup2 = await AttributeGroups.findOne({ order: [['id', 'ASC']], offset: 2, }); if (AttributeGroup2?.setCompany) { await AttributeGroup2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const AttributeGroup3 = await AttributeGroups.findOne({ order: [['id', 'ASC']], offset: 3, }); if (AttributeGroup3?.setCompany) { await AttributeGroup3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const AttributeGroup4 = await AttributeGroups.findOne({ order: [['id', 'ASC']], offset: 4, }); if (AttributeGroup4?.setCompany) { await AttributeGroup4.setCompany(relatedCompany4); } } async function associateAttributeWithGroup() { const relatedGroup0 = await AttributeGroups.findOne({ offset: Math.floor(Math.random() * (await AttributeGroups.count())), }); const Attribute0 = await Attributes.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Attribute0?.setGroup) { await Attribute0.setGroup(relatedGroup0); } const relatedGroup1 = await AttributeGroups.findOne({ offset: Math.floor(Math.random() * (await AttributeGroups.count())), }); const Attribute1 = await Attributes.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Attribute1?.setGroup) { await Attribute1.setGroup(relatedGroup1); } const relatedGroup2 = await AttributeGroups.findOne({ offset: Math.floor(Math.random() * (await AttributeGroups.count())), }); const Attribute2 = await Attributes.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Attribute2?.setGroup) { await Attribute2.setGroup(relatedGroup2); } const relatedGroup3 = await AttributeGroups.findOne({ offset: Math.floor(Math.random() * (await AttributeGroups.count())), }); const Attribute3 = await Attributes.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Attribute3?.setGroup) { await Attribute3.setGroup(relatedGroup3); } const relatedGroup4 = await AttributeGroups.findOne({ offset: Math.floor(Math.random() * (await AttributeGroups.count())), }); const Attribute4 = await Attributes.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Attribute4?.setGroup) { await Attribute4.setGroup(relatedGroup4); } } async function associateAttributeWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Attribute0 = await Attributes.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Attribute0?.setCompany) { await Attribute0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Attribute1 = await Attributes.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Attribute1?.setCompany) { await Attribute1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Attribute2 = await Attributes.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Attribute2?.setCompany) { await Attribute2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Attribute3 = await Attributes.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Attribute3?.setCompany) { await Attribute3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Attribute4 = await Attributes.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Attribute4?.setCompany) { await Attribute4.setCompany(relatedCompany4); } } async function associateChannelWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Channel0 = await Channels.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Channel0?.setCompany) { await Channel0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Channel1 = await Channels.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Channel1?.setCompany) { await Channel1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Channel2 = await Channels.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Channel2?.setCompany) { await Channel2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Channel3 = await Channels.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Channel3?.setCompany) { await Channel3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Channel4 = await Channels.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Channel4?.setCompany) { await Channel4.setCompany(relatedCompany4); } } async function associateCustomerWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Customer0 = await Customers.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Customer0?.setCompany) { await Customer0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Customer1 = await Customers.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Customer1?.setCompany) { await Customer1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Customer2 = await Customers.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Customer2?.setCompany) { await Customer2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Customer3 = await Customers.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Customer3?.setCompany) { await Customer3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Customer4 = await Customers.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Customer4?.setCompany) { await Customer4.setCompany(relatedCompany4); } } async function associateCustomerWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Customer0 = await Customers.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Customer0?.setCompany) { await Customer0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Customer1 = await Customers.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Customer1?.setCompany) { await Customer1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Customer2 = await Customers.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Customer2?.setCompany) { await Customer2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Customer3 = await Customers.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Customer3?.setCompany) { await Customer3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Customer4 = await Customers.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Customer4?.setCompany) { await Customer4.setCompany(relatedCompany4); } } async function associateFileWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const File0 = await Files.findOne({ order: [['id', 'ASC']], offset: 0, }); if (File0?.setCompany) { await File0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const File1 = await Files.findOne({ order: [['id', 'ASC']], offset: 1, }); if (File1?.setCompany) { await File1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const File2 = await Files.findOne({ order: [['id', 'ASC']], offset: 2, }); if (File2?.setCompany) { await File2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const File3 = await Files.findOne({ order: [['id', 'ASC']], offset: 3, }); if (File3?.setCompany) { await File3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const File4 = await Files.findOne({ order: [['id', 'ASC']], offset: 4, }); if (File4?.setCompany) { await File4.setCompany(relatedCompany4); } } async function associateProductWithTaxonomy() { const relatedTaxonomy0 = await Taxonomies.findOne({ offset: Math.floor(Math.random() * (await Taxonomies.count())), }); const Product0 = await Products.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Product0?.setTaxonomy) { await Product0.setTaxonomy(relatedTaxonomy0); } const relatedTaxonomy1 = await Taxonomies.findOne({ offset: Math.floor(Math.random() * (await Taxonomies.count())), }); const Product1 = await Products.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Product1?.setTaxonomy) { await Product1.setTaxonomy(relatedTaxonomy1); } const relatedTaxonomy2 = await Taxonomies.findOne({ offset: Math.floor(Math.random() * (await Taxonomies.count())), }); const Product2 = await Products.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Product2?.setTaxonomy) { await Product2.setTaxonomy(relatedTaxonomy2); } const relatedTaxonomy3 = await Taxonomies.findOne({ offset: Math.floor(Math.random() * (await Taxonomies.count())), }); const Product3 = await Products.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Product3?.setTaxonomy) { await Product3.setTaxonomy(relatedTaxonomy3); } const relatedTaxonomy4 = await Taxonomies.findOne({ offset: Math.floor(Math.random() * (await Taxonomies.count())), }); const Product4 = await Products.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Product4?.setTaxonomy) { await Product4.setTaxonomy(relatedTaxonomy4); } } // Similar logic for "relation_many" // Similar logic for "relation_many" // Similar logic for "relation_many" async function associateProductWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Product0 = await Products.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Product0?.setCompany) { await Product0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Product1 = await Products.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Product1?.setCompany) { await Product1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Product2 = await Products.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Product2?.setCompany) { await Product2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Product3 = await Products.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Product3?.setCompany) { await Product3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Product4 = await Products.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Product4?.setCompany) { await Product4.setCompany(relatedCompany4); } } async function associateProductWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Product0 = await Products.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Product0?.setCompany) { await Product0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Product1 = await Products.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Product1?.setCompany) { await Product1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Product2 = await Products.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Product2?.setCompany) { await Product2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Product3 = await Products.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Product3?.setCompany) { await Product3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Product4 = await Products.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Product4?.setCompany) { await Product4.setCompany(relatedCompany4); } } // Similar logic for "relation_many" async function associateTaxonomyWithCompany() { const relatedCompany0 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Taxonomy0 = await Taxonomies.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Taxonomy0?.setCompany) { await Taxonomy0.setCompany(relatedCompany0); } const relatedCompany1 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Taxonomy1 = await Taxonomies.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Taxonomy1?.setCompany) { await Taxonomy1.setCompany(relatedCompany1); } const relatedCompany2 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Taxonomy2 = await Taxonomies.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Taxonomy2?.setCompany) { await Taxonomy2.setCompany(relatedCompany2); } const relatedCompany3 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Taxonomy3 = await Taxonomies.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Taxonomy3?.setCompany) { await Taxonomy3.setCompany(relatedCompany3); } const relatedCompany4 = await Companies.findOne({ offset: Math.floor(Math.random() * (await Companies.count())), }); const Taxonomy4 = await Taxonomies.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Taxonomy4?.setCompany) { await Taxonomy4.setCompany(relatedCompany4); } } module.exports = { up: async (queryInterface, Sequelize) => { await AttributeGroups.bulkCreate(AttributeGroupsData); await Attributes.bulkCreate(AttributesData); await Channels.bulkCreate(ChannelsData); await Customers.bulkCreate(CustomersData); await Files.bulkCreate(FilesData); await Products.bulkCreate(ProductsData); await Taxonomies.bulkCreate(TaxonomiesData); await Companies.bulkCreate(CompaniesData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithCompany(), await associateAttributeGroupWithCompany(), await associateAttributeWithGroup(), await associateAttributeWithCompany(), await associateChannelWithCompany(), await associateCustomerWithCompany(), await associateCustomerWithCompany(), await associateFileWithCompany(), await associateProductWithTaxonomy(), // Similar logic for "relation_many" // Similar logic for "relation_many" // Similar logic for "relation_many" await associateProductWithCompany(), await associateProductWithCompany(), // Similar logic for "relation_many" await associateTaxonomyWithCompany(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('attribute_groups', null, {}); await queryInterface.bulkDelete('attributes', null, {}); await queryInterface.bulkDelete('channels', null, {}); await queryInterface.bulkDelete('customers', null, {}); await queryInterface.bulkDelete('files', null, {}); await queryInterface.bulkDelete('products', null, {}); await queryInterface.bulkDelete('taxonomies', null, {}); await queryInterface.bulkDelete('companies', null, {}); }, };