37749-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-01-23 14:53:19 +00:00

3656 lines
80 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Organizations = db.organizations;
const Campaigns = db.campaigns;
const Sequences = db.sequences;
const SequenceSteps = db.sequence_steps;
const Templates = db.templates;
const Contacts = db.contacts;
const ContactLists = db.contact_lists;
const SmtpIntegrations = db.smtp_integrations;
const EmailSends = db.email_sends;
const AnalyticsEvents = db.analytics_events;
const Attachments = db.attachments;
const OrganizationsData = [
{
"name": "NorthStar Ventures",
},
{
"name": "BrightEdge Solutions",
},
{
"name": "Summit Growth",
},
];
const CampaignsData = [
{
"name": "Q2 Product Launch",
"description": "Drive awareness and demos for the new product release in Q2",
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "active",
"start_date": new Date('2025-04-01T09:00:00Z'),
"end_date": new Date('2025-06-30T18:00:00Z'),
// type code here for "relation_one" field
},
{
"name": "Conference Follow Up",
"description": "Follow up with leads collected at the Spring conference",
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "active",
"start_date": new Date('2025-05-05T09:00:00Z'),
"end_date": new Date('2025-05-31T18:00:00Z'),
// type code here for "relation_one" field
},
{
"name": "Enterprise Outreach",
"description": "Targeted outreach for enterprise accounts",
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "paused",
"start_date": new Date('2025-03-15T09:00:00Z'),
"end_date": new Date('2025-09-15T18:00:00Z'),
// type code here for "relation_one" field
},
];
const SequencesData = [
{
"name": "Launch Sequence A",
// type code here for "relation_one" field
"steps_count": 3,
"is_active": true,
"sending_window": "09:00-17:00",
// type code here for "relation_one" field
},
{
"name": "Conference Follow Up Sequence",
// type code here for "relation_one" field
"steps_count": 2,
"is_active": false,
"sending_window": "10:00-16:00",
// type code here for "relation_one" field
},
{
"name": "Enterprise Nurture Sequence",
// type code here for "relation_one" field
"steps_count": 4,
"is_active": false,
"sending_window": "09:00-18:00",
// type code here for "relation_one" field
},
];
const SequenceStepsData = [
{
// type code here for "relation_one" field
"step_order": 1,
"step_type": "condition",
"wait_days": 0,
// type code here for "relation_one" field
"subject": "Exclusive preview: new product launch",
"body": "Hello {{first_name}}, We would like to invite you to preview our new product.",
"send_time": new Date('2025-04-02T10:00:00Z'),
"condition": "",
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
"step_order": 2,
"step_type": "wait",
"wait_days": 3,
// type code here for "relation_one" field
"subject": "",
"body": "",
"send_time": new Date('2025-04-05T10:00:00Z'),
"condition": "",
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
"step_order": 1,
"step_type": "condition",
"wait_days": 0,
// type code here for "relation_one" field
"subject": "Your subscription is up for renewal",
"body": "Hello {{first_name}}, Your plan is expiring soon. Schedule a call to discuss.",
"send_time": new Date('2025-05-01T09:00:00Z'),
"condition": "",
// type code here for "relation_one" field
},
];
const TemplatesData = [
{
"name": "Launch Invite",
"subject": "Exclusive preview: new product launch",
"body": "Hello {{first_name}},
We would like to invite you to a preview of our new product. Book a demo today.",
// type code here for "relation_one" field
// type code here for "files" field
// type code here for "relation_one" field
},
{
"name": "Conference Thanks",
"subject": "Great meeting you at the conference",
"body": "Hi {{first_name}},
It was a pleasure meeting you. Here are the resources we discussed.",
// type code here for "relation_one" field
// type code here for "files" field
// type code here for "relation_one" field
},
{
"name": "Enterprise Intro",
"subject": "Strategic partnership opportunity",
"body": "Dear {{first_name}},
We have ideas to help your team achieve faster outcomes.",
// type code here for "relation_one" field
// type code here for "files" field
// type code here for "relation_one" field
},
];
const ContactsData = [
{
"email": "lucy.hart@example.com",
"first_name": "Lucy",
"last_name": "Hart",
"company": "Aster Labs",
"title": "Head of Operations",
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"email": "michael.nguyen@example.com",
"first_name": "Michael",
"last_name": "Nguyen",
"company": "BrightEdge Solutions",
"title": "Director of Product",
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"email": "sophia.ross@example.com",
"first_name": "Sophia",
"last_name": "Ross",
"company": "Summit Growth",
"title": "VP Marketing",
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const ContactListsData = [
{
"name": "Seed Leads Q1",
"description": "Initial seed prospects for quarter one outreach",
// type code here for "relation_many" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"name": "Event Attendees",
"description": "Contacts collected from the Spring conference",
// type code here for "relation_many" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"name": "Marketing Qualified Leads",
"description": "MQLs from marketing automation scoring",
// type code here for "relation_many" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const SmtpIntegrationsData = [
{
"name": "NorthStar SMTP",
"provider": "mailgun",
"host": "smtp.northstar.example.com",
"port": 587,
"username": "noreply@northstar.example.com",
"from_email": "noreply@northstar.example.com",
"is_verified": true,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"name": "BrightEdge Sendgrid",
"provider": "mailgun",
"host": "smtp.sendgrid.net",
"port": 587,
"username": "apikey",
"from_email": "hello@brightedge.example.com",
"is_verified": true,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"name": "Summit Mailgun",
"provider": "sendgrid",
"host": "smtp.mailgun.org",
"port": 587,
"username": "postmaster@summit.example.com",
"from_email": "postmaster@summit.example.com",
"is_verified": true,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const EmailSendsData = [
{
"subject": "Exclusive preview: new product launch",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "replied",
"scheduled_at": new Date('2025-04-02T10:00:00Z'),
"sent_at": new Date('2025-04-02T10:01:00Z'),
"opened_at": new Date('2025-04-02T10:15:00Z'),
"clicked_at": new Date('2025-04-02T10:16:00Z'),
"bounce_reason": "",
// type code here for "relation_one" field
},
{
"subject": "Great meeting you at the conference",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "clicked",
"scheduled_at": new Date('2025-05-06T11:00:00Z'),
"sent_at": new Date('2020-01-01T00:00:00Z'),
"opened_at": new Date('2020-01-01T00:00:00Z'),
"clicked_at": new Date('2020-01-01T00:00:00Z'),
"bounce_reason": "",
// type code here for "relation_one" field
},
{
"subject": "Your subscription is up for renewal",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"status": "sent",
"scheduled_at": new Date('2025-05-01T09:00:00Z'),
"sent_at": new Date('2025-05-01T09:00:10Z'),
"opened_at": new Date('2025-05-01T09:05:00Z'),
"clicked_at": new Date('2020-01-01T00:00:00Z'),
"bounce_reason": "",
// type code here for "relation_one" field
},
];
const AnalyticsEventsData = [
{
"event_name": "open_event_1",
// type code here for "relation_one" field
"event_type": "bounce",
"occurred_at": new Date('2025-04-02T10:15:00Z'),
"value": 1.0,
// type code here for "relation_one" field
},
{
"event_name": "click_event_1",
// type code here for "relation_one" field
"event_type": "open",
"occurred_at": new Date('2025-04-02T10:16:00Z'),
"value": 1.0,
// type code here for "relation_one" field
},
{
"event_name": "bounce_event_1",
// type code here for "relation_one" field
"event_type": "open",
"occurred_at": new Date('2025-06-02T11:00:10Z'),
"value": 0.0,
// type code here for "relation_one" field
},
];
const AttachmentsData = [
{
"filename": "launch-brochure.pdf",
"size": 254321,
"url": "https://cdn.example.com/docs/launch-brochure.pdf",
// type code here for "relation_one" field
"uploaded_at": new Date('2025-03-20T08:00:00Z'),
// type code here for "relation_one" field
},
{
"filename": "sales-deck.pdf",
"size": 512000,
"url": "https://cdn.example.com/resources/sales-deck.pdf",
// type code here for "relation_one" field
"uploaded_at": new Date('2025-02-10T12:30:00Z'),
// type code here for "relation_one" field
},
{
"filename": "case-study.pdf",
"size": 128400,
"url": "https://cdn.example.com/resources/case-study.pdf",
// type code here for "relation_one" field
"uploaded_at": new Date('2025-01-15T09:45:00Z'),
// type code here for "relation_one" field
},
];
// 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 associateCampaignWithOwner() {
const relatedOwner0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Campaign0 = await Campaigns.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Campaign0?.setOwner)
{
await
Campaign0.
setOwner(relatedOwner0);
}
const relatedOwner1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Campaign1 = await Campaigns.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Campaign1?.setOwner)
{
await
Campaign1.
setOwner(relatedOwner1);
}
const relatedOwner2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Campaign2 = await Campaigns.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Campaign2?.setOwner)
{
await
Campaign2.
setOwner(relatedOwner2);
}
}
async function associateCampaignWithContact_list() {
const relatedContact_list0 = await ContactLists.findOne({
offset: Math.floor(Math.random() * (await ContactLists.count())),
});
const Campaign0 = await Campaigns.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Campaign0?.setContact_list)
{
await
Campaign0.
setContact_list(relatedContact_list0);
}
const relatedContact_list1 = await ContactLists.findOne({
offset: Math.floor(Math.random() * (await ContactLists.count())),
});
const Campaign1 = await Campaigns.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Campaign1?.setContact_list)
{
await
Campaign1.
setContact_list(relatedContact_list1);
}
const relatedContact_list2 = await ContactLists.findOne({
offset: Math.floor(Math.random() * (await ContactLists.count())),
});
const Campaign2 = await Campaigns.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Campaign2?.setContact_list)
{
await
Campaign2.
setContact_list(relatedContact_list2);
}
}
async function associateCampaignWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Campaign0 = await Campaigns.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Campaign0?.setOrganization)
{
await
Campaign0.
setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Campaign1 = await Campaigns.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Campaign1?.setOrganization)
{
await
Campaign1.
setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Campaign2 = await Campaigns.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Campaign2?.setOrganization)
{
await
Campaign2.
setOrganization(relatedOrganization2);
}
}
async function associateSequenceWithCampaign() {
const relatedCampaign0 = await Campaigns.findOne({
offset: Math.floor(Math.random() * (await Campaigns.count())),
});
const Sequence0 = await Sequences.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Sequence0?.setCampaign)
{
await
Sequence0.
setCampaign(relatedCampaign0);
}
const relatedCampaign1 = await Campaigns.findOne({
offset: Math.floor(Math.random() * (await Campaigns.count())),
});
const Sequence1 = await Sequences.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Sequence1?.setCampaign)
{
await
Sequence1.
setCampaign(relatedCampaign1);
}
const relatedCampaign2 = await Campaigns.findOne({
offset: Math.floor(Math.random() * (await Campaigns.count())),
});
const Sequence2 = await Sequences.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Sequence2?.setCampaign)
{
await
Sequence2.
setCampaign(relatedCampaign2);
}
}
async function associateSequenceWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Sequence0 = await Sequences.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Sequence0?.setOrganization)
{
await
Sequence0.
setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Sequence1 = await Sequences.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Sequence1?.setOrganization)
{
await
Sequence1.
setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Sequence2 = await Sequences.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Sequence2?.setOrganization)
{
await
Sequence2.
setOrganization(relatedOrganization2);
}
}
async function associateSequenceStepWithSequence() {
const relatedSequence0 = await Sequences.findOne({
offset: Math.floor(Math.random() * (await Sequences.count())),
});
const SequenceStep0 = await SequenceSteps.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (SequenceStep0?.setSequence)
{
await
SequenceStep0.
setSequence(relatedSequence0);
}
const relatedSequence1 = await Sequences.findOne({
offset: Math.floor(Math.random() * (await Sequences.count())),
});
const SequenceStep1 = await SequenceSteps.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (SequenceStep1?.setSequence)
{
await
SequenceStep1.
setSequence(relatedSequence1);
}
const relatedSequence2 = await Sequences.findOne({
offset: Math.floor(Math.random() * (await Sequences.count())),
});
const SequenceStep2 = await SequenceSteps.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (SequenceStep2?.setSequence)
{
await
SequenceStep2.
setSequence(relatedSequence2);
}
}
async function associateSequenceStepWithTemplate() {
const relatedTemplate0 = await Templates.findOne({
offset: Math.floor(Math.random() * (await Templates.count())),
});
const SequenceStep0 = await SequenceSteps.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (SequenceStep0?.setTemplate)
{
await
SequenceStep0.
setTemplate(relatedTemplate0);
}
const relatedTemplate1 = await Templates.findOne({
offset: Math.floor(Math.random() * (await Templates.count())),
});
const SequenceStep1 = await SequenceSteps.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (SequenceStep1?.setTemplate)
{
await
SequenceStep1.
setTemplate(relatedTemplate1);
}
const relatedTemplate2 = await Templates.findOne({
offset: Math.floor(Math.random() * (await Templates.count())),
});
const SequenceStep2 = await SequenceSteps.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (SequenceStep2?.setTemplate)
{
await
SequenceStep2.
setTemplate(relatedTemplate2);
}
}
async function associateSequenceStepWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const SequenceStep0 = await SequenceSteps.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (SequenceStep0?.setOrganization)
{
await
SequenceStep0.
setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const SequenceStep1 = await SequenceSteps.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (SequenceStep1?.setOrganization)
{
await
SequenceStep1.
setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const SequenceStep2 = await SequenceSteps.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (SequenceStep2?.setOrganization)
{
await
SequenceStep2.
setOrganization(relatedOrganization2);
}
}
async function associateTemplateWithOwner() {
const relatedOwner0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Template0 = await Templates.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Template0?.setOwner)
{
await
Template0.
setOwner(relatedOwner0);
}
const relatedOwner1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Template1 = await Templates.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Template1?.setOwner)
{
await
Template1.
setOwner(relatedOwner1);
}
const relatedOwner2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Template2 = await Templates.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Template2?.setOwner)
{
await
Template2.
setOwner(relatedOwner2);
}
}
async function associateTemplateWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Template0 = await Templates.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Template0?.setOrganization)
{
await
Template0.
setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Template1 = await Templates.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Template1?.setOrganization)
{
await
Template1.
setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Template2 = await Templates.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Template2?.setOrganization)
{
await
Template2.
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);
}
}
// Similar logic for "relation_many"
async function associateContactListWithOwner() {
const relatedOwner0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ContactList0 = await ContactLists.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ContactList0?.setOwner)
{
await
ContactList0.
setOwner(relatedOwner0);
}
const relatedOwner1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ContactList1 = await ContactLists.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ContactList1?.setOwner)
{
await
ContactList1.
setOwner(relatedOwner1);
}
const relatedOwner2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ContactList2 = await ContactLists.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ContactList2?.setOwner)
{
await
ContactList2.
setOwner(relatedOwner2);
}
}
async function associateContactListWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const ContactList0 = await ContactLists.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ContactList0?.setOrganization)
{
await
ContactList0.
setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const ContactList1 = await ContactLists.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ContactList1?.setOrganization)
{
await
ContactList1.
setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const ContactList2 = await ContactLists.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ContactList2?.setOrganization)
{
await
ContactList2.
setOrganization(relatedOrganization2);
}
}
async function associateSmtpIntegrationWithOwner() {
const relatedOwner0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SmtpIntegration0 = await SmtpIntegrations.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (SmtpIntegration0?.setOwner)
{
await
SmtpIntegration0.
setOwner(relatedOwner0);
}
const relatedOwner1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SmtpIntegration1 = await SmtpIntegrations.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (SmtpIntegration1?.setOwner)
{
await
SmtpIntegration1.
setOwner(relatedOwner1);
}
const relatedOwner2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SmtpIntegration2 = await SmtpIntegrations.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (SmtpIntegration2?.setOwner)
{
await
SmtpIntegration2.
setOwner(relatedOwner2);
}
}
async function associateSmtpIntegrationWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const SmtpIntegration0 = await SmtpIntegrations.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (SmtpIntegration0?.setOrganization)
{
await
SmtpIntegration0.
setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const SmtpIntegration1 = await SmtpIntegrations.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (SmtpIntegration1?.setOrganization)
{
await
SmtpIntegration1.
setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const SmtpIntegration2 = await SmtpIntegrations.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (SmtpIntegration2?.setOrganization)
{
await
SmtpIntegration2.
setOrganization(relatedOrganization2);
}
}
async function associateEmailSendWithRecipient() {
const relatedRecipient0 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const EmailSend0 = await EmailSends.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (EmailSend0?.setRecipient)
{
await
EmailSend0.
setRecipient(relatedRecipient0);
}
const relatedRecipient1 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const EmailSend1 = await EmailSends.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (EmailSend1?.setRecipient)
{
await
EmailSend1.
setRecipient(relatedRecipient1);
}
const relatedRecipient2 = await Contacts.findOne({
offset: Math.floor(Math.random() * (await Contacts.count())),
});
const EmailSend2 = await EmailSends.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (EmailSend2?.setRecipient)
{
await
EmailSend2.
setRecipient(relatedRecipient2);
}
}
async function associateEmailSendWithSequence_step() {
const relatedSequence_step0 = await SequenceSteps.findOne({
offset: Math.floor(Math.random() * (await SequenceSteps.count())),
});
const EmailSend0 = await EmailSends.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (EmailSend0?.setSequence_step)
{
await
EmailSend0.
setSequence_step(relatedSequence_step0);
}
const relatedSequence_step1 = await SequenceSteps.findOne({
offset: Math.floor(Math.random() * (await SequenceSteps.count())),
});
const EmailSend1 = await EmailSends.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (EmailSend1?.setSequence_step)
{
await
EmailSend1.
setSequence_step(relatedSequence_step1);
}
const relatedSequence_step2 = await SequenceSteps.findOne({
offset: Math.floor(Math.random() * (await SequenceSteps.count())),
});
const EmailSend2 = await EmailSends.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (EmailSend2?.setSequence_step)
{
await
EmailSend2.
setSequence_step(relatedSequence_step2);
}
}
async function associateEmailSendWithCampaign() {
const relatedCampaign0 = await Campaigns.findOne({
offset: Math.floor(Math.random() * (await Campaigns.count())),
});
const EmailSend0 = await EmailSends.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (EmailSend0?.setCampaign)
{
await
EmailSend0.
setCampaign(relatedCampaign0);
}
const relatedCampaign1 = await Campaigns.findOne({
offset: Math.floor(Math.random() * (await Campaigns.count())),
});
const EmailSend1 = await EmailSends.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (EmailSend1?.setCampaign)
{
await
EmailSend1.
setCampaign(relatedCampaign1);
}
const relatedCampaign2 = await Campaigns.findOne({
offset: Math.floor(Math.random() * (await Campaigns.count())),
});
const EmailSend2 = await EmailSends.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (EmailSend2?.setCampaign)
{
await
EmailSend2.
setCampaign(relatedCampaign2);
}
}
async function associateEmailSendWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const EmailSend0 = await EmailSends.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (EmailSend0?.setOrganization)
{
await
EmailSend0.
setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const EmailSend1 = await EmailSends.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (EmailSend1?.setOrganization)
{
await
EmailSend1.
setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const EmailSend2 = await EmailSends.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (EmailSend2?.setOrganization)
{
await
EmailSend2.
setOrganization(relatedOrganization2);
}
}
async function associateAnalyticsEventWithSend() {
const relatedSend0 = await EmailSends.findOne({
offset: Math.floor(Math.random() * (await EmailSends.count())),
});
const AnalyticsEvent0 = await AnalyticsEvents.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (AnalyticsEvent0?.setSend)
{
await
AnalyticsEvent0.
setSend(relatedSend0);
}
const relatedSend1 = await EmailSends.findOne({
offset: Math.floor(Math.random() * (await EmailSends.count())),
});
const AnalyticsEvent1 = await AnalyticsEvents.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (AnalyticsEvent1?.setSend)
{
await
AnalyticsEvent1.
setSend(relatedSend1);
}
const relatedSend2 = await EmailSends.findOne({
offset: Math.floor(Math.random() * (await EmailSends.count())),
});
const AnalyticsEvent2 = await AnalyticsEvents.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (AnalyticsEvent2?.setSend)
{
await
AnalyticsEvent2.
setSend(relatedSend2);
}
}
async function associateAnalyticsEventWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const AnalyticsEvent0 = await AnalyticsEvents.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (AnalyticsEvent0?.setOrganization)
{
await
AnalyticsEvent0.
setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const AnalyticsEvent1 = await AnalyticsEvents.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (AnalyticsEvent1?.setOrganization)
{
await
AnalyticsEvent1.
setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const AnalyticsEvent2 = await AnalyticsEvents.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (AnalyticsEvent2?.setOrganization)
{
await
AnalyticsEvent2.
setOrganization(relatedOrganization2);
}
}
async function associateAttachmentWithUploaded_by() {
const relatedUploaded_by0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Attachment0 = await Attachments.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Attachment0?.setUploaded_by)
{
await
Attachment0.
setUploaded_by(relatedUploaded_by0);
}
const relatedUploaded_by1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Attachment1 = await Attachments.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Attachment1?.setUploaded_by)
{
await
Attachment1.
setUploaded_by(relatedUploaded_by1);
}
const relatedUploaded_by2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Attachment2 = await Attachments.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Attachment2?.setUploaded_by)
{
await
Attachment2.
setUploaded_by(relatedUploaded_by2);
}
}
async function associateAttachmentWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Attachment0 = await Attachments.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Attachment0?.setOrganization)
{
await
Attachment0.
setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Attachment1 = await Attachments.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Attachment1?.setOrganization)
{
await
Attachment1.
setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Attachment2 = await Attachments.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Attachment2?.setOrganization)
{
await
Attachment2.
setOrganization(relatedOrganization2);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Organizations.bulkCreate(OrganizationsData);
await Campaigns.bulkCreate(CampaignsData);
await Sequences.bulkCreate(SequencesData);
await SequenceSteps.bulkCreate(SequenceStepsData);
await Templates.bulkCreate(TemplatesData);
await Contacts.bulkCreate(ContactsData);
await ContactLists.bulkCreate(ContactListsData);
await SmtpIntegrations.bulkCreate(SmtpIntegrationsData);
await EmailSends.bulkCreate(EmailSendsData);
await AnalyticsEvents.bulkCreate(AnalyticsEventsData);
await Attachments.bulkCreate(AttachmentsData);
await Promise.all([
// Similar logic for "relation_many"
await associateUserWithOrganization(),
await associateCampaignWithOwner(),
await associateCampaignWithContact_list(),
await associateCampaignWithOrganization(),
await associateSequenceWithCampaign(),
await associateSequenceWithOrganization(),
await associateSequenceStepWithSequence(),
await associateSequenceStepWithTemplate(),
await associateSequenceStepWithOrganization(),
await associateTemplateWithOwner(),
await associateTemplateWithOrganization(),
await associateContactWithOwner(),
await associateContactWithOrganization(),
// Similar logic for "relation_many"
await associateContactListWithOwner(),
await associateContactListWithOrganization(),
await associateSmtpIntegrationWithOwner(),
await associateSmtpIntegrationWithOrganization(),
await associateEmailSendWithRecipient(),
await associateEmailSendWithSequence_step(),
await associateEmailSendWithCampaign(),
await associateEmailSendWithOrganization(),
await associateAnalyticsEventWithSend(),
await associateAnalyticsEventWithOrganization(),
await associateAttachmentWithUploaded_by(),
await associateAttachmentWithOrganization(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('organizations', null, {});
await queryInterface.bulkDelete('campaigns', null, {});
await queryInterface.bulkDelete('sequences', null, {});
await queryInterface.bulkDelete('sequence_steps', null, {});
await queryInterface.bulkDelete('templates', null, {});
await queryInterface.bulkDelete('contacts', null, {});
await queryInterface.bulkDelete('contact_lists', null, {});
await queryInterface.bulkDelete('smtp_integrations', null, {});
await queryInterface.bulkDelete('email_sends', null, {});
await queryInterface.bulkDelete('analytics_events', null, {});
await queryInterface.bulkDelete('attachments', null, {});
},
};