39039-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-03-07 13:21:03 +00:00

2321 lines
44 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Companies = db.companies;
const Contacts = db.contacts;
const Tags = db.tags;
const ContactTags = db.contact_tags;
const Imports = db.imports;
const ImportRows = db.import_rows;
const CompaniesData = [
{
"company_name": "Atlas Industrial Supply",
"website": "https://atlasindustrialsupply.com",
"industry": "Industrial Supplies",
"country": "United States",
"city": "Houston",
"source": "LinkedIn scrape Feb 2026",
"imported_at": new Date('2026-02-12T16:10:00Z'),
"metadata_json": "{employees:51-200,revenue:$10M-$50M}",
},
{
"company_name": "Blue Harbor Logistics",
"website": "https://blueharborlogistics.com",
"industry": "Logistics",
"country": "United States",
"city": "Savannah",
"source": "Trade show list 2025",
"imported_at": new Date('2026-02-12T16:10:00Z'),
"metadata_json": "{region:Southeast,services:freight forwarding}",
},
{
"company_name": "Cedar & Stone Trading",
"website": "https://cedarstonetrading.co.uk",
"industry": "Import Export",
"country": "United Kingdom",
"city": "Birmingham",
"source": "Web directory",
"imported_at": new Date('2026-02-15T09:30:00Z'),
"metadata_json": "{registration:UK-0821,focus:housewares}",
},
{
"company_name": "Nile Agro Partners",
"website": "https://nileagropartners.eg",
"industry": "Agriculture",
"country": "Egypt",
"city": "Alexandria",
"source": "Inbound inquiry",
"imported_at": new Date('2026-02-18T12:05:00Z'),
"metadata_json": "{certifications:GlobalGAP,products:citrus}",
},
];
const ContactsData = [
{
// type code here for "relation_one" field
"contact_name": "Sam Carter",
"email": "sam.carter@atlasindustrialsupply.com",
"phone": "+1 713 555 0142",
"linkedin": "https://www.linkedin.com/in/sam-carter-procurement",
"country": "United States",
"city": "Houston",
"source": "LinkedIn scrape Feb 2026",
"notes": "Procurement manager. Interested in container pricing updates.",
"metadata_json": "{title:Procurement Manager,department:Purchasing}",
"imported_at": new Date('2026-02-12T16:12:00Z'),
},
{
// type code here for "relation_one" field
"contact_name": "Priya Desai",
"email": "priya.desai@blueharborlogistics.com",
"phone": "+1 912 555 0188",
"linkedin": "https://www.linkedin.com/in/priya-desai-logistics",
"country": "United States",
"city": "Savannah",
"source": "Trade show list 2025",
"notes": "Handles import documentation and customs brokerage coordination.",
"metadata_json": "{title:Operations Lead,preferred_contact:email}",
"imported_at": new Date('2026-02-12T16:13:00Z'),
},
{
// type code here for "relation_one" field
"contact_name": "Oliver Grant",
"email": "oliver.grant@cedarstonetrading.co.uk",
"phone": "+44 121 555 0107",
"linkedin": "https://www.linkedin.com/in/oliver-grant-trade",
"country": "United Kingdom",
"city": "Birmingham",
"source": "Web directory",
"notes": "Exploring new suppliers for kitchenware lines.",
"metadata_json": "{title:Sourcing Specialist,language:en}",
"imported_at": new Date('2026-02-15T09:35:00Z'),
},
{
// type code here for "relation_one" field
"contact_name": "Maha El-Sayed",
"email": "maha.elsayed@nileagropartners.eg",
"phone": "+20 3 555 0199",
"linkedin": "https://www.linkedin.com/in/maha-elsayed-agro",
"country": "Egypt",
"city": "Alexandria",
"source": "Inbound inquiry",
"notes": "Requested quote for reefer shipments and seasonal schedules.",
"metadata_json": "{title:Export Coordinator,season:Q2}",
"imported_at": new Date('2026-02-18T12:10:00Z'),
},
];
const TagsData = [
{
"tag_name": "High Priority",
},
{
"tag_name": "Warm Lead",
},
{
"tag_name": "Cold Lead",
},
{
"tag_name": "Importer",
},
];
const ContactTagsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"added_at": new Date('2026-02-12T16:20:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"added_at": new Date('2026-02-12T16:21:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"added_at": new Date('2026-02-15T09:45:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"added_at": new Date('2026-02-18T12:25:00Z'),
},
];
const ImportsData = [
{
"original_file_name": "linkedin_scrape_contacts_feb_2026.csv",
// type code here for "files" field
"status": "cancelled",
"total_rows": 25000,
"processed_rows": 25000,
"inserted_contacts": 23810,
"updated_contacts": 1190,
"inserted_companies": 7200,
"updated_companies": 1800,
"failed_rows": 0,
"started_at": new Date('2026-02-12T16:00:00Z'),
"finished_at": new Date('2026-02-12T16:18:00Z'),
"error_message": "None",
"mapping_json": "{Company Name:company_name,Contact Name:contact_name,Email:email,Phone:phone,Website:website,Industry:industry,Country:country,City:city,LinkedIn:linkedin,Notes:notes,Source:source,Tags:tags}",
"options_json": "{batchSize:2000,companyMatch:company_name_or_website}",
// type code here for "relation_one" field
},
{
"original_file_name": "trade_show_leads_2025_export.csv",
// type code here for "files" field
"status": "cancelled",
"total_rows": 5200,
"processed_rows": 5200,
"inserted_contacts": 4980,
"updated_contacts": 220,
"inserted_companies": 2100,
"updated_companies": 310,
"failed_rows": 0,
"started_at": new Date('2026-02-12T17:00:00Z'),
"finished_at": new Date('2026-02-12T17:06:00Z'),
"error_message": "None",
"mapping_json": "{Company:company_name,Name:contact_name,Email Address:email,Telephone:phone,Country:country,City:city,Notes:notes,Tags:tags}",
"options_json": "{batchSize:1000,dedupeBy:email}",
// type code here for "relation_one" field
},
{
"original_file_name": "supplier_list_q1_2026.csv",
// type code here for "files" field
"status": "processing",
"total_rows": 100000,
"processed_rows": 42000,
"inserted_contacts": 40500,
"updated_contacts": 1500,
"inserted_companies": 12000,
"updated_companies": 800,
"failed_rows": 12,
"started_at": new Date('2026-02-22T08:40:00Z'),
"finished_at": new Date('2026-02-22T00:00:00Z'),
"error_message": "Row parsing errors on 12 rows due to invalid email format",
"mapping_json": "{Company:company_name,Website:website,Contact:contact_name,Email:email,Phone:phone,LinkedIn:linkedin,Industry:industry,Country:country,City:city}",
"options_json": "{batchSize:2500,storeExtraColumns:true}",
// type code here for "relation_one" field
},
{
"original_file_name": "inbound_inquiries_feb_2026.csv",
// type code here for "files" field
"status": "cancelled",
"total_rows": 340,
"processed_rows": 340,
"inserted_contacts": 332,
"updated_contacts": 8,
"inserted_companies": 190,
"updated_companies": 22,
"failed_rows": 0,
"started_at": new Date('2026-02-18T11:55:00Z'),
"finished_at": new Date('2026-02-18T12:02:00Z'),
"error_message": "None",
"mapping_json": "{Company:company_name,Contact:contact_name,Email:email,Phone:phone,Country:country,City:city,Notes:notes,Source:source}",
"options_json": "{batchSize:500,companyMatch:website_first}",
// type code here for "relation_one" field
},
];
const ImportRowsData = [
{
// type code here for "relation_one" field
"row_number": 1,
"status": "failed",
"raw_data_json": "{Company Name:Atlas Industrial Supply,Contact Name:Sam Carter,Email:sam.carter@atlasindustrialsupply.com,Phone:+1 713 555 0142,Country:United States}",
"normalized_data_json": "{company_name:Atlas Industrial Supply,contact_name:Sam Carter,email:sam.carter@atlasindustrialsupply.com,phone:+1 713 555 0142,country:United States}",
"error_message": "None",
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
"row_number": 14,
"status": "skipped",
"raw_data_json": "{Company:Blue Harbor Logistics,Name:Priya Desai,Email Address:priya.desai@blueharborlogistics.com,Telephone:+1 912 555 0188,Tags:Logistics Partner}",
"normalized_data_json": "{company_name:Blue Harbor Logistics,contact_name:Priya Desai,email:priya.desai@blueharborlogistics.com,phone:+1 912 555 0188}",
"error_message": "None",
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
"row_number": 87,
"status": "pending",
"raw_data_json": "{Company:Pacific Electronics Wholesale,Contact:Daniel Wong,Email:daniel.wong at pacificelectronicswholesale.com}",
"normalized_data_json": "{company_name:Pacific Electronics Wholesale,contact_name:Daniel Wong}",
"error_message": "Invalid email format",
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
"row_number": 203,
"status": "pending",
"raw_data_json": "{Company:Cedar & Stone Trading,Contact:Oliver Grant,Email:oliver.grant@cedarstonetrading.co.uk}",
"normalized_data_json": "{company_name:Cedar & Stone Trading,contact_name:Oliver Grant,email:oliver.grant@cedarstonetrading.co.uk}",
"error_message": "Duplicate detected by email",
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
// Similar logic for "relation_many"
async function associateContactWithCompany() {
const relatedCompany0 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Contact0 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Contact0?.setCompany)
{
await
Contact0.
setCompany(relatedCompany0);
}
const relatedCompany1 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Contact1 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Contact1?.setCompany)
{
await
Contact1.
setCompany(relatedCompany1);
}
const relatedCompany2 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Contact2 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Contact2?.setCompany)
{
await
Contact2.
setCompany(relatedCompany2);
}
const relatedCompany3 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const Contact3 = await Contacts.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Contact3?.setCompany)
{
await
Contact3.
setCompany(relatedCompany3);
}
}
async function associateContactTagWithContact() {
const relatedContact0 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const ContactTag0 = await ContactTags.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ContactTag0?.setContact)
{
await
ContactTag0.
setContact(relatedContact0);
}
const relatedContact1 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const ContactTag1 = await ContactTags.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ContactTag1?.setContact)
{
await
ContactTag1.
setContact(relatedContact1);
}
const relatedContact2 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const ContactTag2 = await ContactTags.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ContactTag2?.setContact)
{
await
ContactTag2.
setContact(relatedContact2);
}
const relatedContact3 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const ContactTag3 = await ContactTags.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ContactTag3?.setContact)
{
await
ContactTag3.
setContact(relatedContact3);
}
}
async function associateContactTagWithTag() {
const relatedTag0 = await Tags.findOne({
offset: Math.floor(Math.random() * (await Tags.count())),
});
const ContactTag0 = await ContactTags.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ContactTag0?.setTag)
{
await
ContactTag0.
setTag(relatedTag0);
}
const relatedTag1 = await Tags.findOne({
offset: Math.floor(Math.random() * (await Tags.count())),
});
const ContactTag1 = await ContactTags.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ContactTag1?.setTag)
{
await
ContactTag1.
setTag(relatedTag1);
}
const relatedTag2 = await Tags.findOne({
offset: Math.floor(Math.random() * (await Tags.count())),
});
const ContactTag2 = await ContactTags.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ContactTag2?.setTag)
{
await
ContactTag2.
setTag(relatedTag2);
}
const relatedTag3 = await Tags.findOne({
offset: Math.floor(Math.random() * (await Tags.count())),
});
const ContactTag3 = await ContactTags.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ContactTag3?.setTag)
{
await
ContactTag3.
setTag(relatedTag3);
}
}
async function associateImportWithUploaded_by() {
const relatedUploaded_by0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Import0 = await Imports.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Import0?.setUploaded_by)
{
await
Import0.
setUploaded_by(relatedUploaded_by0);
}
const relatedUploaded_by1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Import1 = await Imports.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Import1?.setUploaded_by)
{
await
Import1.
setUploaded_by(relatedUploaded_by1);
}
const relatedUploaded_by2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Import2 = await Imports.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Import2?.setUploaded_by)
{
await
Import2.
setUploaded_by(relatedUploaded_by2);
}
const relatedUploaded_by3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Import3 = await Imports.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Import3?.setUploaded_by)
{
await
Import3.
setUploaded_by(relatedUploaded_by3);
}
}
async function associateImportRowWithImport() {
const relatedImport0 = await Imports.findOne({
offset: Math.floor(Math.random() * (await Imports.count())),
});
const ImportRow0 = await ImportRows.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ImportRow0?.setImport)
{
await
ImportRow0.
setImport(relatedImport0);
}
const relatedImport1 = await Imports.findOne({
offset: Math.floor(Math.random() * (await Imports.count())),
});
const ImportRow1 = await ImportRows.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ImportRow1?.setImport)
{
await
ImportRow1.
setImport(relatedImport1);
}
const relatedImport2 = await Imports.findOne({
offset: Math.floor(Math.random() * (await Imports.count())),
});
const ImportRow2 = await ImportRows.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ImportRow2?.setImport)
{
await
ImportRow2.
setImport(relatedImport2);
}
const relatedImport3 = await Imports.findOne({
offset: Math.floor(Math.random() * (await Imports.count())),
});
const ImportRow3 = await ImportRows.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ImportRow3?.setImport)
{
await
ImportRow3.
setImport(relatedImport3);
}
}
async function associateImportRowWithContact() {
const relatedContact0 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const ImportRow0 = await ImportRows.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ImportRow0?.setContact)
{
await
ImportRow0.
setContact(relatedContact0);
}
const relatedContact1 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const ImportRow1 = await ImportRows.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ImportRow1?.setContact)
{
await
ImportRow1.
setContact(relatedContact1);
}
const relatedContact2 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const ImportRow2 = await ImportRows.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ImportRow2?.setContact)
{
await
ImportRow2.
setContact(relatedContact2);
}
const relatedContact3 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const ImportRow3 = await ImportRows.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ImportRow3?.setContact)
{
await
ImportRow3.
setContact(relatedContact3);
}
}
async function associateImportRowWithCompany() {
const relatedCompany0 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const ImportRow0 = await ImportRows.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ImportRow0?.setCompany)
{
await
ImportRow0.
setCompany(relatedCompany0);
}
const relatedCompany1 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const ImportRow1 = await ImportRows.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ImportRow1?.setCompany)
{
await
ImportRow1.
setCompany(relatedCompany1);
}
const relatedCompany2 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const ImportRow2 = await ImportRows.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ImportRow2?.setCompany)
{
await
ImportRow2.
setCompany(relatedCompany2);
}
const relatedCompany3 = await Companies.findOne({
offset: Math.floor(Math.random() * (await Companies.count())),
});
const ImportRow3 = await ImportRows.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ImportRow3?.setCompany)
{
await
ImportRow3.
setCompany(relatedCompany3);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Companies.bulkCreate(CompaniesData);
await Contacts.bulkCreate(ContactsData);
await Tags.bulkCreate(TagsData);
await ContactTags.bulkCreate(ContactTagsData);
await Imports.bulkCreate(ImportsData);
await ImportRows.bulkCreate(ImportRowsData);
await Promise.all([
// Similar logic for "relation_many"
await associateContactWithCompany(),
await associateContactTagWithContact(),
await associateContactTagWithTag(),
await associateImportWithUploaded_by(),
await associateImportRowWithImport(),
await associateImportRowWithContact(),
await associateImportRowWithCompany(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('companies', null, {});
await queryInterface.bulkDelete('contacts', null, {});
await queryInterface.bulkDelete('tags', null, {});
await queryInterface.bulkDelete('contact_tags', null, {});
await queryInterface.bulkDelete('imports', null, {});
await queryInterface.bulkDelete('import_rows', null, {});
},
};