40210-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-06-05 02:27:51 +00:00

3060 lines
60 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Agents = db.agents;
const Conversations = db.conversations;
const Messages = db.messages;
const Attachments = db.attachments;
const UsageEvents = db.usage_events;
const AgentsData = [
{
"name": "General Assistant",
"description": "Helpful assistant for everyday questions and writing.",
"model": "gpt-4.1-mini",
"system_prompt": "You are a concise, accurate assistant. Ask clarifying questions when needed.",
"temperature": 0.4,
"max_output_tokens": 800,
"is_default": true,
"is_active": true,
"metadata_json": "{category:general,version:1.0}",
},
{
"name": "Code Helper",
"description": "Programming-focused agent for debugging and code reviews.",
"model": "gpt-4.1-mini",
"system_prompt": "You are a senior software engineer. Provide runnable examples and explain tradeoffs.",
"temperature": 0.2,
"max_output_tokens": 1200,
"is_default": false,
"is_active": true,
"metadata_json": "{category:engineering,languages:[js,ts,python]}",
},
{
"name": "Product Writer",
"description": "Agent for product copy, specs, and concise documentation.",
"model": "gpt-4.1-mini",
"system_prompt": "You write clear product documentation in a professional tone. Prefer bullets and headings.",
"temperature": 0.6,
"max_output_tokens": 900,
"is_default": true,
"is_active": true,
"metadata_json": "{category:writing}",
},
{
"name": "Data Analyst",
"description": "Agent for SQL, metrics, and analytical summaries.",
"model": "gpt-4.1-mini",
"system_prompt": "You are a data analyst. Provide step-by-step reasoning and validate assumptions.",
"temperature": 0.3,
"max_output_tokens": 1000,
"is_default": false,
"is_active": true,
"metadata_json": "{category:analytics}",
},
{
"name": "Meeting Notes",
"description": "Turns rough notes into structured summaries and action items.",
"model": "gpt-4.1-mini",
"system_prompt": "You create meeting summaries with decisions, risks, and action items.",
"temperature": 0.5,
"max_output_tokens": 700,
"is_default": true,
"is_active": true,
"metadata_json": "{category:productivity}",
},
];
const ConversationsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"title": "Quarterly planning outline",
"summary": "Drafting a Q3 planning outline for team priorities.",
"status": "archived",
"is_pinned": true,
"last_message_at": new Date('2026-05-12T09:22:10Z'),
"client_context_json": "{surface:workspace,device:desktop}",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"title": "Fixing a Node.js streaming bug",
"summary": "Investigating streaming response handling in Node.",
"status": "active",
"is_pinned": false,
"last_message_at": new Date('2026-05-11T17:12:40Z'),
"client_context_json": "{surface:workspace,device:laptop}",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"title": "Rewrite onboarding email",
"summary": "Improving clarity and tone for the welcome email.",
"status": "active",
"is_pinned": false,
"last_message_at": new Date('2026-05-10T08:50:02Z'),
"client_context_json": "{surface:workspace,device:tablet}",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"title": "Usage dashboard metrics ideas",
"summary": "Defining useful metrics for usage and cost tracking.",
"status": "deleted",
"is_pinned": true,
"last_message_at": new Date('2026-05-13T13:35:18Z'),
"client_context_json": "{surface:workspace,device:desktop}",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"title": "Meeting recap formatting",
"summary": "Converting raw notes into a clean recap format.",
"status": "archived",
"is_pinned": false,
"last_message_at": new Date('2026-05-09T22:25:55Z'),
"client_context_json": "{surface:workspace,device:mobile}",
},
];
const MessagesData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"role": "tool",
"content": "Help me draft a Q3 planning outline for an AI chat product. Include goals, initiatives, risks, and milestones.",
"content_markdown": "Help me draft a Q3 planning outline for an AI chat product. Include goals, initiatives, risks, and milestones.",
"tool_name": "none",
"tool_call_json": "{}",
"tool_result_json": "{}",
"delivery_status": "completed",
"sent_at": new Date('2026-05-12T09:15:10Z'),
"completed_at": new Date('2026-05-12T09:15:25Z'),
"sequence": 1,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"role": "assistant",
"content": "Here is a concise Q3 planning outline with goals, initiatives, risks, and milestones.",
"content_markdown": `## Goals
- Improve chat reliability
- Reduce latency
## Initiatives
- Streaming transport hardening
- Conversation search
## Risks
- Model rate limits
- Cost spikes
## Milestones
- Week 2: telemetry
- Week 6: search beta`,
"tool_name": "none",
"tool_call_json": "{}",
"tool_result_json": "{}",
"delivery_status": "completed",
"sent_at": new Date('2026-05-12T09:15:26Z'),
"completed_at": new Date('2026-05-12T09:15:55Z'),
"sequence": 2,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"role": "user",
"content": "My server streams tokens but the UI sometimes freezes. What should I check in a Node.js SSE setup?",
"content_markdown": "My server streams tokens but the UI sometimes freezes. What should I check in a Node.js SSE setup?",
"tool_name": "none",
"tool_call_json": "{}",
"tool_result_json": "{}",
"delivery_status": "draft",
"sent_at": new Date('2026-05-11T17:06:00Z'),
"completed_at": new Date('2026-05-11T17:06:12Z'),
"sequence": 1,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"role": "system",
"content": "Check response headers, flushing, proxy buffering, and event parsing. Also verify backpressure and keep-alives.",
"content_markdown": `Checklist:
- Set Content-Type to text/event-stream
- Disable proxy buffering
- Send periodic heartbeats
- Ensure client parser handles partial chunks
- Watch Node backpressure`,
"tool_name": "none",
"tool_call_json": "{}",
"tool_result_json": "{}",
"delivery_status": "failed",
"sent_at": new Date('2026-05-11T17:06:13Z'),
"completed_at": new Date('2026-05-11T17:06:40Z'),
"sequence": 2,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"role": "user",
"content": "Suggest 8 metrics for an AI chat usage dashboard that help control cost and improve product decisions.",
"content_markdown": "Suggest 8 metrics for an AI chat usage dashboard that help control cost and improve product decisions.",
"tool_name": "none",
"tool_call_json": "{}",
"tool_result_json": "{}",
"delivery_status": "streaming",
"sent_at": new Date('2026-05-13T13:30:00Z'),
"completed_at": new Date('2026-05-13T13:30:15Z'),
"sequence": 1,
},
];
const AttachmentsData = [
{
// type code here for "relation_one" field
"kind": "image",
// type code here for "files" field
// type code here for "images" field
"filename": "q3-planning-notes.txt",
"mime_type": "text/plain",
"size_bytes": 1842,
"storage_key": "attachments/2026/05/q3-planning-notes.txt",
"notes": "Initial notes used to draft the outline.",
},
{
// type code here for "relation_one" field
"kind": "file",
// type code here for "files" field
// type code here for "images" field
"filename": "sse-diagram.png",
"mime_type": "image/png",
"size_bytes": 245678,
"storage_key": "attachments/2026/05/sse-diagram.png",
"notes": "Reference diagram for SSE flow.",
},
{
// type code here for "relation_one" field
"kind": "image",
// type code here for "files" field
// type code here for "images" field
"filename": "metrics-draft.csv",
"mime_type": "text/csv",
"size_bytes": 9321,
"storage_key": "attachments/2026/05/metrics-draft.csv",
"notes": "Draft metrics list for review.",
},
{
// type code here for "relation_one" field
"kind": "image",
// type code here for "files" field
// type code here for "images" field
"filename": "product-brief.pdf",
"mime_type": "application/pdf",
"size_bytes": 512044,
"storage_key": "attachments/2026/05/product-brief.pdf",
"notes": "Background brief for planning.",
},
{
// type code here for "relation_one" field
"kind": "file",
// type code here for "files" field
// type code here for "images" field
"filename": "node-sse-checklist.md",
"mime_type": "text/markdown",
"size_bytes": 2204,
"storage_key": "attachments/2026/05/node-sse-checklist.md",
"notes": "Checklist to validate SSE streaming.",
},
];
const UsageEventsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"event_type": "message_sent",
"occurred_at": new Date('2026-05-12T09:15:10Z'),
"input_tokens": 58,
"output_tokens": 0,
"total_tokens": 58,
"cost_usd": 0.0006,
"provider": "openai",
"model": "gpt-4.1-mini",
"metadata_json": "{region:us,transport:https}",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"event_type": "attachment_uploaded",
"occurred_at": new Date('2026-05-12T09:15:55Z'),
"input_tokens": 58,
"output_tokens": 210,
"total_tokens": 268,
"cost_usd": 0.0032,
"provider": "openai",
"model": "gpt-4.1-mini",
"metadata_json": "{finish_reason:stop}",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"event_type": "message_generated",
"occurred_at": new Date('2026-05-11T17:06:00Z'),
"input_tokens": 33,
"output_tokens": 0,
"total_tokens": 33,
"cost_usd": 0.0003,
"provider": "openai",
"model": "gpt-4.1-mini",
"metadata_json": "{surface:workspace}",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"event_type": "message_generated",
"occurred_at": new Date('2026-05-11T17:06:40Z'),
"input_tokens": 33,
"output_tokens": 140,
"total_tokens": 173,
"cost_usd": 0.0021,
"provider": "openai",
"model": "gpt-4.1-mini",
"metadata_json": "{finish_reason:stop}",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"event_type": "tokens_counted",
"occurred_at": new Date('2026-05-13T13:30:15Z'),
"input_tokens": 24,
"output_tokens": 120,
"total_tokens": 144,
"cost_usd": 0.0018,
"provider": "openai",
"model": "gpt-4.1-mini",
"metadata_json": "{billing:estimate}",
},
];
// Similar logic for "relation_many"
async function associateConversationWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Conversation0 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Conversation0?.setUser)
{
await
Conversation0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Conversation1 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Conversation1?.setUser)
{
await
Conversation1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Conversation2 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Conversation2?.setUser)
{
await
Conversation2.
setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Conversation3 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Conversation3?.setUser)
{
await
Conversation3.
setUser(relatedUser3);
}
const relatedUser4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Conversation4 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Conversation4?.setUser)
{
await
Conversation4.
setUser(relatedUser4);
}
}
async function associateConversationWithAgent() {
const relatedAgent0 = await Agents.findOne({
offset: Math.floor(Math.random() * (await Agents.count())),
});
const Conversation0 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Conversation0?.setAgent)
{
await
Conversation0.
setAgent(relatedAgent0);
}
const relatedAgent1 = await Agents.findOne({
offset: Math.floor(Math.random() * (await Agents.count())),
});
const Conversation1 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Conversation1?.setAgent)
{
await
Conversation1.
setAgent(relatedAgent1);
}
const relatedAgent2 = await Agents.findOne({
offset: Math.floor(Math.random() * (await Agents.count())),
});
const Conversation2 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Conversation2?.setAgent)
{
await
Conversation2.
setAgent(relatedAgent2);
}
const relatedAgent3 = await Agents.findOne({
offset: Math.floor(Math.random() * (await Agents.count())),
});
const Conversation3 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Conversation3?.setAgent)
{
await
Conversation3.
setAgent(relatedAgent3);
}
const relatedAgent4 = await Agents.findOne({
offset: Math.floor(Math.random() * (await Agents.count())),
});
const Conversation4 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Conversation4?.setAgent)
{
await
Conversation4.
setAgent(relatedAgent4);
}
}
async function associateMessageWithConversation() {
const relatedConversation0 = await Conversations.findOne({
offset: Math.floor(Math.random() * (await Conversations.count())),
});
const Message0 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Message0?.setConversation)
{
await
Message0.
setConversation(relatedConversation0);
}
const relatedConversation1 = await Conversations.findOne({
offset: Math.floor(Math.random() * (await Conversations.count())),
});
const Message1 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Message1?.setConversation)
{
await
Message1.
setConversation(relatedConversation1);
}
const relatedConversation2 = await Conversations.findOne({
offset: Math.floor(Math.random() * (await Conversations.count())),
});
const Message2 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Message2?.setConversation)
{
await
Message2.
setConversation(relatedConversation2);
}
const relatedConversation3 = await Conversations.findOne({
offset: Math.floor(Math.random() * (await Conversations.count())),
});
const Message3 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Message3?.setConversation)
{
await
Message3.
setConversation(relatedConversation3);
}
const relatedConversation4 = await Conversations.findOne({
offset: Math.floor(Math.random() * (await Conversations.count())),
});
const Message4 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Message4?.setConversation)
{
await
Message4.
setConversation(relatedConversation4);
}
}
async function associateMessageWithAuthor_user() {
const relatedAuthor_user0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Message0 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Message0?.setAuthor_user)
{
await
Message0.
setAuthor_user(relatedAuthor_user0);
}
const relatedAuthor_user1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Message1 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Message1?.setAuthor_user)
{
await
Message1.
setAuthor_user(relatedAuthor_user1);
}
const relatedAuthor_user2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Message2 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Message2?.setAuthor_user)
{
await
Message2.
setAuthor_user(relatedAuthor_user2);
}
const relatedAuthor_user3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Message3 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Message3?.setAuthor_user)
{
await
Message3.
setAuthor_user(relatedAuthor_user3);
}
const relatedAuthor_user4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Message4 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Message4?.setAuthor_user)
{
await
Message4.
setAuthor_user(relatedAuthor_user4);
}
}
async function associateAttachmentWithMessage() {
const relatedMessage0 = await Messages.findOne({
offset: Math.floor(Math.random() * (await Messages.count())),
});
const Attachment0 = await Attachments.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Attachment0?.setMessage)
{
await
Attachment0.
setMessage(relatedMessage0);
}
const relatedMessage1 = await Messages.findOne({
offset: Math.floor(Math.random() * (await Messages.count())),
});
const Attachment1 = await Attachments.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Attachment1?.setMessage)
{
await
Attachment1.
setMessage(relatedMessage1);
}
const relatedMessage2 = await Messages.findOne({
offset: Math.floor(Math.random() * (await Messages.count())),
});
const Attachment2 = await Attachments.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Attachment2?.setMessage)
{
await
Attachment2.
setMessage(relatedMessage2);
}
const relatedMessage3 = await Messages.findOne({
offset: Math.floor(Math.random() * (await Messages.count())),
});
const Attachment3 = await Attachments.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Attachment3?.setMessage)
{
await
Attachment3.
setMessage(relatedMessage3);
}
const relatedMessage4 = await Messages.findOne({
offset: Math.floor(Math.random() * (await Messages.count())),
});
const Attachment4 = await Attachments.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (Attachment4?.setMessage)
{
await
Attachment4.
setMessage(relatedMessage4);
}
}
async function associateUsageEventWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const UsageEvent0 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (UsageEvent0?.setUser)
{
await
UsageEvent0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const UsageEvent1 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (UsageEvent1?.setUser)
{
await
UsageEvent1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const UsageEvent2 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (UsageEvent2?.setUser)
{
await
UsageEvent2.
setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const UsageEvent3 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (UsageEvent3?.setUser)
{
await
UsageEvent3.
setUser(relatedUser3);
}
const relatedUser4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const UsageEvent4 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (UsageEvent4?.setUser)
{
await
UsageEvent4.
setUser(relatedUser4);
}
}
async function associateUsageEventWithConversation() {
const relatedConversation0 = await Conversations.findOne({
offset: Math.floor(Math.random() * (await Conversations.count())),
});
const UsageEvent0 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (UsageEvent0?.setConversation)
{
await
UsageEvent0.
setConversation(relatedConversation0);
}
const relatedConversation1 = await Conversations.findOne({
offset: Math.floor(Math.random() * (await Conversations.count())),
});
const UsageEvent1 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (UsageEvent1?.setConversation)
{
await
UsageEvent1.
setConversation(relatedConversation1);
}
const relatedConversation2 = await Conversations.findOne({
offset: Math.floor(Math.random() * (await Conversations.count())),
});
const UsageEvent2 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (UsageEvent2?.setConversation)
{
await
UsageEvent2.
setConversation(relatedConversation2);
}
const relatedConversation3 = await Conversations.findOne({
offset: Math.floor(Math.random() * (await Conversations.count())),
});
const UsageEvent3 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (UsageEvent3?.setConversation)
{
await
UsageEvent3.
setConversation(relatedConversation3);
}
const relatedConversation4 = await Conversations.findOne({
offset: Math.floor(Math.random() * (await Conversations.count())),
});
const UsageEvent4 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (UsageEvent4?.setConversation)
{
await
UsageEvent4.
setConversation(relatedConversation4);
}
}
async function associateUsageEventWithMessage() {
const relatedMessage0 = await Messages.findOne({
offset: Math.floor(Math.random() * (await Messages.count())),
});
const UsageEvent0 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (UsageEvent0?.setMessage)
{
await
UsageEvent0.
setMessage(relatedMessage0);
}
const relatedMessage1 = await Messages.findOne({
offset: Math.floor(Math.random() * (await Messages.count())),
});
const UsageEvent1 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (UsageEvent1?.setMessage)
{
await
UsageEvent1.
setMessage(relatedMessage1);
}
const relatedMessage2 = await Messages.findOne({
offset: Math.floor(Math.random() * (await Messages.count())),
});
const UsageEvent2 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (UsageEvent2?.setMessage)
{
await
UsageEvent2.
setMessage(relatedMessage2);
}
const relatedMessage3 = await Messages.findOne({
offset: Math.floor(Math.random() * (await Messages.count())),
});
const UsageEvent3 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (UsageEvent3?.setMessage)
{
await
UsageEvent3.
setMessage(relatedMessage3);
}
const relatedMessage4 = await Messages.findOne({
offset: Math.floor(Math.random() * (await Messages.count())),
});
const UsageEvent4 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (UsageEvent4?.setMessage)
{
await
UsageEvent4.
setMessage(relatedMessage4);
}
}
async function associateUsageEventWithAgent() {
const relatedAgent0 = await Agents.findOne({
offset: Math.floor(Math.random() * (await Agents.count())),
});
const UsageEvent0 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (UsageEvent0?.setAgent)
{
await
UsageEvent0.
setAgent(relatedAgent0);
}
const relatedAgent1 = await Agents.findOne({
offset: Math.floor(Math.random() * (await Agents.count())),
});
const UsageEvent1 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (UsageEvent1?.setAgent)
{
await
UsageEvent1.
setAgent(relatedAgent1);
}
const relatedAgent2 = await Agents.findOne({
offset: Math.floor(Math.random() * (await Agents.count())),
});
const UsageEvent2 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (UsageEvent2?.setAgent)
{
await
UsageEvent2.
setAgent(relatedAgent2);
}
const relatedAgent3 = await Agents.findOne({
offset: Math.floor(Math.random() * (await Agents.count())),
});
const UsageEvent3 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (UsageEvent3?.setAgent)
{
await
UsageEvent3.
setAgent(relatedAgent3);
}
const relatedAgent4 = await Agents.findOne({
offset: Math.floor(Math.random() * (await Agents.count())),
});
const UsageEvent4 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 4
});
if (UsageEvent4?.setAgent)
{
await
UsageEvent4.
setAgent(relatedAgent4);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Agents.bulkCreate(AgentsData);
await Conversations.bulkCreate(ConversationsData);
await Messages.bulkCreate(MessagesData);
await Attachments.bulkCreate(AttachmentsData);
await UsageEvents.bulkCreate(UsageEventsData);
await Promise.all([
// Similar logic for "relation_many"
await associateConversationWithUser(),
await associateConversationWithAgent(),
await associateMessageWithConversation(),
await associateMessageWithAuthor_user(),
await associateAttachmentWithMessage(),
await associateUsageEventWithUser(),
await associateUsageEventWithConversation(),
await associateUsageEventWithMessage(),
await associateUsageEventWithAgent(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('agents', null, {});
await queryInterface.bulkDelete('conversations', null, {});
await queryInterface.bulkDelete('messages', null, {});
await queryInterface.bulkDelete('attachments', null, {});
await queryInterface.bulkDelete('usage_events', null, {});
},
};